copilot2gpt 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Dockerfile +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +51 -20
- data/lib/copilot2gpt/app.rb +11 -6
- data/lib/copilot2gpt/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: da23dae0f4ea1932a9cfc08fb8fe479be3ef082bf505354d606506e3b27511b2
|
|
4
|
+
data.tar.gz: eca989b27b347b678a1f8013ac2ee18228c6e2acfef33f79e588ca68014c473d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2ea78b0aa79bd8cf5cb0d7297c9cfaabf58c4b4960fcf6ee96435df4e87c9c9b9e1a920c5f027c7fde0b4a6aa91f8b14c896c957d326ca8f59e5c0c84095c4b7
|
|
7
|
+
data.tar.gz: be6ec3f22729aea3d15ad35065b2612ceea3017021ba0c7c7e5385eae382200599847a836b9002878ca7938fd6edc2097e85a7d22abfce95c9704baad2acd1ec
|
data/Dockerfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -1,39 +1,70 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Copilot 2 GPT-4
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This is a Sinatra-based application that serves as a bridge between GitHub Copilot and GPT-4 model. It provides endpoints to interact with the GPT-4 model and handles authorization using GitHub tokens.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Getting Started
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Prerequisites
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
You need to have Ruby installed on your machine. You can check if you have Ruby installed by running:
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
```bash
|
|
14
|
+
ruby -v
|
|
15
|
+
```
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
### Installing
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
Clone the repository:
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
```bash
|
|
22
|
+
git clone https://github.com/lululau/copilot2gpt.git
|
|
23
|
+
cd copilot2gpt
|
|
24
|
+
```
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
Install the required gems:
|
|
22
27
|
|
|
23
|
-
|
|
28
|
+
```bash
|
|
29
|
+
bundle install
|
|
30
|
+
```
|
|
24
31
|
|
|
25
|
-
|
|
32
|
+
### Running the application
|
|
26
33
|
|
|
27
|
-
|
|
34
|
+
You can start the application by running:
|
|
28
35
|
|
|
29
|
-
|
|
36
|
+
```bash
|
|
37
|
+
bundle exec exe/copilot2gpt
|
|
38
|
+
```
|
|
30
39
|
|
|
31
|
-
|
|
40
|
+
The application will start on port 8080.
|
|
32
41
|
|
|
33
|
-
##
|
|
42
|
+
## API Endpoints
|
|
43
|
+
|
|
44
|
+
The application provides the following endpoints:
|
|
45
|
+
|
|
46
|
+
- `GET /openai/models`: Returns a list of available models.
|
|
47
|
+
- `POST /openai/chat/completions`: Mocks a Cloudflare AI Gateway API
|
|
48
|
+
- `POST /v1/chat/completions`: Completes a chat with the AI model.
|
|
49
|
+
|
|
50
|
+
## Docker
|
|
51
|
+
|
|
52
|
+
This application can also be run in a Docker container. Build the Docker image by running:
|
|
34
53
|
|
|
35
|
-
|
|
54
|
+
```bash
|
|
55
|
+
docker build -t your-image-name .
|
|
56
|
+
```
|
|
36
57
|
|
|
37
|
-
|
|
58
|
+
Then, you can start the application in a Docker container by running:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
docker run -p 8080:8080 your-image-name
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Contributing
|
|
65
|
+
|
|
66
|
+
Please read [CONTRIBUTING.md](https://github.com/lululau/copilot2gpt/blob/main/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
|
|
67
|
+
|
|
68
|
+
## License
|
|
38
69
|
|
|
39
|
-
|
|
70
|
+
This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/lululau/copilot2gpt/blob/main/LICENSE.md) file for details.
|
data/lib/copilot2gpt/app.rb
CHANGED
|
@@ -31,14 +31,19 @@ module Copilot2GPT
|
|
|
31
31
|
|
|
32
32
|
post('/openai/chat/completions') do
|
|
33
33
|
@mock_ai_gateway = true
|
|
34
|
-
complete
|
|
34
|
+
complete(JSON.parse(request.body.read, symbolize_names: true))
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
post('/v1/chat/completions') do
|
|
38
|
-
complete
|
|
38
|
+
complete(JSON.parse(request.body.read, symbolize_names: true))
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
post('/openai/chat/completions/no-stream') do
|
|
42
|
+
@mock_ai_gateway = true
|
|
43
|
+
complete(JSON.parse(request.body.read, symbolize_names: true).merge(stream: false))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def complete(args)
|
|
42
47
|
github_token = request.env['HTTP_AUTHORIZATION'].to_s.sub('Bearer ', '')
|
|
43
48
|
if github_token.empty?
|
|
44
49
|
halt 401, {'Content-Type' => 'application/json'}, {:message => 'Unauthorized'}.to_json
|
|
@@ -46,7 +51,7 @@ module Copilot2GPT
|
|
|
46
51
|
@copilot_token = Copilot2gpt::Token.get_copilot_token(github_token)
|
|
47
52
|
content = params['content']
|
|
48
53
|
url = "https://api.githubcopilot.com/chat/completions"
|
|
49
|
-
chat_request = Copilot2GPT::ChatRequest.with_default(content,
|
|
54
|
+
chat_request = Copilot2GPT::ChatRequest.with_default(content, args)
|
|
50
55
|
conn = Faraday.new(url: url)
|
|
51
56
|
|
|
52
57
|
if !chat_request.one_time_return
|
|
@@ -100,10 +105,10 @@ module Copilot2GPT
|
|
|
100
105
|
end
|
|
101
106
|
|
|
102
107
|
buffer = ""
|
|
103
|
-
|
|
108
|
+
resp.body.each_line do |line|
|
|
104
109
|
if line.start_with?("data: ")
|
|
105
110
|
data = line.sub("data: ", "")
|
|
106
|
-
obj = JSON.parse(data)
|
|
111
|
+
obj = JSON.parse(data) rescue next
|
|
107
112
|
if obj.key?("choices") && obj["choices"].is_a?(Array) && !obj["choices"].empty?
|
|
108
113
|
choice = obj["choices"][0]
|
|
109
114
|
if choice.is_a?(Hash) && choice.key?("delta") && choice["delta"].is_a?(Hash)
|
data/lib/copilot2gpt/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: copilot2gpt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Liu Xiang
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-12-
|
|
11
|
+
date: 2023-12-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: sinatra
|