Comments (7)
Just FYI, json_object
is not supported for gtp-4
model anyway:
Error code: 400 - {'error': {'message': "Invalid parameter: 'response_format' of type 'json_object' is not supported with this model.", 'type': 'invalid_request_error', 'param': 'response_format', 'code': None}}
response = client.chat.completions.create(
messages = [
{
"role": "user",
"content": prompt,
}
],
model="gpt-4",
response_format = {
"type": "json_object",
}
)
from client.
For gtp-4
model, the following prompt produces a JSON output:
response = client.chat.completions.create(
messages = [
{
"role": "user",
"content": "What are the first five letters in English? Answer in JSON format",
}
],
model="gpt-4",
)
% python test.py
What are the first five letters in English? Answer in JSON format
{
"1": "A",
"2": "B",
"3": "C",
"4": "D",
"5": "E"
}
from client.
Just FYI,
json_object
is not supported forgtp-4
model anyway:
This is not true:
To prevent these errors and improve model performance, when calling gpt-4-turbo-preview or gpt-3.5-turbo-0125, you can set response_format to { "type": "json_object" } to enable JSON mode. When JSON mode is enabled, the model is constrained to only generate strings that parse into valid JSON object.
https://platform.openai.com/docs/guides/text-generation/json-mode
from client.
@RHosono Did you run the code with different model(s) or just quoted the doc? The error message was return from OpenAI API. The model used was model="gpt-4"
.
from client.
Just FYI,
json_object
is not supported forgtp-4
model anyway:Error code: 400 - {'error': {'message': "Invalid parameter: 'response_format' of type 'json_object' is not supported with this model.", 'type': 'invalid_request_error', 'param': 'response_format', 'code': None}}
response = client.chat.completions.create( messages = [ { "role": "user", "content": prompt, } ], model="gpt-4", response_format = { "type": "json_object", } )
not sure why gpt4 is being mentioned, the model used in the original post was gpt-3.5-turbo-0125
. this is the exact model used in openai documentation: https://platform.openai.com/docs/guides/text-generation/json-mode
this works just by using a guzzle http client:
$response = $client->request('POST', 'https://api.openai.com/v1/chat/completions', [
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . getenv('OPENAI_API_KEY')
],
'json' => [
"messages" => [
["role" => "system", "content" => $system_content ],
["role" => "user", "content" => $address_json ]
],
"model" => "gpt-3.5-turbo",
"response_format" => [ "type" => "json_object" ]
]
]);
from client.
@RHosono Did you run the code with different model(s) or just quoted the doc? The error message was return from OpenAI API. The model used was
model="gpt-4"
.
So you mean the very old gpt-4 model, yes, that is correct. But both the new gpt-4-turbo and the older gpt-4-turbo-preview support it. I do not think anyone is using the more expensive and older gpt-4 modal. I was just making a general point, not about the code.
Because you said:
"json_object is not supported for gtp-4 model anyway:"
from client.
Hi @aaftre
This does not look like an error related to the package.
If you do not agree, feel free to reopen the issue.
from client.
Related Issues (20)
- [Bug]: HOT 1
- Fatal error: Cannot declare class OpenAI, because the name is already in use in E:\Xampp_8.2\htdocs\ia\vendor\openai-php\client\src\OpenAI.php on line 8 [Bug]: HOT 2
- [Feature]: Compatibility with assistants v2 HOT 4
- [improvement]: No support for assistant version v2 HOT 28
- Usage stats are now available when using streaming in the Chat Completions API HOT 11
- [file_search]: Do we have to wait for the v2 API to get file_search? HOT 5
- Undefined array key "file_ids"[Bug]: HOT 4
- API V2 Library? HOT 2
- Support Stream for Thread using Assistant HOT 4
- How to use data but not share with others people HOT 1
- [Bug]: MistralAI- Undefined array key "type" HOT 3
- Exceptions should have more detailed information, like what was the RESPONSE text. HOT 1
- [Bug]: ErrorException: Undefined array key "outputs" HOT 4
- [Bug]: Azure Asynchronous Filter HOT 4
- [Bug]: Faking custom metadata key-value pairs in responses is not possible HOT 1
- [Bug]: Undefined array key "input" when streaming with files attached HOT 1
- [Bug]: Undefined array key "outputs" when using code interpreter on a thread HOT 3
- [Bug]: Undefined array key \"input\" HOT 1
- Thread Message Delete method does not exist in latest Assistants V2 implementation HOT 1
- [Bug]: Call to undefined method OpenAI\\Resources\\ThreadsRuns::createStreamed() HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from client.