-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from ChuckJonas/chat-function-support
support for passing "functions" to chat completions
- Loading branch information
Showing
3 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { OpenAI } from "../mod.ts"; | ||
|
||
const openAI = new OpenAI(Deno.env.get("YOUR_API_KEY")!); | ||
|
||
const chatCompletion = await openAI.createChatCompletion({ | ||
model: "gpt-3.5-turbo", | ||
messages: [ | ||
{"role": "user", "content": "What is the weather like in Boston?"} | ||
], | ||
function_call: { name: "get_current_weather" }, | ||
functions: [ | ||
{ | ||
"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"] | ||
} | ||
} | ||
] | ||
}); | ||
|
||
console.log(chatCompletion); |
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
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