Edits history of script submission #15701 for ' Deployment Logs Query (deep_infra)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Deepinfra = {
      token: string;
    };
    /**
     * Deployment Logs Query
     * Query deployment logs.
     * Without timestamps (from/to) returns last `limit` messages (in last month).
     * With `from` only, returns first `limit` messages after `from` (inclusive).
     * With `to` only, returns last `limit` messages before `to` (inclusive).
     * With both `from` and `to`, return the first `limit` messages after `from`, but not later than `to`.
     * `from` and `to` should be no more than a month apart.
     */
    export async function main(
      auth: Deepinfra,
      deploy_id: string | undefined,
      pod_name: string | undefined,
      from: string | undefined,
      to: string | undefined,
      limit: string | undefined,
    ) {
      const url = new URL(`https://api.deepinfra.com/v1/deployment_logs/query`);
      for (const [k, v] of [
        ["deploy_id", deploy_id],
        ["pod_name", pod_name],
        ["from", from],
        ["to", to],
        ["limit", limit],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago