I am using gpt-4o-2024-08-06 model with structured output. In documentation it is mentioned that this model support Context window 128k and Max output tokens supported are 16384. I have given the code which i have followed in my project. The error i am getting is as follow.
Could not parse response content as the length limit was reached - CompletionUsage(completion_tokens=5000, prompt_tokens=21633, total_tokens=26633, completion_tokens_details=None, prompt_tokens_details=None)
How to resolve this error.
The code which I have followed is given below.
from openai import OpenAI
client = OpenAI()
class CalendarEvent(BaseModel):
name: str
date: str
participants: list[str]
completion = client.beta.chatpletions.parse(
model="gpt-4o-2024-08-06",
messages=[
{"role": "system", "content": "Extract the event information."},
{"role": "user", "content": "Alice and Bob are going to a science fair on Friday."},
],
response_format=CalendarEvent,
max_tokens=5000
)
event = completion.choices[0].message.parsed
I am using gpt-4o-2024-08-06 model with structured output. In documentation it is mentioned that this model support Context window 128k and Max output tokens supported are 16384. I have given the code which i have followed in my project. The error i am getting is as follow.
Could not parse response content as the length limit was reached - CompletionUsage(completion_tokens=5000, prompt_tokens=21633, total_tokens=26633, completion_tokens_details=None, prompt_tokens_details=None)
How to resolve this error.
The code which I have followed is given below.
from openai import OpenAI
client = OpenAI()
class CalendarEvent(BaseModel):
name: str
date: str
participants: list[str]
completion = client.beta.chatpletions.parse(
model="gpt-4o-2024-08-06",
messages=[
{"role": "system", "content": "Extract the event information."},
{"role": "user", "content": "Alice and Bob are going to a science fair on Friday."},
],
response_format=CalendarEvent,
max_tokens=5000
)
event = completion.choices[0].message.parsed
Share
Improve this question
edited Nov 19, 2024 at 11:56
Sanjeevani
asked Nov 19, 2024 at 11:43
SanjeevaniSanjeevani
271 silver badge7 bronze badges
5
|
1 Answer
Reset to default 1max_tokens
is the token generated from completion, that is including output tokens and reasoning tokens.
You can check this documentation.
So, you need to give the max_tokens
greater than the completion token else you will get error.
See below example.
Completion token is 17
which is difference of total and prompt tokens.
Now, if i give max_tokens
as 17
i get below error.
LengthFinishReasonError: Could not parse response content as the length limit was reached - CompletionUsage(completion_tokens=17, prompt_tokens=92, total_tokens=109, completion_tokens_details=None, prompt_tokens_details=None)
When i give greater than 17
it is working fine.
So, you give the max_tokens
greater than the difference of total tokens and prompt tokens, in your case it is greater than 5000
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745564350a4633303.html
max_completion_tokens
?max_tokens
seems to have been deprecated. – Luaan Commented Nov 19, 2024 at 12:00Maximum length
and in the APImax_tokens
. – Sampath Commented Nov 19, 2024 at 12:50max_tokens
is deprecated see platform.openai/docs/api-reference/chat/… – herve Commented Nov 27, 2024 at 9:52