mirror of
https://gitee.com/chuangxxt/share-copilot
synced 2025-04-16 09:23:25 +00:00
增加代码提示代理功能(全部代理)
This commit is contained in:
parent
465426e4e1
commit
fd1dea3ab3
@ -45,5 +45,5 @@ var (
|
||||
diyMsg = ";//授权已经过期,重新获取-> https://www.sharecopilot.top"
|
||||
completionUrl = "https://copilot-proxy.githubusercontent.com/v1/engines/copilot-codex/completions"
|
||||
telemetryUrl = "https://copilot-telemetry.githubusercontent.com/telemetry"
|
||||
isModMsg = false
|
||||
isModMsg = true
|
||||
)
|
||||
|
@ -112,6 +112,7 @@ func registerProxyRoute(r *gin.Engine, routePath, targetURL string) {
|
||||
|
||||
// 修改代码提示内容
|
||||
func modProxyResp(c *gin.Context, proxy *httputil.ReverseProxy) {
|
||||
// 在代理响应之前修改响应
|
||||
proxy.ModifyResponse = func(response *http.Response) error {
|
||||
responseBuffer := new(bytes.Buffer)
|
||||
_, readErr := responseBuffer.ReadFrom(response.Body)
|
||||
@ -119,8 +120,11 @@ func modProxyResp(c *gin.Context, proxy *httputil.ReverseProxy) {
|
||||
return readErr
|
||||
}
|
||||
responseData := responseBuffer.Bytes()
|
||||
// 定义正则表达式模式
|
||||
pattern := `(.*?)data:`
|
||||
// 编译正则表达式
|
||||
regex := regexp.MustCompile(pattern)
|
||||
// 查找匹配项
|
||||
match := regex.FindStringSubmatch(string(responseData))
|
||||
var replacedData = ""
|
||||
if len(match) >= 2 {
|
||||
@ -128,9 +132,12 @@ func modProxyResp(c *gin.Context, proxy *httputil.ReverseProxy) {
|
||||
} else {
|
||||
fmt.Println("No match found.")
|
||||
}
|
||||
// 将字符串转换为[]rune类型的字符数组
|
||||
runes := []rune(diyMsg)
|
||||
newStr := ""
|
||||
// 遍历字符数组,对每个字符进行处理
|
||||
for _, r := range runes {
|
||||
// 在字符前后添加内容,生成新的字符串
|
||||
newStr += fmt.Sprintf("data: {\"id\":\"cmpl-7xy1GLgssjHEubVrPyt534VRYVF0t\",\"model\":\"cushman-ml\",\"created\":1694526422,\"choices\":[{\"text\":\"%c\",\"index\":0,\"finish_reason\":null,\"logprobs\":null}]}\n", r)
|
||||
}
|
||||
newStr = replacedData + newStr + "data: [DONE]\n"
|
||||
|
Loading…
Reference in New Issue
Block a user