openai
OpenAI is an artificial intelligence research laboratory.
Usage
import { openai } from 'netzo/apis/openai.ts'
const api = openai({
apiKey: Deno.env.get('OPENAI_API_KEY')
})
Configuration
The openai
factory function expects an object with the following, and returns an object with an API client api
.
Param | Type | Default | Description |
---|---|---|---|
apiKey | string | Deno.env.get('OPENAI_API_KEY') | the api key to use for authentication |
Refer to the API documentation to get the required information.
Examples
The following examples assume you have created an api client instance.
Create chat completion
Obtain a model response for the given chat conversation.
const data: DataChatCompletion = {
model: 'gpt-3.5-turbo',
messages: [
{
role: 'system',
content: 'You are a helpful assistant.'
},
{
role: 'user',
content: 'Hello!'
}
]
}
const result = await api.chat.completions.post<ChatCompletion>(data)
const resultData = result.choices