import type { Resource } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
import { removeObjectEmptyFields } from 'https://deno.land/x/windmill_helpers@v1.0.0/mod.ts'
import { Configuration, CreateChatCompletionRequest, OpenAIApi } from "npm:openai@3.2.1"
/**
* You can read about the parameters at
* https://platform.openai.com/docs/api-reference/chat/create
*/
export async function main(
auth: Resource<'openai'>,
messages: {
role: 'assistant' | 'system' | 'user',
content: string,
name?: string
}[],
model: 'gpt-3.5-turbo' | 'gpt-3.5-turbo-16k' | 'gpt-4' | 'gpt-4-32k',
frequency_penalty?: number,
logit_bias?: object,
max_tokens?: number,
n?: number,
presence_penalty?: number,
stop?: string,
stream?: boolean,
temperature?: number,
top_p?: number,
user: string | undefined = Deno.env.get('WM_USERNAME'),
) {
const configuration = new Configuration({
apiKey: auth.api_key,
organization: auth.organization_id
});
const openai = new OpenAIApi(configuration);
const request: CreateChatCompletionRequest = {
messages,
model,
frequency_penalty,
logit_bias,
max_tokens,
n,
presence_penalty,
stop,
stream,
temperature,
top_p,
user
}
const response = await openai.createChatCompletion(
removeObjectEmptyFields(request)
)
return response.data
}
Submitted by sindre svendby964 533 days ago