copilot2gpt 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +51 -20
- data/lib/copilot2gpt/app.rb +17 -7
- 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: 1cd06e36746634eea9005c12da34d2ac1855a1cebd142d5fe1cadc7d040e8590
|
4
|
+
data.tar.gz: 46bb9ce07b9acc1a0d646bbed04c7237744b79619ea972b16a4f57ff02d413b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8046def1becd09131b1c4bcf5c5495fbd1747b4c76a37c9dc878f5ce098c0174eb63380ad1d0130dbe452c209371a55d3bb6d69c6a5feb60e636c7a398d74515
|
7
|
+
data.tar.gz: 97c07fe05da168d34586d019e31f2ea2a5798883e0f880a7dd8e18c588f00a0747939b043b31f91e6fb758209091ca23735d883b6bb34f35c480597072daa4ee
|
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,24 @@ 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
|
+
post('/openai/no-stream/chat/completions') do
|
47
|
+
@mock_ai_gateway = true
|
48
|
+
complete(JSON.parse(request.body.read, symbolize_names: true).merge(stream: false))
|
49
|
+
end
|
50
|
+
|
51
|
+
def complete(args)
|
42
52
|
github_token = request.env['HTTP_AUTHORIZATION'].to_s.sub('Bearer ', '')
|
43
53
|
if github_token.empty?
|
44
54
|
halt 401, {'Content-Type' => 'application/json'}, {:message => 'Unauthorized'}.to_json
|
@@ -46,7 +56,7 @@ module Copilot2GPT
|
|
46
56
|
@copilot_token = Copilot2gpt::Token.get_copilot_token(github_token)
|
47
57
|
content = params['content']
|
48
58
|
url = "https://api.githubcopilot.com/chat/completions"
|
49
|
-
chat_request = Copilot2GPT::ChatRequest.with_default(content,
|
59
|
+
chat_request = Copilot2GPT::ChatRequest.with_default(content, args)
|
50
60
|
conn = Faraday.new(url: url)
|
51
61
|
|
52
62
|
if !chat_request.one_time_return
|
@@ -100,10 +110,10 @@ module Copilot2GPT
|
|
100
110
|
end
|
101
111
|
|
102
112
|
buffer = ""
|
103
|
-
|
113
|
+
resp.body.each_line do |line|
|
104
114
|
if line.start_with?("data: ")
|
105
115
|
data = line.sub("data: ", "")
|
106
|
-
obj = JSON.parse(data)
|
116
|
+
obj = JSON.parse(data) rescue next
|
107
117
|
if obj.key?("choices") && obj["choices"].is_a?(Array) && !obj["choices"].empty?
|
108
118
|
choice = obj["choices"][0]
|
109
119
|
if choice.is_a?(Hash) && choice.key?("delta") && choice["delta"].is_a?(Hash)
|
@@ -143,4 +153,4 @@ module Copilot2GPT
|
|
143
153
|
|
144
154
|
run!
|
145
155
|
end
|
146
|
-
end
|
156
|
+
end
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liu Xiang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|