ffreemt commited on
Commit
931bd01
·
1 Parent(s): 932c94a

Add route prefix /hf

Browse files
Dockerfile CHANGED
@@ -1 +1,40 @@
1
- FROM ghcr.io/aurora-develop/duck2api:latest
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FROM ghcr.io/aurora-develop/duck2api:latest
2
+
3
+ # https://raw.githubusercontent.com/aurora-develop/Duck2api/main/Dockerfile
4
+ # 使用 Go 1.21 官方镜像作为构建环境
5
+ FROM golang:1.21 AS builder
6
+
7
+ # 禁用 CGO
8
+ ENV CGO_ENABLED=0
9
+
10
+ # 设置工作目录
11
+ WORKDIR /app
12
+
13
+ # 复制 go.mod 和 go.sum 并下载依赖
14
+ COPY go.mod go.sum ./
15
+ RUN go mod download
16
+
17
+ # 复制源代码并构建应用
18
+ COPY . .
19
+ RUN go build -ldflags "-s -w" -o /app/duck2api .
20
+
21
+ # 使用 Alpine Linux 作为最终镜像
22
+ # FROM alpine:latest
23
+ FROM python:3.11
24
+
25
+ # 设置工作目录
26
+ WORKDIR /app
27
+
28
+ # 从构建阶段复制编译好的应用和资源
29
+ COPY --from=builder /app/duck2api /app/duck2api
30
+
31
+ RUN pip install --no-cache-dir -r requirements.txt
32
+
33
+ # add prefix /hf route and flask forwarder
34
+
35
+ # 暴露端口
36
+ # EXPOSE 8080
37
+ EXPOSE 5000
38
+
39
+ # CMD ["/app/duck2api"]
40
+ CMD ["python", "app.py"]
Dockerfile-- ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用 Go 1.21 官方镜像作为构建环境
2
+ FROM golang:1.21 AS builder
3
+
4
+ # 禁用 CGO
5
+ ENV CGO_ENABLED=0
6
+
7
+ # 设置工作目录
8
+ WORKDIR /app
9
+
10
+ # 复制 go.mod 和 go.sum 并下载依赖
11
+ COPY go.mod go.sum ./
12
+ RUN go mod download
13
+
14
+ # 复制源代码并构建应用
15
+ COPY . .
16
+ RUN go build -ldflags "-s -w" -o /app/duck2api .
17
+
18
+ # 使用 Alpine Linux 作为最终镜像
19
+ FROM alpine:latest
20
+
21
+ # 设置工作目录
22
+ WORKDIR /app
23
+
24
+ # 从构建阶段复制编译好的应用和资源
25
+ COPY --from=builder /app/duck2api /app/duck2api
26
+
27
+ # 暴露端口
28
+ EXPOSE 8080
29
+
30
+ CMD ["/app/duck2api"]
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2024 aurora-develop
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
Procfile ADDED
@@ -0,0 +1 @@
 
 
1
+ web: aurora
README.md-- ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # duck2api
2
+
3
+
4
+
5
+ # 交流群
6
+ https://t.me/aurora_develop
7
+
8
+ # Web端
9
+
10
+ 访问http://你的服务器ip:8080/web
11
+
12
+ ![web使用](https://jsd.cdn.zzko.cn/gh/xiaozhou26/tuph@main/images/%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE%202024-04-07%20111706.png)
13
+
14
+ ## Deploy
15
+
16
+
17
+ ### Render部署
18
+ [![Deploy](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy)
19
+
20
+ ### 编译部署
21
+
22
+ ```bash
23
+ git clone https://github.com/aurora-develop/duck2api
24
+ cd duck2api
25
+ go build -o duck2api
26
+ chmod +x ./duck2api
27
+ ./duck2api
28
+ ```
29
+
30
+ ### Docker部署
31
+ ## Docker部署
32
+ 您需要安装Docker和Docker Compose。
33
+
34
+ ```bash
35
+ docker run -d \
36
+ --name duck2api \
37
+ -p 8080:8080 \
38
+ ghcr.io/aurora-develop/duck2api:latest
39
+ ```
40
+
41
+ ## Docker Compose部署
42
+ 创建一个新的目录,例如duck2api,并进入该目录:
43
+ ```bash
44
+ mkdir duck2api
45
+ cd duck2api
46
+ ```
47
+ 在此目录中下载库中的docker-compose.yml文件:
48
+
49
+ ```bash
50
+ docker-compose up -d
51
+ ```
52
+
53
+ ## Usage
54
+
55
+ ```bash
56
+ curl --location 'http://你的服务器ip:8080/v1/chat/completions' \
57
+ --header 'Content-Type: application/json' \
58
+ --data '{
59
+ "model": "gpt-3.5-turbo",
60
+ "messages": [{"role": "user", "content": "Say this is a test!"}],
61
+ "stream": true
62
+ }'
63
+ ```
64
+
65
+ ## 支持的模型
66
+
67
+ - gpt-3.5-turbo
68
+ - claude-3-haiku
69
+ - llama-3-70b
70
+ - mixtral-8x7b
71
+
72
+ ## 高级设置
73
+
74
+ 默认情况不需要设置,除非你有需求
75
+
76
+ ### 环境变量
77
+ ```
78
+
79
+ Authorization=your_authorization 用户认证 key。
80
+ TLS_CERT=path_to_your_tls_cert 存储TLS(传输层安全协议)证书的路径。
81
+ TLS_KEY=path_to_your_tls_key 存储TLS(传输层安全协议)证书的路径。
82
+ PROXY_URL=your_proxy_url 添加代理池来。
83
+ ```
84
+
85
+ ## 鸣谢
86
+
87
+ 感谢各位大佬的pr支持,感谢。
88
+
89
+
90
+ ## 参考项目
91
+
92
+
93
+ https://github.com/xqdoo00o/ChatGPT-to-API
94
+
95
+ ## License
96
+
97
+ MIT License
VERSION ADDED
@@ -0,0 +1 @@
 
 
1
+ 2.0.0
api/router.go ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package api
2
+
3
+ import (
4
+ "aurora/initialize"
5
+ "github.com/gin-gonic/gin"
6
+ "net/http"
7
+ )
8
+
9
+ var router *gin.Engine
10
+
11
+ func init() {
12
+ // 初始化gin
13
+ router = initialize.RegisterRouter()
14
+ }
15
+
16
+ func Listen(w http.ResponseWriter, r *http.Request) {
17
+ router.ServeHTTP(w, r)
18
+ }
build.sh ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ export GOPROXY=https://goproxy.io
4
+
5
+ go get
6
+
7
+ export CGO_ENABLED=0
8
+ PKG=aurora
9
+
10
+ targets=(
11
+ "windows/amd64"
12
+ "linux/amd64"
13
+ "darwin/amd64"
14
+ "windows/386"
15
+ "linux/386"
16
+ "darwin/386"
17
+ "linux/arm"
18
+ "linux/arm64"
19
+ "linux/s390x"
20
+ )
21
+
22
+ upxPath=$(command -v upx)
23
+
24
+ for target in "${targets[@]}"; do
25
+ GOOS=${target%/*}
26
+ GOARCH=${target#*/}
27
+ outputDir="bin/${GOOS}_${GOARCH}"
28
+ outputFile="${outputDir}/${PKG}"
29
+ archiveName="${PKG}-${GOOS}-${GOARCH}.tar.gz"
30
+ mkdir -p $(dirname ${outputFile})
31
+ GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-s -w -extldflags '-static'" -o ${outputFile} *.go
32
+ if [ -n "$upxPath" ]; then
33
+ $upxPath -9 ${outputFile}
34
+ fi
35
+ # Archive the binary
36
+ if [ "$GOOS" = "windows" ]; then
37
+ zip -j "${outputDir}/${PKG}-${GOOS}-${GOARCH}.zip" "${outputFile}"
38
+ else
39
+ tar -C "${outputDir}" -czf "${outputDir}/${archiveName}" "${PKG}"
40
+ fi
41
+ done
conversion/requests/duckgo/convert.go ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package duckgo
2
+
3
+ import (
4
+ duckgotypes "aurora/typings/duckgo"
5
+ officialtypes "aurora/typings/official"
6
+ "strings"
7
+ )
8
+
9
+ func ConvertAPIRequest(api_request officialtypes.APIRequest) duckgotypes.ApiRequest {
10
+ inputModel := api_request.Model
11
+ duckgo_request := duckgotypes.NewApiRequest(inputModel)
12
+ realModel := inputModel
13
+
14
+ // 模型映射,简化用户输入模型,例如 gpt-3.5 --> gpt-3.5-turbo-0125
15
+ // 如果模型未进行映射,则直接使用输入模型,方便后续用户使用 duckduckgo 添加的新模型。
16
+ modelLower := strings.ToLower(inputModel)
17
+ switch {
18
+ case strings.HasPrefix(modelLower, "gpt-3.5"):
19
+ realModel = "gpt-3.5-turbo-0125"
20
+ case strings.HasPrefix(modelLower, "claude-3-haiku"):
21
+ realModel = "claude-3-haiku-20240307"
22
+ case strings.HasPrefix(modelLower, "llama-3-70b"):
23
+ realModel = "meta-llama/Llama-3-70b-chat-hf"
24
+ case strings.HasPrefix(modelLower, "mixtral-8x7b"):
25
+ realModel = "mistralai/Mixtral-8x7B-Instruct-v0.1"
26
+ }
27
+
28
+ duckgo_request.Model = realModel
29
+ content := buildContent(&api_request)
30
+ duckgo_request.AddMessage("user", content)
31
+
32
+ return duckgo_request
33
+ }
34
+
35
+ func buildContent(api_request *officialtypes.APIRequest) string {
36
+ var content strings.Builder
37
+ for _, apiMessage := range api_request.Messages {
38
+ role := apiMessage.Role
39
+ if role == "user" || role == "system" || role == "assistant" {
40
+ contentStr := ""
41
+ // 判断 apiMessage.Content 是否为数组
42
+ if arrayContent, ok := apiMessage.Content.([]interface{}); ok {
43
+ // 如果是数组,遍历数组,查找第一个 type 为 "text" 的元素
44
+ for _, element := range arrayContent {
45
+ if elementMap, ok := element.(map[string]interface{}); ok {
46
+ if elementMap["type"] == "text" {
47
+ contentStr = elementMap["text"].(string)
48
+ break
49
+ }
50
+ }
51
+ }
52
+ } else {
53
+ contentStr, _ = apiMessage.Content.(string)
54
+ }
55
+ content.WriteString(role + ":" + contentStr + ";\r\n")
56
+ }
57
+ }
58
+ return content.String()
59
+ }
docker-compose.yml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ version: '3'
2
+
3
+ services:
4
+ app:
5
+ image: ghcr.io/aurora-develop/duck2api:latest
6
+ container_name: duck2api
7
+ restart: unless-stopped
8
+ ports:
9
+ - '8080:8080'
env.template ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ SERVER_HOST=0.0.0.0
2
+ SERVER_PORT=8080
3
+ FREE_ACCOUNTS=true
4
+ FREE_ACCOUNTS_NUM=1024
5
+ Authorization=
6
+ TLS_CERT=
7
+ TLS_KEY=
8
+ PROXY_URL=
go.mod ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module aurora
2
+
3
+ go 1.21
4
+
5
+ require (
6
+ github.com/EDDYCJY/fake-useragent v0.2.0
7
+ github.com/acheong08/endless v0.0.0-20230615162514-90545c7793fd
8
+ github.com/bogdanfinn/fhttp v0.5.27
9
+ github.com/bogdanfinn/tls-client v1.7.2
10
+ github.com/gin-gonic/gin v1.9.1
11
+ github.com/go-resty/resty/v2 v2.12.0
12
+ github.com/google/uuid v1.6.0
13
+ github.com/gorilla/websocket v1.5.1
14
+ github.com/joho/godotenv v1.5.1
15
+ github.com/pkoukk/tiktoken-go v0.1.6
16
+ github.com/xqdoo00o/funcaptcha v0.0.0-20240403090732-1b604d808f6c
17
+ )
18
+
19
+ require (
20
+ github.com/PuerkitoBio/goquery v1.9.1 // indirect
21
+ github.com/andybalholm/brotli v1.0.5 // indirect
22
+ github.com/andybalholm/cascadia v1.3.2 // indirect
23
+ github.com/bogdanfinn/utls v1.6.1 // indirect
24
+ github.com/bytedance/sonic v1.10.1 // indirect
25
+ github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
26
+ github.com/chenzhuoyu/iasm v0.9.0 // indirect
27
+ github.com/cloudflare/circl v1.3.6 // indirect
28
+ github.com/dlclark/regexp2 v1.10.0 // indirect
29
+ github.com/gabriel-vasile/mimetype v1.4.2 // indirect
30
+ github.com/gin-contrib/sse v0.1.0 // indirect
31
+ github.com/go-playground/locales v0.14.1 // indirect
32
+ github.com/go-playground/universal-translator v0.18.1 // indirect
33
+ github.com/go-playground/validator/v10 v10.15.4 // indirect
34
+ github.com/goccy/go-json v0.10.2 // indirect
35
+ github.com/json-iterator/go v1.1.12 // indirect
36
+ github.com/klauspost/compress v1.17.0 // indirect
37
+ github.com/klauspost/cpuid/v2 v2.2.5 // indirect
38
+ github.com/kr/text v0.2.0 // indirect
39
+ github.com/leodido/go-urn v1.2.4 // indirect
40
+ github.com/mattn/go-isatty v0.0.19 // indirect
41
+ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
42
+ github.com/modern-go/reflect2 v1.0.2 // indirect
43
+ github.com/pelletier/go-toml/v2 v2.1.0 // indirect
44
+ github.com/quic-go/quic-go v0.37.4 // indirect
45
+ github.com/rogpeppe/go-internal v1.12.0 // indirect
46
+ github.com/tam7t/hpkp v0.0.0-20160821193359-2b70b4024ed5 // indirect
47
+ github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
48
+ github.com/ugorji/go/codec v1.2.11 // indirect
49
+ golang.org/x/arch v0.5.0 // indirect
50
+ golang.org/x/crypto v0.21.0 // indirect
51
+ golang.org/x/net v0.22.0 // indirect
52
+ golang.org/x/sys v0.18.0 // indirect
53
+ golang.org/x/text v0.14.0 // indirect
54
+ google.golang.org/protobuf v1.31.0 // indirect
55
+ gopkg.in/yaml.v3 v3.0.1 // indirect
56
+ )
go.sum ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ github.com/EDDYCJY/fake-useragent v0.2.0 h1:Jcnkk2bgXmDpX0z+ELlUErTkoLb/mxFBNd2YdcpvJBs=
2
+ github.com/EDDYCJY/fake-useragent v0.2.0/go.mod h1:5wn3zzlDxhKW6NYknushqinPcAqZcAPHy8lLczCdJdc=
3
+ github.com/PuerkitoBio/goquery v1.9.1 h1:mTL6XjbJTZdpfL+Gwl5U2h1l9yEkJjhmlTeV9VPW7UI=
4
+ github.com/PuerkitoBio/goquery v1.9.1/go.mod h1:cW1n6TmIMDoORQU5IU/P1T3tGFunOeXEpGP2WHRwkbY=
5
+ github.com/acheong08/endless v0.0.0-20230615162514-90545c7793fd h1:oIpfrRhD7Jus41dotbK+SQjWSFRnf1cLZUYCZpF/o/4=
6
+ github.com/acheong08/endless v0.0.0-20230615162514-90545c7793fd/go.mod h1:0yO7neMeJLvKk/B/fq5votDY8rByrOPDubpvU+6saKo=
7
+ github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
8
+ github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
9
+ github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
10
+ github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
11
+ github.com/bogdanfinn/fhttp v0.5.27 h1:+glR3k8v5nxfUSk7+J3M246zEQ2yadhS0vLq1utK71A=
12
+ github.com/bogdanfinn/fhttp v0.5.27/go.mod h1:oJiYPG3jQTKzk/VFmogH8jxjH5yiv2rrOH48Xso2lrE=
13
+ github.com/bogdanfinn/tls-client v1.7.2 h1:vpL5qBYUfT9ueygEf1yLfymrXyUEZQatL25amfqGV8M=
14
+ github.com/bogdanfinn/tls-client v1.7.2/go.mod h1:pOGa2euqTbEkGNqE5idx5jKKfs9ytlyn3fwEw8RSP+g=
15
+ github.com/bogdanfinn/utls v1.6.1 h1:dKDYAcXEyFFJ3GaWaN89DEyjyRraD1qb4osdEK89ass=
16
+ github.com/bogdanfinn/utls v1.6.1/go.mod h1:VXIbRZaiY/wHZc6Hu+DZ4O2CgTzjhjCg/Ou3V4r/39Y=
17
+ github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
18
+ github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
19
+ github.com/bytedance/sonic v1.10.1 h1:7a1wuFXL1cMy7a3f7/VFcEtriuXQnUBhtoVfOZiaysc=
20
+ github.com/bytedance/sonic v1.10.1/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
21
+ github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
22
+ github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
23
+ github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
24
+ github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA=
25
+ github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo=
26
+ github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
27
+ github.com/cloudflare/circl v1.3.6 h1:/xbKIqSHbZXHwkhbrhrt2YOHIwYJlXH94E3tI/gDlUg=
28
+ github.com/cloudflare/circl v1.3.6/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
29
+ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
30
+ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
31
+ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
32
+ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
+ github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq0=
34
+ github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
35
+ github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
36
+ github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
37
+ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
38
+ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
39
+ github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
40
+ github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
41
+ github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
42
+ github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
43
+ github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
44
+ github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
45
+ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
46
+ github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
47
+ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
48
+ github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
49
+ github.com/go-playground/validator/v10 v10.15.4 h1:zMXza4EpOdooxPel5xDqXEdXG5r+WggpvnAKMsalBjs=
50
+ github.com/go-playground/validator/v10 v10.15.4/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
51
+ github.com/go-resty/resty/v2 v2.12.0 h1:rsVL8P90LFvkUYq/V5BTVe203WfRIU4gvcf+yfzJzGA=
52
+ github.com/go-resty/resty/v2 v2.12.0/go.mod h1:o0yGPrkS3lOe1+eFajk6kBW8ScXzwU3hD69/gt2yB/0=
53
+ github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
54
+ github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
55
+ github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
56
+ github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
57
+ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
58
+ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
59
+ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
60
+ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
61
+ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
62
+ github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
63
+ github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
64
+ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
65
+ github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
66
+ github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
67
+ github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
68
+ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
69
+ github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
70
+ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
71
+ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
72
+ github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
73
+ github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
74
+ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
75
+ github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
76
+ github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
77
+ github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
78
+ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
79
+ github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
80
+ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
81
+ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
82
+ github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
83
+ github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
84
+ github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
85
+ github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
86
+ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
87
+ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
88
+ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
89
+ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
90
+ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
91
+ github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q=
92
+ github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k=
93
+ github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
94
+ github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg=
95
+ github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
96
+ github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
97
+ github.com/pkoukk/tiktoken-go v0.1.6 h1:JF0TlJzhTbrI30wCvFuiw6FzP2+/bR+FIxUdgEAcUsw=
98
+ github.com/pkoukk/tiktoken-go v0.1.6/go.mod h1:9NiV+i9mJKGj1rYOT+njbv+ZwA/zJxYdewGl6qVatpg=
99
+ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
100
+ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
101
+ github.com/quic-go/quic-go v0.37.4 h1:ke8B73yMCWGq9MfrCCAw0Uzdm7GaViC3i39dsIdDlH4=
102
+ github.com/quic-go/quic-go v0.37.4/go.mod h1:YsbH1r4mSHPJcLF4k4zruUkLBqctEMBDR6VPvcYjIsU=
103
+ github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
104
+ github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
105
+ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
106
+ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
107
+ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
108
+ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
109
+ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
110
+ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
111
+ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
112
+ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
113
+ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
114
+ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
115
+ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
116
+ github.com/tam7t/hpkp v0.0.0-20160821193359-2b70b4024ed5 h1:YqAladjX7xpA6BM04leXMWAEjS0mTZ5kUU9KRBriQJc=
117
+ github.com/tam7t/hpkp v0.0.0-20160821193359-2b70b4024ed5/go.mod h1:2JjD2zLQYH5HO74y5+aE3remJQvl6q4Sn6aWA2wD1Ng=
118
+ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
119
+ github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
120
+ github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
121
+ github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
122
+ github.com/xqdoo00o/funcaptcha v0.0.0-20240403090732-1b604d808f6c h1:nj17XsSTwprsZUDXLldOUZmqz7VlHsLCeXXFOE6Q+Mk=
123
+ github.com/xqdoo00o/funcaptcha v0.0.0-20240403090732-1b604d808f6c/go.mod h1:7aCyoW5MHDUsoooMVLqKe0F7W9HMPUvDG3bXqw++8XA=
124
+ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
125
+ golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
126
+ golang.org/x/arch v0.5.0 h1:jpGode6huXQxcskEIpOCvrU+tzo81b6+oFLUYXWtH/Y=
127
+ golang.org/x/arch v0.5.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
128
+ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
129
+ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
130
+ golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
131
+ golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
132
+ golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
133
+ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
134
+ golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
135
+ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
136
+ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
137
+ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
138
+ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
139
+ golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
140
+ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
141
+ golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
142
+ golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
143
+ golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
144
+ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
145
+ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
146
+ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
147
+ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
148
+ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
149
+ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
150
+ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
151
+ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
152
+ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
153
+ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
154
+ golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
155
+ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
156
+ golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
157
+ golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
158
+ golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
159
+ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
160
+ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
161
+ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
162
+ golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
163
+ golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
164
+ golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
165
+ golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
166
+ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
167
+ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
168
+ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
169
+ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
170
+ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
171
+ golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
172
+ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
173
+ golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
174
+ golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
175
+ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
176
+ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
177
+ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
178
+ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
179
+ golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo=
180
+ golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
181
+ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
182
+ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
183
+ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
184
+ google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
185
+ google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
186
+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
187
+ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
188
+ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
189
+ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
190
+ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
191
+ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
192
+ nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
193
+ rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
httpclient/Iaurorahttpclient.go ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package httpclient
2
+
3
+ import (
4
+ "io"
5
+ "net/http"
6
+ )
7
+
8
+ type AuroraHttpClient interface {
9
+ Request(method HttpMethod, url string, headers AuroraHeaders, cookies []*http.Cookie, body io.Reader) (*http.Response, error)
10
+ SetProxy(url string) error
11
+ }
12
+
13
+ type HttpMethod string
14
+
15
+ const (
16
+ GET HttpMethod = "GET"
17
+ POST HttpMethod = "POST"
18
+ PUT HttpMethod = "PUT"
19
+ HEAD HttpMethod = "HEAD"
20
+ DELETE HttpMethod = "DELETE"
21
+ OPTIONS HttpMethod = "OPTIONS"
22
+ )
23
+
24
+ type AuroraHeaders map[string]string
25
+
26
+ func (a AuroraHeaders) Set(key, value string) {
27
+ a[key] = value
28
+ }
httpclient/bogdanfinn/tls_client.go ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package bogdanfinn
2
+
3
+ import (
4
+ "aurora/httpclient"
5
+ "io"
6
+ "net/http"
7
+
8
+ fhttp "github.com/bogdanfinn/fhttp"
9
+ tls_client "github.com/bogdanfinn/tls-client"
10
+ "github.com/bogdanfinn/tls-client/profiles"
11
+ )
12
+
13
+ type TlsClient struct {
14
+ Client tls_client.HttpClient
15
+ ReqBefore handler
16
+ }
17
+
18
+ type handler func(r *fhttp.Request) error
19
+
20
+ func NewStdClient() *TlsClient {
21
+ client, _ := tls_client.NewHttpClient(tls_client.NewNoopLogger(), []tls_client.HttpClientOption{
22
+ tls_client.WithCookieJar(tls_client.NewCookieJar()),
23
+ tls_client.WithTimeoutSeconds(600),
24
+ tls_client.WithClientProfile(profiles.Okhttp4Android13),
25
+ }...)
26
+
27
+ stdClient := &TlsClient{Client: client}
28
+ return stdClient
29
+ }
30
+
31
+ func convertResponse(resp *fhttp.Response) *http.Response {
32
+ response := &http.Response{
33
+ Status: resp.Status,
34
+ StatusCode: resp.StatusCode,
35
+ Proto: resp.Proto,
36
+ ProtoMajor: resp.ProtoMajor,
37
+ ProtoMinor: resp.ProtoMinor,
38
+ Header: http.Header(resp.Header),
39
+ Body: resp.Body,
40
+ ContentLength: resp.ContentLength,
41
+ TransferEncoding: resp.TransferEncoding,
42
+ Close: resp.Close,
43
+ Uncompressed: resp.Uncompressed,
44
+ Trailer: http.Header(resp.Trailer),
45
+ }
46
+ return response
47
+ }
48
+
49
+ func (t *TlsClient) handleHeaders(req *fhttp.Request, headers httpclient.AuroraHeaders) {
50
+ if headers == nil {
51
+ return
52
+ }
53
+ for k, v := range headers {
54
+ req.Header.Set(k, v)
55
+ }
56
+ }
57
+
58
+ func (t *TlsClient) handleCookies(req *fhttp.Request, cookies []*http.Cookie) {
59
+ if cookies == nil {
60
+ return
61
+ }
62
+ for _, c := range cookies {
63
+ req.AddCookie(&fhttp.Cookie{
64
+ Name: c.Name,
65
+ Value: c.Value,
66
+ Path: c.Path,
67
+ Domain: c.Domain,
68
+ Expires: c.Expires,
69
+ RawExpires: c.RawExpires,
70
+ MaxAge: c.MaxAge,
71
+ Secure: c.Secure,
72
+ HttpOnly: c.HttpOnly,
73
+ SameSite: fhttp.SameSite(c.SameSite),
74
+ Raw: c.Raw,
75
+ Unparsed: c.Unparsed,
76
+ })
77
+ }
78
+ }
79
+
80
+ func (t *TlsClient) Request(method httpclient.HttpMethod, url string, headers httpclient.AuroraHeaders, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
81
+ req, err := fhttp.NewRequest(string(method), url, body)
82
+ if err != nil {
83
+ return nil, err
84
+ }
85
+ t.handleHeaders(req, headers)
86
+ t.handleCookies(req, cookies)
87
+ if t.ReqBefore != nil {
88
+ if err := t.ReqBefore(req); err != nil {
89
+ return nil, err
90
+ }
91
+ }
92
+ do, err := t.Client.Do(req)
93
+ if err != nil {
94
+ return nil, err
95
+ }
96
+ return convertResponse(do), nil
97
+ }
98
+
99
+ func (t *TlsClient) SetProxy(url string) error {
100
+ return t.Client.SetProxy(url)
101
+ }
httpclient/bogdanfinn/tls_client_test.go ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package bogdanfinn
2
+
3
+ import (
4
+ "aurora/httpclient"
5
+ "fmt"
6
+ "io"
7
+ "net/http"
8
+ "os"
9
+ "strings"
10
+ "testing"
11
+
12
+ "github.com/joho/godotenv"
13
+ )
14
+
15
+ var BaseURL string
16
+
17
+ func init() {
18
+ _ = godotenv.Load(".env")
19
+ BaseURL = os.Getenv("BASE_URL")
20
+ if BaseURL == "" {
21
+ BaseURL = "https://chat.openai.com/backend-anon"
22
+ }
23
+ }
24
+ func TestTlsClient_Request(t *testing.T) {
25
+ client := NewStdClient()
26
+ userAgent := "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
27
+ proxy := "http://127.0.0.1:7990"
28
+ client.SetProxy(proxy)
29
+
30
+ apiUrl := BaseURL + "/sentinel/chat-requirements"
31
+ payload := strings.NewReader(`{"conversation_mode_kind":"primary_assistant"}`)
32
+ header := make(httpclient.AuroraHeaders)
33
+ header.Set("Content-Type", "application/json")
34
+ header.Set("User-Agent", userAgent)
35
+ header.Set("Accept", "*/*")
36
+ header.Set("oai-language", "en-US")
37
+ header.Set("origin", "https://chat.openai.com")
38
+ header.Set("referer", "https://chat.openai.com/")
39
+ header.Set("oai-device-id", "c83b24f0-5a9e-4c43-8915-3f67d4332609")
40
+ response, err := client.Request(http.MethodPost, apiUrl, header, nil, payload)
41
+ if err != nil {
42
+ return
43
+ }
44
+ defer response.Body.Close()
45
+ fmt.Println(response.StatusCode)
46
+ if response.StatusCode != 200 {
47
+ fmt.Println("Error: ", response.StatusCode)
48
+ }
49
+ }
50
+
51
+ func TestChatGPTModel(t *testing.T) {
52
+ client := NewStdClient()
53
+ userAgent := "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
54
+ proxy := "http://127.0.0.1:7990"
55
+ client.SetProxy(proxy)
56
+ apiUrl := "https://chat.openai.com/backend-anon/models"
57
+
58
+ header := make(httpclient.AuroraHeaders)
59
+ header.Set("Content-Type", "application/json")
60
+ header.Set("User-Agent", userAgent)
61
+ header.Set("Accept", "*/*")
62
+ header.Set("oai-language", "en-US")
63
+ header.Set("origin", "https://chat.openai.com")
64
+ header.Set("referer", "https://chat.openai.com/")
65
+ header.Set("oai-device-id", "c83b24f0-5a9e-4c43-8915-3f67d4332609")
66
+ response, err := client.Request(http.MethodGet, apiUrl, header, nil, nil)
67
+ if err != nil {
68
+ return
69
+ }
70
+ defer response.Body.Close()
71
+ fmt.Println(response.StatusCode)
72
+ if response.StatusCode != 200 {
73
+ fmt.Println("Error: ", response.StatusCode)
74
+ body, _ := io.ReadAll(response.Body)
75
+ fmt.Println(string(body))
76
+ return
77
+ }
78
+
79
+ type EnginesData struct {
80
+ Models []struct {
81
+ Slug string `json:"slug"`
82
+ MaxTokens int `json:"max_tokens"`
83
+ Title string `json:"title"`
84
+ Description string `json:"description"`
85
+ Tags []string `json:"tags"`
86
+ Capabilities struct {
87
+ } `json:"capabilities,omitempty"`
88
+ ProductFeatures struct {
89
+ } `json:"product_features,omitempty"`
90
+ } `json:"models"`
91
+ Categories []struct {
92
+ Category string `json:"category"`
93
+ HumanCategoryName string `json:"human_category_name"`
94
+ SubscriptionLevel string `json:"subscription_level"`
95
+ DefaultModel string `json:"default_model"`
96
+ CodeInterpreterModel string `json:"code_interpreter_model,omitempty"`
97
+ PluginsModel string `json:"plugins_model"`
98
+ } `json:"categories"`
99
+ }
100
+
101
+ }
httpclient/resty/resty_client.go ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package resty
2
+
3
+ import (
4
+ "aurora/util"
5
+ "crypto/tls"
6
+ browser "github.com/EDDYCJY/fake-useragent"
7
+ "github.com/go-resty/resty/v2"
8
+ "net/http"
9
+ "time"
10
+ )
11
+
12
+ type RestyClient struct {
13
+ Client *resty.Client
14
+ }
15
+
16
+ func NewStdClient() *RestyClient {
17
+ client := &RestyClient{
18
+ Client: resty.NewWithClient(&http.Client{
19
+ Transport: &http.Transport{
20
+ // 禁用长连接
21
+ DisableKeepAlives: true,
22
+ // 配置TLS设置,跳过证书验证
23
+ TLSClientConfig: &tls.Config{
24
+ InsecureSkipVerify: true,
25
+ },
26
+ },
27
+ }),
28
+ }
29
+ client.Client.SetBaseURL("https://chat.openai.com")
30
+ client.Client.SetRetryCount(3)
31
+ client.Client.SetRetryWaitTime(5 * time.Second)
32
+ client.Client.SetRetryMaxWaitTime(20 * time.Second)
33
+
34
+ client.Client.SetTimeout(600 * time.Second)
35
+ client.Client.SetHeader("user-agent", browser.Random()).
36
+ SetHeader("accept", "*/*").
37
+ SetHeader("accept-language", "en-US,en;q=0.9").
38
+ SetHeader("cache-control", "no-cache").
39
+ SetHeader("content-type", "application/json").
40
+ SetHeader("oai-language", util.RandomLanguage()).
41
+ SetHeader("pragma", "no-cache").
42
+ SetHeader("sec-ch-ua", `"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"`).
43
+ SetHeader("sec-ch-ua-mobile", "?0").
44
+ SetHeader("sec-ch-ua-platform", "Windows").
45
+ SetHeader("sec-fetch-dest", "empty").
46
+ SetHeader("sec-fetch-mode", "cors").
47
+ SetHeader("sec-fetch-site", "same-origin")
48
+ return client
49
+ }
50
+
51
+ //func (c *RestyClient) Request(method string, url string, headers map[string]string, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
52
+ //}
53
+
54
+ //func (c *RestyClient) Post(url string, headers map[string]string, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
55
+ //}
56
+ //
57
+ //func (c *RestyClient) Get(url string, headers map[string]string, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
58
+ //}
59
+ //
60
+ //func (c *RestyClient) Head(url string, headers map[string]string, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
61
+ //}
62
+ //
63
+ //func (c *RestyClient) Options(url string, headers map[string]string, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
64
+ //}
65
+ //
66
+ //func (c *RestyClient) Put(url string, headers map[string]string, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
67
+ //}
68
+ //
69
+ //func (c *RestyClient) Delete(url string, headers map[string]string, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
70
+ //}
71
+ //
72
+ //func (c *RestyClient) SetProxy(url string) error {}
initialize/handlers.go ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package initialize
2
+
3
+ import (
4
+ duckgoConvert "aurora/conversion/requests/duckgo"
5
+ "aurora/httpclient/bogdanfinn"
6
+ "aurora/internal/duckgo"
7
+ "aurora/internal/proxys"
8
+ officialtypes "aurora/typings/official"
9
+
10
+ "github.com/gin-gonic/gin"
11
+ )
12
+
13
+ type Handler struct {
14
+ proxy *proxys.IProxy
15
+ }
16
+
17
+ func NewHandle(proxy *proxys.IProxy) *Handler {
18
+ return &Handler{proxy: proxy}
19
+ }
20
+
21
+ func optionsHandler(c *gin.Context) {
22
+ // Set headers for CORS
23
+ c.Header("Access-Control-Allow-Origin", "*")
24
+ c.Header("Access-Control-Allow-Methods", "POST")
25
+ c.Header("Access-Control-Allow-Headers", "*")
26
+ c.JSON(200, gin.H{
27
+ "message": "pong",
28
+ })
29
+ }
30
+
31
+ func (h *Handler) duckduckgo(c *gin.Context) {
32
+ var original_request officialtypes.APIRequest
33
+ err := c.BindJSON(&original_request)
34
+ if err != nil {
35
+ c.JSON(400, gin.H{"error": gin.H{
36
+ "message": "Request must be proper JSON",
37
+ "type": "invalid_request_error",
38
+ "param": nil,
39
+ "code": err.Error(),
40
+ }})
41
+ return
42
+ }
43
+ proxyUrl := h.proxy.GetProxyIP()
44
+ client := bogdanfinn.NewStdClient()
45
+ token, err := duckgo.InitXVQD(client, proxyUrl)
46
+ if err != nil {
47
+ c.JSON(500, gin.H{
48
+ "error": err.Error(),
49
+ })
50
+ return
51
+ }
52
+
53
+ translated_request := duckgoConvert.ConvertAPIRequest(original_request)
54
+ response, err := duckgo.POSTconversation(client, translated_request, token, proxyUrl)
55
+ if err != nil {
56
+ c.JSON(500, gin.H{
57
+ "error": "request conversion error",
58
+ })
59
+ return
60
+ }
61
+
62
+ defer response.Body.Close()
63
+ if duckgo.Handle_request_error(c, response) {
64
+ return
65
+ }
66
+ var response_part string
67
+ response_part = duckgo.Handler(c, response, translated_request, original_request.Stream)
68
+ if c.Writer.Status() != 200 {
69
+ return
70
+ }
71
+ if !original_request.Stream {
72
+ c.JSON(200, officialtypes.NewChatCompletionWithModel(response_part, translated_request.Model))
73
+ } else {
74
+ c.String(200, "data: [DONE]\n\n")
75
+ }
76
+ }
77
+
78
+ func (h *Handler) engines(c *gin.Context) {
79
+ type ResData struct {
80
+ ID string `json:"id"`
81
+ Object string `json:"object"`
82
+ Created int `json:"created"`
83
+ OwnedBy string `json:"owned_by"`
84
+ }
85
+
86
+ type JSONData struct {
87
+ Object string `json:"object"`
88
+ Data []ResData `json:"data"`
89
+ }
90
+
91
+ modelS := JSONData{
92
+ Object: "list",
93
+ }
94
+ var resModelList []ResData
95
+
96
+ // Supported models
97
+ modelIDs := []string{
98
+ "gpt-3.5-turbo-0125",
99
+ "claude-3-haiku-20240307",
100
+ "meta-llama/Llama-3-70b-chat-hf",
101
+ "mistralai/Mixtral-8x7B-Instruct-v0.1",
102
+ }
103
+
104
+ for _, modelID := range modelIDs {
105
+ resModelList = append(resModelList, ResData{
106
+ ID: modelID,
107
+ Object: "model",
108
+ Created: 1685474247,
109
+ OwnedBy: "duckduckgo",
110
+ })
111
+ }
112
+
113
+ modelS.Data = resModelList
114
+ c.JSON(200, modelS)
115
+ }
initialize/proxy.go ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package initialize
2
+
3
+ import (
4
+ "aurora/internal/proxys"
5
+ "bufio"
6
+ "log/slog"
7
+ "net/url"
8
+ "os"
9
+ )
10
+
11
+ func checkProxy() *proxys.IProxy {
12
+ var proxies []string
13
+ proxyUrl := os.Getenv("PROXY_URL")
14
+ if proxyUrl != "" {
15
+ proxies = append(proxies, proxyUrl)
16
+ }
17
+
18
+ if _, err := os.Stat("proxies.txt"); err == nil {
19
+ file, _ := os.Open("proxies.txt")
20
+ defer file.Close()
21
+ scanner := bufio.NewScanner(file)
22
+ for scanner.Scan() {
23
+ proxy := scanner.Text()
24
+ parsedURL, err := url.Parse(proxy)
25
+ if err != nil {
26
+ slog.Warn("proxy url is invalid", "url", proxy, "err", err)
27
+ continue
28
+ }
29
+
30
+ // 如果缺少端口信息,不是完整的代理链接
31
+ if parsedURL.Port() != "" {
32
+ proxies = append(proxies, proxy)
33
+ } else {
34
+ continue
35
+ }
36
+ }
37
+ }
38
+
39
+ if len(proxies) == 0 {
40
+ proxy := os.Getenv("http_proxy")
41
+ if proxy != "" {
42
+ proxies = append(proxies, proxy)
43
+ }
44
+ }
45
+
46
+ proxyIP := proxys.NewIProxyIP(proxies)
47
+ return &proxyIP
48
+ }
initialize/router.go ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package initialize
2
+
3
+ import (
4
+ "aurora/middlewares"
5
+
6
+ "github.com/gin-gonic/gin"
7
+ )
8
+
9
+ func RegisterRouter() *gin.Engine {
10
+ handler := NewHandle(
11
+ checkProxy(),
12
+ )
13
+
14
+ router := gin.Default()
15
+ router.Use(middlewares.Cors)
16
+
17
+ router.GET("/", func(c *gin.Context) {
18
+ c.JSON(200, gin.H{
19
+ "message": "Hello, world!",
20
+ })
21
+ })
22
+
23
+ router.GET("/ping", func(c *gin.Context) {
24
+ c.JSON(200, gin.H{
25
+ "message": "pong",
26
+ })
27
+ })
28
+
29
+ router.OPTIONS("/v1/chat/completions", optionsHandler)
30
+ router.OPTIONS("/v1/chat/models", optionsHandler)
31
+ authGroup := router.Group("").Use(middlewares.Authorization)
32
+ authGroup.POST("/v1/chat/completions", handler.duckduckgo)
33
+ authGroup.GET("/v1/models", handler.engines)
34
+ return router
35
+ }
internal/duckgo/request.go ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package duckgo
2
+
3
+ import (
4
+ "aurora/httpclient"
5
+ duckgotypes "aurora/typings/duckgo"
6
+ officialtypes "aurora/typings/official"
7
+ "bufio"
8
+ "bytes"
9
+ "encoding/json"
10
+ "errors"
11
+ "github.com/gin-gonic/gin"
12
+ "io"
13
+ "net/http"
14
+ "strings"
15
+ "sync"
16
+ "time"
17
+ )
18
+
19
+ var (
20
+ Token *XqdgToken
21
+ UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
22
+ )
23
+
24
+ type XqdgToken struct {
25
+ Token string `json:"token"`
26
+ M sync.Mutex `json:"-"`
27
+ ExpireAt time.Time `json:"expire"`
28
+ }
29
+
30
+ func InitXVQD(client httpclient.AuroraHttpClient, proxyUrl string) (string, error) {
31
+ if Token == nil {
32
+ Token = &XqdgToken{
33
+ Token: "",
34
+ M: sync.Mutex{},
35
+ }
36
+ }
37
+ Token.M.Lock()
38
+ defer Token.M.Unlock()
39
+ if Token.Token == "" || Token.ExpireAt.Before(time.Now()) {
40
+ status, err := postStatus(client, proxyUrl)
41
+ if err != nil {
42
+ return "", err
43
+ }
44
+ defer status.Body.Close()
45
+ token := status.Header.Get("x-vqd-4")
46
+ if token == "" {
47
+ return "", errors.New("no x-vqd-4 token")
48
+ }
49
+ Token.Token = token
50
+ Token.ExpireAt = time.Now().Add(time.Minute * 5)
51
+ }
52
+
53
+ return Token.Token, nil
54
+ }
55
+
56
+ func postStatus(client httpclient.AuroraHttpClient, proxyUrl string) (*http.Response, error) {
57
+ if proxyUrl != "" {
58
+ client.SetProxy(proxyUrl)
59
+ }
60
+ header := createHeader()
61
+ header.Set("accept", "*/*")
62
+ header.Set("x-vqd-accept", "1")
63
+ response, err := client.Request(httpclient.GET, "https://duckduckgo.com/duckchat/v1/status", header, nil, nil)
64
+ if err != nil {
65
+ return nil, err
66
+ }
67
+ return response, nil
68
+ }
69
+
70
+ func POSTconversation(client httpclient.AuroraHttpClient, request duckgotypes.ApiRequest, token string, proxyUrl string) (*http.Response, error) {
71
+ if proxyUrl != "" {
72
+ client.SetProxy(proxyUrl)
73
+ }
74
+ body_json, err := json.Marshal(request)
75
+ if err != nil {
76
+ return &http.Response{}, err
77
+ }
78
+ header := createHeader()
79
+ header.Set("accept", "text/event-stream")
80
+ header.Set("x-vqd-4", token)
81
+ response, err := client.Request(httpclient.POST, "https://duckduckgo.com/duckchat/v1/chat", header, nil, bytes.NewBuffer(body_json))
82
+ if err != nil {
83
+ return nil, err
84
+ }
85
+ return response, nil
86
+ }
87
+
88
+ func Handle_request_error(c *gin.Context, response *http.Response) bool {
89
+ if response.StatusCode != 200 {
90
+ // Try read response body as JSON
91
+ var error_response map[string]interface{}
92
+ err := json.NewDecoder(response.Body).Decode(&error_response)
93
+ if err != nil {
94
+ // Read response body
95
+ body, _ := io.ReadAll(response.Body)
96
+ c.JSON(response.StatusCode, gin.H{"error": gin.H{
97
+ "message": "Unknown error",
98
+ "type": "internal_server_error",
99
+ "param": nil,
100
+ "code": "500",
101
+ "details": string(body),
102
+ }})
103
+ return true
104
+ }
105
+ c.JSON(response.StatusCode, gin.H{"error": gin.H{
106
+ "message": error_response["detail"],
107
+ "type": response.Status,
108
+ "param": nil,
109
+ "code": "error",
110
+ }})
111
+ return true
112
+ }
113
+ return false
114
+ }
115
+
116
+ func createHeader() httpclient.AuroraHeaders {
117
+ header := make(httpclient.AuroraHeaders)
118
+ header.Set("accept-language", "zh-CN,zh;q=0.9")
119
+ header.Set("content-type", "application/json")
120
+ header.Set("origin", "https://duckduckgo.com")
121
+ header.Set("referer", "https://duckduckgo.com/")
122
+ header.Set("sec-ch-ua", `"Chromium";v="120", "Google Chrome";v="120", "Not-A.Brand";v="99"`)
123
+ header.Set("sec-ch-ua-mobile", "?0")
124
+ header.Set("sec-ch-ua-platform", `"Windows"`)
125
+ header.Set("user-agent", UA)
126
+ return header
127
+ }
128
+
129
+ func Handler(c *gin.Context, response *http.Response, oldRequest duckgotypes.ApiRequest, stream bool) string {
130
+ reader := bufio.NewReader(response.Body)
131
+ if stream {
132
+ // Response content type is text/event-stream
133
+ c.Header("Content-Type", "text/event-stream")
134
+ } else {
135
+ // Response content type is application/json
136
+ c.Header("Content-Type", "application/json")
137
+ }
138
+
139
+ var previousText strings.Builder
140
+ for {
141
+ line, err := reader.ReadString('\n')
142
+ if err != nil {
143
+ if err == io.EOF {
144
+ break
145
+ }
146
+ return ""
147
+ }
148
+ if len(line) < 6 {
149
+ continue
150
+ }
151
+ line = line[6:]
152
+ if !strings.HasPrefix(line, "[DONE]") {
153
+ var originalResponse duckgotypes.ApiResponse
154
+ err = json.Unmarshal([]byte(line), &originalResponse)
155
+ if err != nil {
156
+ continue
157
+ }
158
+ if originalResponse.Action != "success" {
159
+ c.JSON(500, gin.H{"error": "Error"})
160
+ return ""
161
+ }
162
+ responseString := ""
163
+ if originalResponse.Message != "" {
164
+ previousText.WriteString(originalResponse.Message)
165
+ translatedResponse := officialtypes.NewChatCompletionChunkWithModel(originalResponse.Message, originalResponse.Model)
166
+ responseString = "data: " + translatedResponse.String() + "\n\n"
167
+ }
168
+
169
+ if responseString == "" {
170
+ continue
171
+ }
172
+
173
+ if stream {
174
+ _, err = c.Writer.WriteString(responseString)
175
+ if err != nil {
176
+ return ""
177
+ }
178
+ c.Writer.Flush()
179
+ }
180
+ } else {
181
+ if stream {
182
+ final_line := officialtypes.StopChunkWithModel("stop", oldRequest.Model)
183
+ c.Writer.WriteString("data: " + final_line.String() + "\n\n")
184
+ }
185
+ }
186
+ }
187
+ return previousText.String()
188
+ }
internal/proxys/proxys.go ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package proxys
2
+
3
+ import "sync"
4
+
5
+ type IProxy struct {
6
+ ips []string
7
+ lock sync.Mutex
8
+ }
9
+
10
+ func NewIProxyIP(ips []string) IProxy {
11
+ return IProxy{
12
+ ips: ips,
13
+ }
14
+ }
15
+
16
+ func (p *IProxy) GetIPS() int {
17
+ return len(p.ips)
18
+ }
19
+
20
+ func (p *IProxy) GetProxyIP() string {
21
+ if p == nil {
22
+ return ""
23
+ }
24
+
25
+ p.lock.Lock()
26
+ defer p.lock.Unlock()
27
+
28
+ if len(p.ips) == 0 {
29
+ return ""
30
+ }
31
+
32
+ proxyIp := p.ips[0]
33
+ p.ips = append(p.ips[1:], proxyIp)
34
+ return proxyIp
35
+ }
main.go ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package main
2
+
3
+ import (
4
+ "aurora/initialize"
5
+ "embed"
6
+ "io/fs"
7
+ "log"
8
+ "net/http"
9
+ "os"
10
+
11
+ "github.com/gin-gonic/gin"
12
+
13
+ "github.com/acheong08/endless"
14
+ "github.com/joho/godotenv"
15
+ )
16
+
17
+ //go:embed web/*
18
+ var staticFiles embed.FS
19
+
20
+ func main() {
21
+ gin.SetMode(gin.ReleaseMode)
22
+ router := initialize.RegisterRouter()
23
+ subFS, err := fs.Sub(staticFiles, "web")
24
+ if err != nil {
25
+ log.Fatal(err)
26
+ }
27
+ router.StaticFS("/web", http.FS(subFS))
28
+
29
+ _ = godotenv.Load(".env")
30
+ host := os.Getenv("SERVER_HOST")
31
+ port := os.Getenv("SERVER_PORT")
32
+ tlsCert := os.Getenv("TLS_CERT")
33
+ tlsKey := os.Getenv("TLS_KEY")
34
+
35
+ if host == "" {
36
+ host = "0.0.0.0"
37
+ }
38
+ if port == "" {
39
+ port = os.Getenv("PORT")
40
+ if port == "" {
41
+ port = "8080"
42
+ }
43
+ }
44
+
45
+ if tlsCert != "" && tlsKey != "" {
46
+ _ = endless.ListenAndServeTLS(host+":"+port, tlsCert, tlsKey, router)
47
+ } else {
48
+ _ = endless.ListenAndServe(host+":"+port, router)
49
+ }
50
+ }
middlewares/auth.go ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package middlewares
2
+
3
+ import (
4
+ "github.com/gin-gonic/gin"
5
+ "os"
6
+ "strings"
7
+ )
8
+
9
+ func Authorization(c *gin.Context) {
10
+ customer_key := os.Getenv("Authorization")
11
+ if customer_key != "" {
12
+ authHeader := c.GetHeader("Authorization")
13
+ if authHeader == "" {
14
+ c.JSON(401, gin.H{"error": "Unauthorized"})
15
+ c.Abort()
16
+ return
17
+ }
18
+ tokenParts := strings.Split(strings.Replace(authHeader, "Bearer ", "", 1)," ")
19
+ customAccessToken := tokenParts[0]
20
+ if customer_key != customAccessToken {
21
+ c.JSON(401, gin.H{"error": "Unauthorized"})
22
+ c.Abort()
23
+ return
24
+ }
25
+ if len(tokenParts) > 1 {
26
+ openaiAccessToken := tokenParts[1]
27
+ c.Request.Header.Set("Authorization", "Bearer " + openaiAccessToken)
28
+ }
29
+ }
30
+ c.Next()
31
+ }
middlewares/cors.go ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ package middlewares
2
+
3
+ import "github.com/gin-gonic/gin"
4
+
5
+ func Cors(c *gin.Context) {
6
+ c.Header("Access-Control-Allow-Origin", "*")
7
+ c.Header("Access-Control-Allow-Methods", "*")
8
+ c.Header("Access-Control-Allow-Headers", "*")
9
+ c.Next()
10
+ }
release.bat ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @echo off
2
+ SETLOCAL
3
+
4
+ REM 指定编码为 UTF-8
5
+ chcp 65001
6
+
7
+ REM 设置要生成的可执行文件的名称
8
+ set OUTPUT_NAME=aurora
9
+
10
+ REM 设置 Go 源文件的名称
11
+ SET GOFILE=aurora
12
+
13
+ REM 设置输出目录
14
+ SET OUTPUTDIR=target
15
+
16
+ REM 确保输出目录存在
17
+ IF NOT EXIST %OUTPUTDIR% MKDIR %OUTPUTDIR%
18
+
19
+ REM 编译为 Windows/amd64
20
+ echo 开始编译 Windows/amd64
21
+ SET GOOS=windows
22
+ SET GOARCH=amd64
23
+ go build -o %OUTPUTDIR%/%OUTPUT_NAME%_windows_amd64.exe %GOFILE%
24
+ echo 编译完成 Windows/amd64
25
+
26
+ REM 编译为 Windows/386
27
+ echo 开始编译 Windows/386
28
+ SET GOOS=windows
29
+ SET GOARCH=386
30
+ go build -o %OUTPUTDIR%/%OUTPUT_NAME%_windows_386.exe %GOFILE%
31
+ echo 编译完成 Windows/386
32
+
33
+ REM 编译为 Linux/amd64
34
+ echo 开始编译 Linux/amd64
35
+ SET GOOS=linux
36
+ SET GOARCH=amd64
37
+ go build -o %OUTPUTDIR%/%OUTPUT_NAME%_linux_amd64 %GOFILE%
38
+ echo 编译完成 Linux/amd64
39
+
40
+ REM 编译为 macOS/amd64
41
+ echo 开始编译 macOS/amd64
42
+ SET GOOS=darwin
43
+ SET GOARCH=amd64
44
+ go build -o %OUTPUTDIR%/%OUTPUT_NAME%_macos_amd64 %GOFILE%
45
+ echo 编译完成 macOS/amd64
46
+
47
+ REM 编译为 freebsd/amd64
48
+ echo 开始编译 freebsd/amd64
49
+ SET GOOS=freebsd
50
+ SET GOARCH=amd64
51
+ go build -o %OUTPUTDIR%/%OUTPUT_NAME%_freebsd_amd64 %GOFILE%
52
+ echo 编译完成 freebsd/amd64
53
+
54
+ REM 结束批处理脚本
55
+ ENDLOCAL
56
+ echo 编译完成!
render.yaml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ services:
2
+ - type: web
3
+ name: duck2api
4
+ env: docker
5
+ dockerfilePath: ./Dockerfile
6
+ plan: free
7
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ flask
2
+ ycecream
3
+ requests
typings/duckgo/request.go ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package duckgo
2
+
3
+ type ApiRequest struct {
4
+ Model string `json:"model"`
5
+ Messages []messages `json:"messages"`
6
+ }
7
+ type messages struct {
8
+ Role string `json:"role"`
9
+ Content string `json:"content"`
10
+ }
11
+
12
+ func (a *ApiRequest) AddMessage(role string, content string) {
13
+ a.Messages = append(a.Messages, messages{
14
+ Role: role,
15
+ Content: content,
16
+ })
17
+ }
18
+
19
+ func NewApiRequest(model string) ApiRequest {
20
+ return ApiRequest{
21
+ Model: model,
22
+ }
23
+ }
typings/duckgo/response.go ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ package duckgo
2
+
3
+ type ApiResponse struct {
4
+ Message string `json:"message"`
5
+ Created int `json:"created"`
6
+ Id string `json:"id"`
7
+ Action string `json:"action"`
8
+ Model string `json:"model"`
9
+ }
typings/official/request.go ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package official
2
+
3
+ type APIRequest struct {
4
+ Messages []api_message `json:"messages"`
5
+ Stream bool `json:"stream"`
6
+ Model string `json:"model"`
7
+ PluginIDs []string `json:"plugin_ids"`
8
+ }
9
+
10
+ type api_message struct {
11
+ Role string `json:"role"`
12
+ Content interface{} `json:"content"`
13
+ }
14
+
15
+ type OpenAISessionToken struct {
16
+ SessionToken string `json:"session_token"`
17
+ }
18
+
19
+ type OpenAIRefreshToken struct {
20
+ RefreshToken string `json:"refresh_token"`
21
+ }
typings/official/response.go ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package official
2
+
3
+ import "encoding/json"
4
+
5
+ type ChatCompletionChunk struct {
6
+ ID string `json:"id"`
7
+ Object string `json:"object"`
8
+ Created int64 `json:"created"`
9
+ Model string `json:"model"`
10
+ Choices []Choices `json:"choices"`
11
+ }
12
+
13
+ func (chunk *ChatCompletionChunk) String() string {
14
+ resp, _ := json.Marshal(chunk)
15
+ return string(resp)
16
+ }
17
+
18
+ type Choices struct {
19
+ Delta Delta `json:"delta"`
20
+ Index int `json:"index"`
21
+ FinishReason interface{} `json:"finish_reason"`
22
+ }
23
+
24
+ type Delta struct {
25
+ Content string `json:"content,omitempty"`
26
+ Role string `json:"role,omitempty"`
27
+ }
28
+
29
+ func NewChatCompletionChunk(text string) ChatCompletionChunk {
30
+ return ChatCompletionChunk{
31
+ ID: "chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK",
32
+ Object: "chat.completion.chunk",
33
+ Created: 0,
34
+ Model: "gpt-3.5-turbo-0301",
35
+ Choices: []Choices{
36
+ {
37
+ Index: 0,
38
+ Delta: Delta{
39
+ Content: text,
40
+ },
41
+ FinishReason: nil,
42
+ },
43
+ },
44
+ }
45
+ }
46
+
47
+ func NewChatCompletionChunkWithModel(text string, model string) ChatCompletionChunk {
48
+ return ChatCompletionChunk{
49
+ ID: "chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK",
50
+ Object: "chat.completion.chunk",
51
+ Created: 0,
52
+ Model: model,
53
+ Choices: []Choices{
54
+ {
55
+ Index: 0,
56
+ Delta: Delta{
57
+ Content: text,
58
+ },
59
+ FinishReason: nil,
60
+ },
61
+ },
62
+ }
63
+ }
64
+
65
+ func StopChunkWithModel(reason string, model string) ChatCompletionChunk {
66
+ return ChatCompletionChunk{
67
+ ID: "chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK",
68
+ Object: "chat.completion.chunk",
69
+ Created: 0,
70
+ Model: model,
71
+ Choices: []Choices{
72
+ {
73
+ Index: 0,
74
+ FinishReason: reason,
75
+ },
76
+ },
77
+ }
78
+ }
79
+
80
+ func StopChunk(reason string) ChatCompletionChunk {
81
+ return ChatCompletionChunk{
82
+ ID: "chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK",
83
+ Object: "chat.completion.chunk",
84
+ Created: 0,
85
+ Model: "gpt-3.5-turbo-0125",
86
+ Choices: []Choices{
87
+ {
88
+ Index: 0,
89
+ FinishReason: reason,
90
+ },
91
+ },
92
+ }
93
+ }
94
+
95
+ type ChatCompletion struct {
96
+ ID string `json:"id"`
97
+ Object string `json:"object"`
98
+ Created int64 `json:"created"`
99
+ Model string `json:"model"`
100
+ Usage usage `json:"usage"`
101
+ Choices []Choice `json:"choices"`
102
+ }
103
+ type Msg struct {
104
+ Role string `json:"role"`
105
+ Content string `json:"content"`
106
+ }
107
+ type Choice struct {
108
+ Index int `json:"index"`
109
+ Message Msg `json:"message"`
110
+ FinishReason interface{} `json:"finish_reason"`
111
+ }
112
+ type usage struct {
113
+ PromptTokens int `json:"prompt_tokens"`
114
+ CompletionTokens int `json:"completion_tokens"`
115
+ TotalTokens int `json:"total_tokens"`
116
+ }
117
+
118
+ func NewChatCompletionWithModel(text string, model string) ChatCompletion {
119
+ return ChatCompletion{
120
+ ID: "chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK",
121
+ Object: "chat.completion",
122
+ Created: int64(0),
123
+ Model: model,
124
+ Usage: usage{
125
+ PromptTokens: 0,
126
+ CompletionTokens: 0,
127
+ TotalTokens: 0,
128
+ },
129
+ Choices: []Choice{
130
+ {
131
+ Message: Msg{
132
+ Content: text,
133
+ Role: "assistant",
134
+ },
135
+ Index: 0,
136
+ },
137
+ },
138
+ }
139
+ }
140
+
141
+ func NewChatCompletion(full_test string, input_tokens, output_tokens int) ChatCompletion {
142
+ return ChatCompletion{
143
+ ID: "chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK",
144
+ Object: "chat.completion",
145
+ Created: int64(0),
146
+ Model: "gpt-3.5-turbo-0125",
147
+ Usage: usage{
148
+ PromptTokens: input_tokens,
149
+ CompletionTokens: output_tokens,
150
+ TotalTokens: input_tokens + output_tokens,
151
+ },
152
+ Choices: []Choice{
153
+ {
154
+ Message: Msg{
155
+ Content: full_test,
156
+ Role: "assistant",
157
+ },
158
+ Index: 0,
159
+ },
160
+ },
161
+ }
162
+ }
typings/typings.go ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ package typings
2
+
3
+ type GenericResponseLine struct {
4
+ Line string `json:"line"`
5
+ Error string `json:"error"`
6
+ }
7
+
8
+ type StringStruct struct {
9
+ Text string `json:"text"`
10
+ }
util/util.go ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package util
2
+
3
+ import (
4
+ "github.com/pkoukk/tiktoken-go"
5
+ "log/slog"
6
+ "math/rand"
7
+ "time"
8
+ )
9
+
10
+ func RandomLanguage() string {
11
+ // 初始化随机数生成器
12
+ rand.Seed(time.Now().UnixNano())
13
+ // 语言列表
14
+ languages := []string{"af", "am", "ar-sa", "as", "az-Latn", "be", "bg", "bn-BD", "bn-IN", "bs", "ca", "ca-ES-valencia", "cs", "cy", "da", "de", "de-de", "el", "en-GB", "en-US", "es", "es-ES", "es-US", "es-MX", "et", "eu", "fa", "fi", "fil-Latn", "fr", "fr-FR", "fr-CA", "ga", "gd-Latn", "gl", "gu", "ha-Latn", "he", "hi", "hr", "hu", "hy", "id", "ig-Latn", "is", "it", "it-it", "ja", "ka", "kk", "km", "kn", "ko", "kok", "ku-Arab", "ky-Cyrl", "lb", "lt", "lv", "mi-Latn", "mk", "ml", "mn-Cyrl", "mr", "ms", "mt", "nb", "ne", "nl", "nl-BE", "nn", "nso", "or", "pa", "pa-Arab", "pl", "prs-Arab", "pt-BR", "pt-PT", "qut-Latn", "quz", "ro", "ru", "rw", "sd-Arab", "si", "sk", "sl", "sq", "sr-Cyrl-BA", "sr-Cyrl-RS", "sr-Latn-RS", "sv", "sw", "ta", "te", "tg-Cyrl", "th", "ti", "tk-Latn", "tn", "tr", "tt-Cyrl", "ug-Arab", "uk", "ur", "uz-Latn", "vi", "wo", "xh", "yo-Latn", "zh-Hans", "zh-Hant", "zu"}
15
+ // 随机选择一个语言
16
+ randomIndex := rand.Intn(len(languages))
17
+ return languages[randomIndex]
18
+ }
19
+
20
+ func RandomHexadecimalString() string {
21
+ rand.Seed(time.Now().UnixNano())
22
+ const charset = "0123456789abcdef"
23
+ const length = 16 // The length of the string you want to generate
24
+ b := make([]byte, length)
25
+ for i := range b {
26
+ b[i] = charset[rand.Intn(len(charset))]
27
+ }
28
+ return string(b)
29
+ }
30
+ func CountToken(input string) int {
31
+ encoding := "gpt-3.5-turbo"
32
+ tkm, err := tiktoken.EncodingForModel(encoding)
33
+ if err != nil {
34
+ slog.Warn("tiktoken.EncodingForModel error:", err)
35
+ return 0
36
+ }
37
+ token := tkm.Encode(input, nil, nil)
38
+ return len(token)
39
+ }
util/utils_test.go ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package util
2
+
3
+ import (
4
+ "fmt"
5
+ "testing"
6
+ )
7
+
8
+ func TestRandomHexadecimalString(t *testing.T) {
9
+ var str = RandomHexadecimalString()
10
+ fmt.Println(str)
11
+ }
vercel.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "routes": [
3
+ {
4
+ "src": "/.*",
5
+ "dest": "/api/router.go"
6
+ }
7
+ ]
8
+ }
web/avatar.png ADDED
web/icon.png ADDED
web/index.html ADDED
The diff for this file is too large to render. See raw diff