Edits history of script submission #18763 for ' Get a model's README (replicate)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Replicate = {
      token: string;
    };
    /**
     * Get a model's README
     * Get the README content for a model.
    
    Example cURL request:
    
    ```console
    curl -s \
      -H "Authorization: Bearer $REPLICATE_API_TOKEN" \
      https://api.replicate.com/v1/models/replicate/hello-world/readme
    ```
    
    The response will be the README content as plain text in Markdown format:
    
    ```
    # Hello World Model
    
    This is an example model that...
    ```
    
     */
    export async function main(
      auth: Replicate,
      model_owner: string,
      model_name: string,
    ) {
      const url = new URL(
        `https://api.replicate.com/v1/models/${model_owner}/${model_name}/readme`,
      );
    
      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.text();
    }
    

    Submitted by hugo697 235 days ago