Skip to content
TheChatArchiveThe Chat Archive
Mistralmixtral-8x7b-instruct-v0.1· Mistral AIHugging Face Arena Human Preference 55K

Using Typescript and Axios implement a function getGithubIssue(owner:string,…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-2.1’s answer.
  1. User

    Using Typescript and Axios implement a function getGithubIssue(owner:string, repo:string, number:number):GithubIssue | null.

    It only needs to return the fields number, title, body.

    The values passed in may be unsanitized

    We should return null on a 404. A valid value on 200 throw on anything else

  2. Mistral Assistant

    Here's an implementation of the getGithubIssue function using TypeScript, Axios, and Promises:

    import axios from 'axios';
    
    interface GithubIssue {
      number: number;
      title: string;
      body: string;
    }
    
    async function getGithubIssue(owner: string, repo: string, number: number): Promise<GithubIssue | null> {
      try {
        const response = await axios.get(`https://api.github.com/repos/${owner}/${repo}/issues/${number}`);
        if (response.status === 200) {
          const { number, title, body } = response.data;
          return { number, title, body };
        } else {
          return null;
        }
      } catch (error) {
        if (error.response) {
          if (error.response.status === 404) {
            return null;
          } else {
            throw error;
          }
        } else {
          throw error;
        }
      }
    }
    

    Here's a brief explanation of the code:

    • We define an interface GithubIssue for the issue data we expect to receive from the GitHub API.
    • We define the getGithubIssue function, which takes in three parameters: owner, repo, and number.
    • We use the axios.get method to make a GET request to the GitHub API and retrieve the issue data.
    • We use the await keyword to wait for the promise to resolve before continuing with the function.
    • We check the status property of the response object to determine if the request was successful (200) or if the issue was not found (404).
    • If the request was successful, we extract the number, title, and body properties from the response data and return them as a GithubIssue object.
    • If the request was not successful (i.e., not a 200 or 404), we throw an error.
    • We use a try...catch block to handle any errors that may occur during the request. If an error occurs and the response object is available, we check the status property of the response object to determine if it was a 404 error. If it was, we return null. Otherwise, we throw the error.

    Note that this implementation assumes that the axios package has been installed and imported correctly.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.