elvuel / gh-gpt

This is a simple tool to use the GitHub Copilot API as a GPT API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gh-gpt

This is a simple tool to use the GitHub Copilot API as a GPT API.

Ensure you can access the GitHub Copilot API

There are two ways to access the GitHub Copilot API.

Login

gh-gpt login
Please take this code "0000-0000" to authenticate at https://github.com/login/device.
Press 'y' to continue, or any other key to abort.
Waiting for authentication...

Login Copilot in IDE

Windows: ~\AppData\Local\github-copilot\hosts.json Other: ~/.config/github-copilot/hosts.json

The file is created when you log in to Copilot in an IDE

  • JetBrains (tested)
  • VS Code
  • ...

Setup Environment

I have only tested ghu_ of Identifiable prefixes

GH_COPILOT_TOKEN=ghu_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Usage

As a CLI

gh-gpt run "Who are you?"
# I am an artificial intelligence designed to assist with information and tasks. How can I help you today?

As a server

Listening on http://127.0.0.1:8000

gh-gpt server --address :8000
curl --location 'http://127.0.0.1:8000/v1/chat/completions' \
--header 'Content-Type: application/json' \
--data '{
  "model": "gpt-4",
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Who are you?"}
   ]
}' | jq -r '.choices[0].message.content'
# I am an artificial intelligence designed to assist with information and tasks. How can I help you today?

As a library

package main

import (
	"context"
	"os"

	"github.com/wzshiming/gh-gpt/pkg/run"
)

func main() {
	_ = run.RunStream(context.Background(), "Who are you?", os.Stdout)
	// I am an artificial intelligence designed to assist with information and tasks. How can I help you today?
}

About

This is a simple tool to use the GitHub Copilot API as a GPT API.

License:MIT License


Languages

Language:Go 100.0%