Created
July 13, 2023 10:10
-
-
Save JordanDalton/8d26e5f8e4af79ab44a9a9347ec77bc3 to your computer and use it in GitHub Desktop.
Code sample on using custom function in the OpenAI PHP Laravel package.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$city_fact_result = OpenAI::chat()->create([ | |
'model' => 'gpt-3.5-turbo', | |
'messages' => [ | |
[ | |
'role' => 'user', | |
'content' => "I'm in {$location}?", | |
],[ | |
'role' => 'assistant', | |
'content' => null, | |
'function_call' => [ | |
'name' => 'get_interesting_location_fact', | |
'arguments' => "{'location': '{$location}'}" | |
], | |
] | |
], | |
'functions' => [ | |
[ | |
'name' => 'get_interesting_laravel_fact', | |
'description' => 'Find something interesting about a location.', | |
'parameters' => [ | |
'type' => 'object', | |
'properties' => [ | |
'location' => [ | |
'type' => 'string', | |
'description' => "The city and state, e.g. San Francisco, CA" | |
] | |
], | |
'required' => ['location'] | |
] | |
] | |
], | |
'max_tokens' => 250 | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment