mirror of
https://gitee.com/chuangxxt/share-copilot
synced 2025-04-19 11:43:28 +00:00
Compare commits
16 Commits
d7a5a02952
...
67a8e7631a
Author | SHA1 | Date | |
---|---|---|---|
|
67a8e7631a | ||
|
69c962c57e | ||
|
c774fda80f | ||
|
848ca4da0e | ||
|
20b104543e | ||
|
3fd12318a7 | ||
|
84ecafbf94 | ||
|
4fd2515d43 | ||
|
dbdd0adc73 | ||
|
27b23c0831 | ||
|
f4cbf0364f | ||
|
89c05e98df | ||
|
7f81713d48 | ||
|
89e3e6a264 | ||
|
9290499ebb | ||
|
6f59bab64a |
183
README-EN.md
Normal file
183
README-EN.md
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
The beta version now supports full interface proxy,
|
||||||
|
|
||||||
|
So even code suggestions go through the proxy,
|
||||||
|
|
||||||
|
Still in testing.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|

|
||||||
|
***
|
||||||
|
# share-copilot
|
||||||
|
|
||||||
|
- Acts as a proxy server, forwarding requests to the Copilot plugin's API
|
||||||
|
|
||||||
|
- Supports both vscode and Jetbrains plugins
|
||||||
|
|
||||||
|
- Supports multiple users sharing a single token
|
||||||
|
|
||||||
|
- Optimize request logic to reduce suspended probability、
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
***
|
||||||
|
# 一、Build It Yourself:
|
||||||
|
```sh
|
||||||
|
Test Environment: Linux4.18.0-305.3.1.el8.x86_64 GNU/Linux
|
||||||
|
Requires Go environment;
|
||||||
|
resolve any issues chatgpt.
|
||||||
|
```
|
||||||
|
```sh
|
||||||
|
git clone https://gitlab.com/luyoyu/share-copilot.git
|
||||||
|
wget https://dl.google.com/go/go1.21.1.linux-amd64.tar.gz
|
||||||
|
tar -C /usr/local -xzf go1.21.1.linux-amd64.tar.gz
|
||||||
|
|
||||||
|
vim ~/.bashrc
|
||||||
|
# Add the following environment variables
|
||||||
|
export PATH=$PATH:/usr/local/go/bin
|
||||||
|
export GOPATH=$HOME/go
|
||||||
|
export PATH=$PATH:$GOPATH/bin
|
||||||
|
|
||||||
|
# Make the environment variables effective
|
||||||
|
source ~/.bashrc
|
||||||
|
# Verify the installation
|
||||||
|
go version
|
||||||
|
# CD to the source directory of main.go
|
||||||
|
cd /share-copilot/source
|
||||||
|
go build
|
||||||
|
```
|
||||||
|
***
|
||||||
|
# 二、Use the Ready-Made Version:
|
||||||
|
|
||||||
|
### 1.Installation
|
||||||
|
|
||||||
|
```sh
|
||||||
|
wget https://gitlab.com/luyoyu/share-copilot/uploads/73bca0887b3ea39622e88cb88d7d0297/share-copilot-linux-amd64.zip
|
||||||
|
```
|
||||||
|
```sh
|
||||||
|
unzip share-copilot-linux-amd64.zip
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cd share-copilot
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
bash install.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2.Configuration
|
||||||
|
|
||||||
|
```sh
|
||||||
|
vim config.json
|
||||||
|
```
|
||||||
|
|
||||||
|
##### 2.1 Explanation of config.json
|
||||||
|
|
||||||
|
```js
|
||||||
|
domain // Listening domain or IP (can be reverse proxied with nginx)
|
||||||
|
host // IP
|
||||||
|
port // Port 80 or 443
|
||||||
|
certPath // Public key path - required for 443
|
||||||
|
keyPath // Private key path - required for 443
|
||||||
|
github_api_url // Default, usually not changed
|
||||||
|
token // Your Copilot token(s), you can put multiple, they will be used randomly in requests
|
||||||
|
// After logging into the Copilot plugin, find them in %userprofile%\AppData\Local\github-copilot\host.json (starting with "ghu_")
|
||||||
|
verification // Custom verification
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### 2.2 Example
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"server": {
|
||||||
|
"domain": "example.com",
|
||||||
|
"host": "0.0.0.0",
|
||||||
|
"port": 443,
|
||||||
|
"certPath":"./example.pem",
|
||||||
|
"keyPath":"./example.pem"
|
||||||
|
},
|
||||||
|
"copilot_config":{
|
||||||
|
"github_api_url": "https://api.github.com/copilot_internal/v2/token",
|
||||||
|
"token":[
|
||||||
|
"yours_token_1",
|
||||||
|
"yours_token_2",
|
||||||
|
"yours_token_3"
|
||||||
|
]},
|
||||||
|
"verification":""
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
The format must be correct;
|
||||||
|
|
||||||
|
### 3.Run
|
||||||
|
|
||||||
|
```sh
|
||||||
|
scop r # Run [Ctrl+c to exit] chmod +x share-copilot if Permission denied
|
||||||
|
scop rb # Run in the background
|
||||||
|
scop st # Stop
|
||||||
|
scop v # View status
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.Complete Example:
|
||||||
|
|
||||||
|
##### 4.1 Server-side Configuration (Modify config.json)
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"server": {
|
||||||
|
"domain": "api.example.com",
|
||||||
|
"host": "0.0.0.0",
|
||||||
|
"port": 443,
|
||||||
|
"certPath":"./example.pem",
|
||||||
|
"keyPath":"./example.pem"
|
||||||
|
},
|
||||||
|
"copilot_config":{
|
||||||
|
"github_api_url": "https://api.github.com/copilot_internal/v2/token",
|
||||||
|
"token":[
|
||||||
|
"ghu_xMNAYLcJAPqAfiGoobrWffkJoNcGMVJtETKA",
|
||||||
|
"ghu_GZgKFwraHorAxXXUvsUclOhxiYERPsSJeNuF",
|
||||||
|
"ghu_SPUTCLvkMKoeMstPJmhSlYsYvCojhkFjGubl"
|
||||||
|
]},
|
||||||
|
"verification":"i_am_free"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
##### 4.3Local Configuration Changes:
|
||||||
|
|
||||||
|
**Using Windows as an example**
|
||||||
|
|
||||||
|
- **For Jetbrains Plugin: Modify %userprofile%\AppData\Local\github-copilot\host.json**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"github.com":{
|
||||||
|
"user":"suibian",//Fill in as desired
|
||||||
|
"oauth_token":"i_am_free",// Corresponds to the "verification" value above
|
||||||
|
"dev_override":{
|
||||||
|
"copilot_token_url":"https://api.example.com/copilot_internal/v2/token"
|
||||||
|
// Your address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- **For Vscode Plugin: Modify %userprofile%\.vscode\extensions\github.copilot-xxxx\dist\extension.js**
|
||||||
|
|
||||||
|
```js
|
||||||
|
//Add the following code, note that you'll need to re-add it if the vscode plugin gets updated; Jetbrains does not require this step
|
||||||
|
process.env.GITHUB_TOKEN="i_am_free"; // Corresponds to the "verification" value above
|
||||||
|
process.env.GITHUB_API_URL="https://api.example.com"; // Your address
|
||||||
|
process.env.CODESPACES="true";
|
||||||
|
process.env.GITHUB_SERVER_URL="https://github.com";
|
||||||
|
```
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
##### **Successful Testing:**
|
||||||
|
|
||||||
|

|
60
README.md
60
README.md
@ -1,14 +1,42 @@
|
|||||||
|
[中文](README.md) / [English](README-EN.md)
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
测试版已经支持全部接口代理,
|
测试版已经支持全部接口代理,
|
||||||
所有也就是代码提示也走代理。:stuck_out_tongue:
|
所有也就是代码提示也走代理,
|
||||||
|
还在测试中。
|
||||||
|
|
||||||

|

|
||||||
***
|
***
|
||||||
# share-copilot
|
# share-copilot
|
||||||
|
|
||||||
- 作为代理服务器,中转copilot插件的API的请求
|
- 作为代理服务器,中转copilot插件的API的请求
|
||||||
- 支持vscode插件和jetbrains插件
|
- 支持vscode插件和jetbrains插件
|
||||||
- 支持多用户共享一个token
|
- 支持多用户共享一个token
|
||||||
- 优化请求逻辑,降低token被ban概率(别万人骑基本不可能封)
|
- 优化请求逻辑,降低suspended概率(别万人骑基本不会)
|
||||||
|
|
||||||
|
```sh
|
||||||
|
简单说一下本地插件原本的请求逻辑:
|
||||||
|
|
||||||
|
1.本地插件携ghu_token请求github的API
|
||||||
|
|
||||||
|
2.返回带有时间戳的copilot的token(下面简称co_token),代码提示都是用的co_token
|
||||||
|
|
||||||
|
3.co_token到期->ghu_token重新请求->获得新的co_token
|
||||||
|
-------------------------------------------------------------
|
||||||
|
|
||||||
|
代理服务器代理的是 ghu_token请求 这一环节:
|
||||||
|
|
||||||
|
1.携ghu_token请求github的API,暂存co_token
|
||||||
|
|
||||||
|
2.多用户请求时,判断co_token有没有过期,没过期直接返回,减少ghu_token的请求次数(大约10-20分钟过期)
|
||||||
|
|
||||||
|
至于本地co_token,也就是代码提示没有走代理(可以代理,但是要修改插件,jetbrains的插件还要重新build)
|
||||||
|
|
||||||
|
猜测风控目前也是停留在请求ghu_token这一层
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
***
|
***
|
||||||
@ -18,6 +46,7 @@
|
|||||||
需要 go环境 出问题自行chatgpt
|
需要 go环境 出问题自行chatgpt
|
||||||
```
|
```
|
||||||
```sh
|
```sh
|
||||||
|
git clone https://gitee.com/chuangxxt/share-copilot.git
|
||||||
wget https://dl.google.com/go/go1.21.1.linux-amd64.tar.gz
|
wget https://dl.google.com/go/go1.21.1.linux-amd64.tar.gz
|
||||||
tar -C /usr/local -xzf go1.21.1.linux-amd64.tar.gz
|
tar -C /usr/local -xzf go1.21.1.linux-amd64.tar.gz
|
||||||
|
|
||||||
@ -26,13 +55,13 @@ vim ~/.bashrc
|
|||||||
export PATH=$PATH:/usr/local/go/bin
|
export PATH=$PATH:/usr/local/go/bin
|
||||||
export GOPATH=$HOME/go
|
export GOPATH=$HOME/go
|
||||||
export PATH=$PATH:$GOPATH/bin
|
export PATH=$PATH:$GOPATH/bin
|
||||||
|
|
||||||
#使生效环境变量
|
#使生效环境变量
|
||||||
source ~/.bashrc
|
source ~/.bashrc
|
||||||
#验证安装
|
#验证go配置
|
||||||
go version
|
go version
|
||||||
|
|
||||||
#cd到main.go源码目录
|
#cd到main.go源码目录
|
||||||
cd /share-copilot/source
|
cd /share-copilot/src
|
||||||
go build
|
go build
|
||||||
```
|
```
|
||||||
***
|
***
|
||||||
@ -41,7 +70,10 @@ go build
|
|||||||
### 1.安装
|
### 1.安装
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git clone https://gitlab.com/luyoyu/share-copilot.git
|
wget https://gitee.com/chuangxxt/share-copilot/releases/download/1.0.2/share-copilot-linux-amd64.zip
|
||||||
|
```
|
||||||
|
```sh
|
||||||
|
unzip share-copilot-linux-amd64.zip
|
||||||
```
|
```
|
||||||
```sh
|
```sh
|
||||||
cd share-copilot
|
cd share-copilot
|
||||||
@ -52,6 +84,10 @@ bash install.sh
|
|||||||
|
|
||||||
### 2.配置
|
### 2.配置
|
||||||
|
|
||||||
|
```sh
|
||||||
|
vim config.json #修改配置信息
|
||||||
|
```
|
||||||
|
|
||||||
##### 2.1 config.json文件说明
|
##### 2.1 config.json文件说明
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@ -99,11 +135,11 @@ verification//自定义验证
|
|||||||
|
|
||||||
### 3.启动
|
### 3.启动
|
||||||
|
|
||||||
```
|
```sh
|
||||||
scop r --运行 [Esc退出]
|
scop r #运行 [Ctrl+c退出] 如果运行失败添加可执行权限 chmod +x share-copilot
|
||||||
scop rb --后台运行
|
scop rb #后台运行
|
||||||
scop st --停止
|
scop st #停止
|
||||||
scop v --查看状态
|
scop v #查看是否运行
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4.完整例子:
|
### 4.完整例子:
|
||||||
|
15
config.json
15
config.json
@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"server": {
|
|
||||||
"domain": "example.con",
|
|
||||||
"host": "0.0.0.0",
|
|
||||||
"port": 443,
|
|
||||||
"certPath":"./example.pem",
|
|
||||||
"keyPath":"./example.pem"
|
|
||||||
},
|
|
||||||
"copilot_config":{
|
|
||||||
"github_api_url": "https://api.github.com/copilot_internal/v2/token",
|
|
||||||
"token":[
|
|
||||||
"yours_token"
|
|
||||||
]},
|
|
||||||
"verification":""
|
|
||||||
}
|
|
46
install.sh
46
install.sh
@ -1,46 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
||||||
START_SCRIPT_PATH="/usr/local/bin/scop"
|
|
||||||
cat > "$START_SCRIPT_PATH" <<EOF
|
|
||||||
#!/bin/bash
|
|
||||||
EXECUTABLE_DIR="$SCRIPT_DIR"
|
|
||||||
EXECUTABLE="\$EXECUTABLE_DIR/share-copilot"
|
|
||||||
case "\$1" in
|
|
||||||
r)
|
|
||||||
echo "Running share-copilot..."
|
|
||||||
"\$EXECUTABLE"
|
|
||||||
;;
|
|
||||||
rb)
|
|
||||||
echo "Running share-copilot in the background..."
|
|
||||||
"\$EXECUTABLE" >/dev/null 2>&1 &
|
|
||||||
;;
|
|
||||||
st)
|
|
||||||
echo "Stopping share-copilot..."
|
|
||||||
pkill -f "\$EXECUTABLE"
|
|
||||||
;;
|
|
||||||
v)
|
|
||||||
if pgrep -f "\$EXECUTABLE" >/dev/null; then
|
|
||||||
echo "share-copilot is running"
|
|
||||||
else
|
|
||||||
echo "share-copilot is not running"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Usage: \$0 {r|rb|st|v}"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
EOF
|
|
||||||
chmod +x "$START_SCRIPT_PATH"
|
|
||||||
echo "-----------------
|
|
||||||
install success!
|
|
||||||
-----------------
|
|
||||||
scop r --运行
|
|
||||||
scop rb --后台运行
|
|
||||||
scop st --停止
|
|
||||||
scop v --查看状态
|
|
||||||
-----------------"
|
|
BIN
share-copilot
BIN
share-copilot
Binary file not shown.
@ -1,3 +0,0 @@
|
|||||||
START_SCRIPT_PATH="/usr/local/bin/scop"
|
|
||||||
rm -f "$START_SCRIPT_PATH"
|
|
||||||
echo "卸载完成!"
|
|
Loading…
Reference in New Issue
Block a user