openai-php / client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
MIT License
4.75k stars 491 forks source link

[Feature request] Support function calling #142

Closed innocenzi closed 1 year ago

innocenzi commented 1 year ago

Tweet: https://twitter.com/OpenAI/status/1668668732347129856 Blog post: https://openai.com/blog/function-calling-and-other-api-updates Documentation: https://platform.openai.com/docs/guides/gpt/function-calling

Open AI now supports "function calling". The feature consists of passing function details to an OpenAI request, and the response will tell you if the model wants to run a function.

Function calling allows you to more reliably get structured data back from the model. For example, you can:

  • Create chatbots that answer questions by calling external APIs (e.g. like ChatGPT Plugins)
    • e.g. define functions like send_email(to: string, body: string), or get_current_weather(location: string, unit: 'celsius' | 'fahrenheit')
  • Convert natural language into API calls
    • e.g. convert "Who are my top customers?" to get_customers(min_revenue: int, created_before: string, limit: int) and call your internal API
  • Extract structured data from text
    • e.g. define a function called extract_data(name: string, birthday: string), or sql_query(query: >string)
peterjaap commented 1 year ago

It looks like it does not take into account the existence of the function_call parameter here;

https://github.com/openai-php/client/blob/main/src/Responses/Chat/CreateResponseMessage.php#L21

It also breaks on $attributes['content'] being null in this case since there's no content there when a function_call is needed.

gehrisandro commented 1 year ago

Currently working on this one.

gehrisandro commented 1 year ago

https://github.com/openai-php/client/pull/144

Reviews welcome 🙏

innocenzi commented 1 year ago

Awesome @gehrisandro. Thank you for your time. ❤️

gehrisandro commented 1 year ago

v0.6.0 has been released: https://twitter.com/gehrisandro/status/1669076719200874496?s=20