Hello everyone,
I’m currently working on integrating the GPT-4o-mini model into my project, and I need to generate text outputs with a length of up to 12,000 tokens. However, I’m facing an issue where the output gets cut off before reaching the desired length.
Here’s a snippet of my code:
const generateText = async (prompt, maxTokens = 16000, model = ‘gpt-4o-mini-2024-07-18’) => {
try {
const response = await openai.chat.completions.create({
model,
messages: [{ role: ‘user’, content: prompt }],
max_tokens: maxTokens,
});
const tokensUsed = response.usage?.total_tokens || 0;
trackTokens(tokensUsed);
return {
response: response.choices[0].message.content.trim(),
tokensUsed,
};
} catch (error) {
logger.log(‘error’, OpenAI API Error: ${error.message}
);
throw new AppError(OpenAI API call failed: ${error.message}
, 500);
}
};
Despite setting maxTokens
to 16,000, the response is still cut short, and I’m not achieving the 12,000 tokens I need.
Could anyone provide guidance on how to ensure the model produces the full output length? Any advice or suggestions would be greatly appreciated.
Thank you in advance for your help!