fix max_tokens error on gpt 4o
This commit is contained in:
parent
a2e5baa665
commit
2f38b0b190
1 changed files with 14 additions and 2 deletions
|
|
@ -112,7 +112,7 @@ async def _test_openai_completion_with_tools(api_key: str, llm_model: str) -> No
|
||||||
}
|
}
|
||||||
|
|
||||||
# Simple tool calling test
|
# Simple tool calling test
|
||||||
payload = {
|
base_payload = {
|
||||||
"model": llm_model,
|
"model": llm_model,
|
||||||
"messages": [
|
"messages": [
|
||||||
{"role": "user", "content": "What tools do you have available?"}
|
{"role": "user", "content": "What tools do you have available?"}
|
||||||
|
|
@ -136,10 +136,11 @@ async def _test_openai_completion_with_tools(api_key: str, llm_model: str) -> No
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"max_tokens": 50,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
|
# Try with max_tokens first
|
||||||
|
payload = {**base_payload, "max_tokens": 50}
|
||||||
response = await client.post(
|
response = await client.post(
|
||||||
"https://api.openai.com/v1/chat/completions",
|
"https://api.openai.com/v1/chat/completions",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
|
|
@ -147,6 +148,17 @@ async def _test_openai_completion_with_tools(api_key: str, llm_model: str) -> No
|
||||||
timeout=30.0,
|
timeout=30.0,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# If max_tokens doesn't work, try with max_completion_tokens
|
||||||
|
if response.status_code != 200:
|
||||||
|
logger.info("max_tokens parameter failed, trying max_completion_tokens instead")
|
||||||
|
payload = {**base_payload, "max_completion_tokens": 50}
|
||||||
|
response = await client.post(
|
||||||
|
"https://api.openai.com/v1/chat/completions",
|
||||||
|
headers=headers,
|
||||||
|
json=payload,
|
||||||
|
timeout=30.0,
|
||||||
|
)
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
logger.error(f"OpenAI completion test failed: {response.status_code} - {response.text}")
|
logger.error(f"OpenAI completion test failed: {response.status_code} - {response.text}")
|
||||||
raise Exception(f"OpenAI API error: {response.status_code}")
|
raise Exception(f"OpenAI API error: {response.status_code}")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue