Edits history of script submission #14386 for ' Generate text (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * Generate text
     * Sends an AI request to supported Large Language Models (LLMs) and returns generated text based on the provided prompt.
     */
    export async function main(
      auth: Box,
      body: {
        prompt: string;
        items: { id: string; type: "file"; content?: string }[];
        dialogue_history?: {
          prompt?: string;
          answer?: string;
          created_at?: string;
        }[];
        ai_agent?: {
          type: "ai_agent_text_gen";
          basic_gen?: {
            model?: string;
            num_tokens_for_completion?: number;
            llm_endpoint_params?:
              | {
                  type: "openai_params";
                  temperature?: number;
                  top_p?: number;
                  frequency_penalty?: number;
                  presence_penalty?: number;
                  stop?: string;
                }
              | {
                  type: "google_params";
                  temperature?: number;
                  top_p?: number;
                  top_k?: number;
                }
              | { type: "aws_params"; temperature?: number; top_p?: number };
          } & { system_message?: string; prompt_template?: string } & {
            embeddings?: {
              model?: string;
              strategy?: { id?: string; num_tokens_per_chunk?: number };
            };
          } & { content_template?: string };
        };
      },
    ) {
      const url = new URL(`https://api.box.com/2.0/ai/text_gen`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago