Edits history of script submission #5838 for ' Submit tool ouputs to run (openai)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Openai = {
      api_key: string;
      organization_id: string;
    };
    /**
     * Submit tool ouputs to run
     * When a run has the `status: "requires_action"` and `required_action.type` is `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request.
    
     */
    export async function main(
      auth: Openai,
      thread_id: string,
      run_id: string,
      body: {
        tool_outputs: {
          tool_call_id?: string;
          output?: string;
          [k: string]: unknown;
        }[];
      }
    ) {
      const url = new URL(
        `https://api.openai.com/v1/threads/${thread_id}/runs/${run_id}/submit_tool_outputs`
      );
    
      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 372 days ago

  • nativets
    type Openai = {
      api_key: string;
      organization_id: string;
    };
    /**
     * Submit tool ouputs to run
     * When a run has the `status: "requires_action"` and `required_action.type` is `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request.
    
     */
    export async function main(
      auth: Openai,
      thread_id: string,
      run_id: string,
      body: {
        tool_outputs: {
          tool_call_id?: string;
          output?: string;
          [k: string]: unknown;
        }[];
      }
    ) {
      const url = new URL(
        `https://api.openai.com/v1/threads/${thread_id}/runs/${run_id}/submit_tool_outputs`
      );
    
      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 895 days ago