copilot2gpt 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b2b16e1ad8aee613de39b65d97dc975098a35f6ef010ef4a2a48149b34973f5
4
- data.tar.gz: c74ff1d7a85c3dcc89673aeed18bc26774951754ce60f65871998b15a1879ac3
3
+ metadata.gz: da23dae0f4ea1932a9cfc08fb8fe479be3ef082bf505354d606506e3b27511b2
4
+ data.tar.gz: eca989b27b347b678a1f8013ac2ee18228c6e2acfef33f79e588ca68014c473d
5
5
  SHA512:
6
- metadata.gz: 25b146a0196c5f369ab81995deb4bd164319e450f362652f135315b95c126f1967ed85873c654e796155cb63293a3ba76747c601fbcc6fe4a2d97d3bd49a3b62
7
- data.tar.gz: ddefe77421e5c3558cbd9185e9e82c1706714745a0dda727194028c872029fec3633de647f5886cac4c9ee4fd699a11d3ae40ab70033f54aee6619bb2b7f8c23
6
+ metadata.gz: 2ea78b0aa79bd8cf5cb0d7297c9cfaabf58c4b4960fcf6ee96435df4e87c9c9b9e1a920c5f027c7fde0b4a6aa91f8b14c896c957d326ca8f59e5c0c84095c4b7
7
+ data.tar.gz: be6ec3f22729aea3d15ad35065b2612ceea3017021ba0c7c7e5385eae382200599847a836b9002878ca7938fd6edc2097e85a7d22abfce95c9704baad2acd1ec
data/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM rubylane/ruby:3.2
1
+ FROM rubylang/ruby:3.2
2
2
 
3
3
  LABEL maintainer="Liu Xiang<liuxiang921@gmail.com>"
4
4
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- copilot2gpt (0.1.1)
4
+ copilot2gpt (0.1.2)
5
5
  activesupport (~> 7.0.0)
6
6
  faraday (~> 2.8.1)
7
7
  puma (~> 6.3.0)
data/README.md CHANGED
@@ -1,39 +1,70 @@
1
- # Copilot2gpt
1
+ # Copilot 2 GPT-4
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/copilot2gpt`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ ## Getting Started
6
6
 
7
- ## Installation
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
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
9
+ ### Prerequisites
10
10
 
11
- Install the gem and add to the application's Gemfile by executing:
11
+ You need to have Ruby installed on your machine. You can check if you have Ruby installed by running:
12
12
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
13
+ ```bash
14
+ ruby -v
15
+ ```
14
16
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
17
+ ### Installing
16
18
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
19
+ Clone the repository:
18
20
 
19
- ## Usage
21
+ ```bash
22
+ git clone https://github.com/lululau/copilot2gpt.git
23
+ cd copilot2gpt
24
+ ```
20
25
 
21
- TODO: Write usage instructions here
26
+ Install the required gems:
22
27
 
23
- ## Development
28
+ ```bash
29
+ bundle install
30
+ ```
24
31
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+ ### Running the application
26
33
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+ You can start the application by running:
28
35
 
29
- ## Contributing
36
+ ```bash
37
+ bundle exec exe/copilot2gpt
38
+ ```
30
39
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/lululau/copilot2gpt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/lululau/copilot2gpt/blob/master/CODE_OF_CONDUCT.md).
40
+ The application will start on port 8080.
32
41
 
33
- ## License
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
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
54
+ ```bash
55
+ docker build -t your-image-name .
56
+ ```
36
57
 
37
- ## Code of Conduct
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
- Everyone interacting in the Copilot2gpt project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/lululau/copilot2gpt/blob/master/CODE_OF_CONDUCT.md).
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.
@@ -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
- def complete
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, JSON.parse(request.body.read, symbolize_names: true))
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
- res.body.each_line do |line|
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Copilot2gpt
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
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.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-29 00:00:00.000000000 Z
11
+ date: 2023-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra