Edits history of script submission #12096 for ' List Models (cohere)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Cohere = {
      apiKey: string;
    };
    /**
     * List Models
     * Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models.
     */
    export async function main(
      auth: Cohere,
      page_size: string | undefined,
      page_token: string | undefined,
      endpoint:
        | "chat"
        | "embed"
        | "classify"
        | "summarize"
        | "rerank"
        | "rate"
        | "generate"
        | undefined,
      default_only: string | undefined,
    ) {
      const url = new URL(`https://api.cohere.com/v1/models`);
      for (const [k, v] of [
        ["page_size", page_size],
        ["page_token", page_token],
        ["endpoint", endpoint],
        ["default_only", default_only],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.apiKey,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago