Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function calling #129

Open
lakshaysethi opened this issue Nov 27, 2023 · 1 comment
Open

Function calling #129

lakshaysethi opened this issue Nov 27, 2023 · 1 comment

Comments

@lakshaysethi
Copy link

Describe the feature or improvement you're requesting

does this library not support function calling? Tried but could not get this to work

as also noted in

#98
https://platform.openai.com/docs/api-reference/chat/create
image

curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
  "model": "gpt-3.5-turbo",
  "messages": [
    {
      "role": "user",
      "content": "What is the weather like in Boston?"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_current_weather",
        "description": "Get the current weather in a given location",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "The city and state, e.g. San Francisco, CA"
            },
            "unit": {
              "type": "string",
              "enum": ["celsius", "fahrenheit"]
            }
          },
          "required": ["location"]
        }
      }
    }
  ],
  "tool_choice": "auto"
}'

Additional context

No response

@genolve
Copy link

genolve commented Feb 13, 2024

Not sure about the direct call with curl but the library worked for me, using gpt-4-turbo-preview, and adding a 'tools' param into args for $open_ai->chat(). You need to be real careful with the JSON If using json_decode as it will silently fail on JSON errors unless you specifically check:

$jData = stripslashes(html_entity_decode($tools));
$toolsO = json_decode($jData,true);
if ($toolsO === null && json_last_error() !== JSON_ERROR_NONE){
echo '{"success":false,"message": "OpenAI tools JSON parse fail:'.json_last_error().'"}';
exit;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants