Edits history of script submission #12100 for ' Retrieves the chronology of statuses the fine-tuned model has been through. (cohere)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Cohere = {
      apiKey: string;
    };
    /**
     * Retrieves the chronology of statuses the fine-tuned model has been through.
     *
     */
    export async function main(
      auth: Cohere,
      finetuned_model_id: string,
      page_size: string | undefined,
      page_token: string | undefined,
      order_by: string | undefined,
    ) {
      const url = new URL(
        `https://api.cohere.com/v1/finetuning/finetuned-models/${finetuned_model_id}/events`,
      );
      for (const [k, v] of [
        ["page_size", page_size],
        ["page_token", page_token],
        ["order_by", order_by],
      ]) {
        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