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
*/
type Openai = {
api_key: string;
organization_id: string;
};
export async function main(
auth: Openai,
messages: {
role: "assistant" | "system" | "user";
content: string;
name?: string;
}[],
model: "gpt-3.5-turbo" | "gpt-3.5-turbo-0301" = "gpt-3.5-turbo",
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,
) {
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 admin 497 days ago
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
*/
type Openai = {
api_key: string;
organization_id: string;
};
export async function main(
auth: Openai,
messages: {
role: 'assistant' | 'system' | 'user',
content: string,
name?: string
}[],
model: 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301' = 'gpt-3.5-turbo',
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,
) {
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 admin 500 days ago
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-0301' = 'gpt-3.5-turbo',
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,
) {
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 adam186 614 days ago