Edits history of script submission #5866 for ' Create embedding (openai)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Openai = {
      api_key: string;
      organization_id: string;
    };
    /**
     * Create embedding
     * Creates an embedding vector representing the input text.
     */
    export async function main(
      auth: Openai,
      body: {
        input: string | string[] | number[] | number[][];
        model:
          | string
          | (
              | "text-embedding-ada-002"
              | "text-embedding-3-small"
              | "text-embedding-3-large"
            );
        encoding_format?: "float" | "base64";
        dimensions?: number;
        user?: string;
      }
    ) {
      const url = new URL(`https://api.openai.com/v1/embeddings`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "OpenAI-Organization": auth.organization_id,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.api_key,
        },
        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 376 days ago

  • nativets
    type Openai = {
      api_key: string;
      organization_id: string;
    };
    /**
     * Create embedding
     * Creates an embedding vector representing the input text.
     */
    export async function main(
      auth: Openai,
      body: {
        input: string | string[] | number[] | number[][];
        model:
          | string
          | (
              | "text-embedding-ada-002"
              | "text-embedding-3-small"
              | "text-embedding-3-large"
            );
        encoding_format?: "float" | "base64";
        dimensions?: number;
        user?: string;
      }
    ) {
      const url = new URL(`https://api.openai.com/v1/embeddings`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "OpenAI-Organization": auth.organization_id,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.api_key,
        },
        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 840 days ago

  • nativets
    type Openai = {
      api_key: string;
      organization_id: string;
    };
    /**
     * Create embedding
     * Creates an embedding vector representing the input text.
     */
    export async function main(
      auth: Openai,
      body: {
        input: string | string[] | number[] | number[][];
        model: string | "text-embedding-ada-002";
        encoding_format?: "float" | "base64";
        user?: string;
      }
    ) {
      const url = new URL(`https://api.openai.com/v1/embeddings`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "OpenAI-Organization": auth.organization_id,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.api_key,
        },
        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 899 days ago