Coder Social home page Coder Social logo

json_schema/Structured Outputs about client HOT 4 OPEN

rhughes8469 avatar rhughes8469 commented on August 20, 2024 6
json_schema/Structured Outputs

from client.

Comments (4)

ericthornton88 avatar ericthornton88 commented on August 20, 2024

I did not try this with structured outputs, but this worked for me when setting the response format to json

'model' => 'gpt-4o',
'response_format' => [
     'type' => 'json_object'
],

Cross reference to this post

from client.

jrmgx avatar jrmgx commented on August 20, 2024

Does this package support the new response_format = 'json_schema' option (Structured Outputs).

Would you be able to send the schema in via the $client->chat()->create method as an array?

https://platform.openai.com/docs/guides/structured-outputs

As today, it does not.

The OpenAI announce is quite new, and this library has not been updated yet.
See OpenAI blog post for details: https://openai.com/index/introducing-structured-outputs-in-the-api/

Note that type: json_object is a different thing, here we are talking about the new type: json_schema

from client.

monsieurbab avatar monsieurbab commented on August 20, 2024

+1 to add support for this feature

from client.

thijndehaas avatar thijndehaas commented on August 20, 2024

This can be resolved by passing the json schema as parameter:

'model' => 'gpt-4o',
'response_format' => [
    'type' => 'json_schema',
    'json_schema' => $jsonSchema,
]

For example:

[
    'model' => 'gpt-4o',
    'message' => 'what is 1 + 1?',
    'response_format' => [
        'type' => 'json_schema',
        'json_schema' => [
            "name" => "math_response",
            "strict" => true,
            "schema" => [
                "type" => "object",
                "properties" => [
                    "steps" => [
                        "type" => "array",
                        "items" => [
                            "type" => "object",
                            "properties" => [
                                "explanation" => [
                                    "type" => "string"
                                ],
                                "output" => [
                                    "type" => "string"
                                ]
                            ],
                            "required" => [
                                "explanation",
                                "output"
                            ],
                            "additionalProperties" => false
                        ]
                    ],
                    "final_answer" => [
                        "type" => "string"
                    ]
                ],
                "required" => [
                    "steps",
                    "final_answer"
                ],
                "additionalProperties" => false
            ],
        ]
    ]
];

from client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.