Skip to content

Instantly share code, notes, and snippets.

@JordanDalton
Created July 13, 2023 10:10
Show Gist options
  • Save JordanDalton/8d26e5f8e4af79ab44a9a9347ec77bc3 to your computer and use it in GitHub Desktop.
Save JordanDalton/8d26e5f8e4af79ab44a9a9347ec77bc3 to your computer and use it in GitHub Desktop.
Code sample on using custom function in the OpenAI PHP Laravel package.
<?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