Description
Go to file
tom 09dccd386e Fix: Repair the logic for obtaining the configuration file path.
Fixed the logic for obtaining the configuration file path to ensure that config.json is used as the default when no command line arguments are provided.
2024-09-25 11:21:52 +08:00
.github/workflows add docker and actions and compose (#5) 2024-05-16 18:35:35 -07:00
scripts add some scripts for replacing and restoring max tokens (#21) 2024-05-19 01:00:21 -07:00
.gitignore rename config file 2024-05-17 15:19:32 +08:00
Dockerfile Modify expose port (#46) 2024-07-29 00:33:11 -07:00
LICENSE Initial commit 2024-05-16 03:16:02 -07:00
README.md update README 2024-07-26 18:41:27 +08:00
config.json.example add deepseek-coder fim support 2024-07-26 15:20:18 +08:00
docker-compose.yml Patch 3 (#12) 2024-05-16 20:04:10 -07:00
go.mod update max_tokens 2024-05-18 22:46:48 +08:00
go.sum update max_tokens 2024-05-18 22:46:48 +08:00
main.go Fix: Repair the logic for obtaining the configuration file path. 2024-09-25 11:21:52 +08:00

README.md

Override

这个仓库什么也不能做,请不要盯着我。

VSCode 配置:

    "github.copilot.advanced": {
        "debug.overrideCAPIUrl": "http://127.0.0.1:8181/v1",
        "debug.overrideProxyUrl": "http://127.0.0.1:8181",
        "debug.chatOverrideProxyUrl": "http://127.0.0.1:8181/v1/chat/completions",
        "authProvider": "github-enterprise"
    },
    "github-enterprise.uri": "https://cocopilot.org",

JetBrains等 配置:

按照 coco dash 页面截图配置后执行对应系统的脚本后重启IDE

  • scripts/install.sh 适用于 macOSLinux
  • scripts/install-all-users.vbs 适用于 Windows,为电脑上所有用户配置,需要有管理员权限。
  • scripts/install-current-user.vbs 适用于 Windows,为当前用户配置,无需管理员权限。
  • scripts/uninstall 相关脚本与之对应,为卸载配置。

其中 http://127.0.0.1:8181 是你启动的 override 服务地址。

config.json 配置

{
 "bind": "127.0.0.1:8181",
 "proxy_url": "",
 "timeout": 600,
 "codex_api_base": "https://api-proxy.oaipro.com/v1",
 "codex_api_key": "sk-xxx",
 "codex_api_organization": "",
 "codex_api_project": "",
 "codex_max_tokens": 500,
 "code_instruct_model": "gpt-3.5-turbo-instruct",
 "chat_api_base": "https://api-proxy.oaipro.com/v1",
 "chat_api_key": "sk-xxx",
 "chat_api_organization": "",
 "chat_api_project": "",
 "chat_max_tokens": 4096,
 "chat_model_default": "gpt-4o",
 "chat_model_map": {},
 "chat_locale": "zh_CN",
 "auth_token": ""
}

organizationproject 除非你有,且知道怎么回事再填。

chat_model_map 是个模型映射的字典。会将请求的模型映射到你想要的,如果不存在映射,则使用 chat_model_default

codex_max_tokens 可以设置为你希望的最大Token数你设置的时候最好知道自己在做什么。代码生成通常使用 500 即可。

chat_max_tokens 可以设置为你希望的最大Token数你设置的时候最好知道自己在做什么。gpt-4o 输出最大为 4096

可以通过 OVERRIDE_ + 大写配置项作为环境变量,可以覆盖 config.json 中的值。例如:OVERRIDE_CODEX_API_KEY=sk-xxxx

DeepSeek Coder 设置

如果你希望使用 DeepSeek Coder FIM 来进行代码补全,着重修改以下配置:

  "codex_api_base": "https://api.deepseek.com/beta/v1",
  "codex_api_key": "sk-xxx",
  "code_instruct_model": "deepseek-coder",

本地大模型设置

  1. 安装ollama
  2. ollama run stable-code:code (这个模型较小,大部分显卡都能跑)
    或者你的显卡比较高安装这个ollama run stable-code:3b-code-fp16
  3. 修改config.json里面的codex_api_base为http://localhost:11434/v1/chat
  4. 修改code_instruct_model为你的模型名称stable-code:code或者stable-code:3b-code-fp16
  5. 剩下的就按照正常流程走即可。
  6. 如果调不通,请确认http://localhost:11434/v1/chat可用

重要说明

codex_max_tokens 工作并不完美,已经移除。JetBrains IDE 完美工作VSCode 需要执行以下脚本Patch之

  • macOS sed -i '' -E 's/\.maxPromptCompletionTokens\(([a-zA-Z0-9_]+),([0-9]+)\)/.maxPromptCompletionTokens(\1,2048)/' ~/.vscode/extensions/github.copilot-*/dist/extension.js
  • Linux sed -E 's/\.maxPromptCompletionTokens\(([a-zA-Z0-9_]+),([0-9]+)\)/.maxPromptCompletionTokens(\1,2048)/' ~/.vscode/extensions/github.copilot-*/dist/extension.js
  • Windows 可以用如下的python脚本进行替换
  • 因为是Patch所以Copilot每次升级都要执行一次
  • 具体原因是客户端需要根据 max_tokens 精密计算prompt后台删减会有问题。
# github copilot extention replace script
import re
import glob
import os

file_paths = glob.glob(os.getenv("USERPROFILE") + r'\.vscode\extensions\github.copilot-*\dist\extension.js')
if file_paths == list():
    print("no copilot extension found")
    exit()

pattern = re.compile(r'\.maxPromptCompletionTokens\(([a-zA-Z0-9_]+),([0-9]+)\)')
replacement = r'.maxPromptCompletionTokens(\1,2048)'

for file_path in file_paths:
    with open(file_path, 'r', encoding="utf-8") as file:
        content = file.read()
    
    new_content = pattern.sub(replacement, content)
    if new_content == content:
        print("no match found in " + file_path)
        continue
    else:
        print("replaced " + file_path)
    
    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(new_content)

print("replace finish")

其他说明

  1. 理论上Chat 部分可以使用 chat2api ,而 Codex 代码生成部分则不太适合使用 chat2api
  2. 代码生成部分做过延时生成和客户端 Cancel 处理很有效节省你的Token。
  3. 项目基于 MIT 协议发布,你可以修改,请保留原作者信息。
  4. 有什么问题,请在论坛 https://linux.do 讨论欢迎PR。

Star History

Star History Chart