Skip to content
TheChatArchiveThe Chat Archive
vicuna-33b· LMSYSHugging Face Arena Human Preference 55K

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

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

    Using Typescript 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. Assistant

    To implement the getGithubIssue function, you'll need to use a library that can interact with the GitHub API. I recommend using the github-api package. First, you'll need to install it:

    npm install github-api
    

    Now you can implement the getGithubIssue function using TypeScript:

    import { GitHubClient } from 'github-api';
    
    type GithubIssue = {
      number: number;
      title: string;
      body: string;
    };
    
    function getGithubIssue(owner: string, repo: string, number: number): GithubIssue | null {
      const githubClient = new GitHubClient({
        auth: 'YOUR_GITHUB_ACCESS_TOKEN', // Replace with your GitHub access token
      });
    
      try {
        const response = githubClient.issues.get({
          owner,
          repo,
          number,
        });
    
        if (response.status === 200) {
          const issue = response.data;
          return {
            number: issue.number,
            title: issue.title,
            body: issue.body,
          };
        } else if (response.status === 404) {
          return null;
        } else {
          throw new Error(`Failed to get GitHub issue: ${response.status}`);
        }
      } catch (error) {
        throw new Error(`Error fetching GitHub issue: ${error.message}`);
      }
    }
    
    // Example usage:
    const owner = 'your-repo-owner';
    const repo = 'your-repo-name';
    const issueNumber = 123; // Replace with a valid issue number
    
    const issue = getGithubIssue(owner, repo, issueNumber);
    if (issue) {
      console.log('Issue details:', issue);
    } else {
      console.log('Issue not found');
    }
    

    Replace 'YOUR_GITHUB_ACCESS_TOKEN' with your GitHub access token and the other placeholders with the appropriate values for your use case.

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