Create Completion ( openai)
One script reply has been approved by the moderators Verified

Created by adam186 105 days ago Viewed 618 times 1 Point

Create a completion for the provided prompt.

No comments yet

Login to be able to comment
Points: 0
deno
One script reply has been approved by the moderators
Ap­pro­ved
import type { Resource } from "https://deno.land/x/windmill@v1.70.1/mod.ts";
import { removeObjectEmptyFields } from 'https://deno.land/x/windmill_helpers@v1.0.0/mod.ts'
import { Configuration, CreateCompletionRequest, OpenAIApi } from "npm:openai@3.1.0"

/**
 * You can read about the parameters at 
 * https://beta.openai.com/docs/api-reference/completions/create
 */
export async function main(
  auth: Resource<'openai'>,
  model = 'text-davinci-003',
  prompt?: string,
  suffix?: string,
  max_tokens?: number,
  temperature?: number,
  top_p?: number,
  n?: number,
  stream?: boolean,
  logprobs?: number,
  echo?: boolean,
  stop?: string,
  presence_penalty?: number,
  frequency_penalty?: number,
  best_of?: number,
  logit_bias?: object
) {
  const configuration = new Configuration({
    apiKey: auth.api_key,
    organization: auth.organization_id
  });
  const openai = new OpenAIApi(configuration);

  const request = removeObjectEmptyFields({
    model,
    prompt,
    suffix,
    max_tokens,
    temperature,
    top_p,
    n,
    stream,
    logprobs,
    echo,
    stop,
    presence_penalty,
    frequency_penalty,
    best_of,
    logit_bias
  }) as CreateCompletionRequest
  const response = await openai.createCompletion(request)
  return response.data
}

Submitted by adam186 105 days ago

Edited 27 days ago

No comments yet

Login to be able to comment