admin管理员组文章数量:1431145
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
.
本文标签:
版权声明:本文标题:Azure Openai gpt-4o-2024-08-06 model is giving response as Could not parse response content as the length limit was reached - St 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745564349a2663669.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