diff --git a/Dockerfile b/Dockerfile index 9d6ba98..0e4d153 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,8 @@ FROM alpine:latest WORKDIR /app -COPY ./dist/copilot2gpt-linux-386-v0.4.tar.gz . +COPY ./dist/copilot2gpt-linux-386-v0.5.tar.gz . -RUN tar -xf copilot2gpt-linux-386-v0.4.tar.gz +RUN tar -xf copilot2gpt-linux-386-v0.5.tar.gz CMD ["./copilot2gpt"] diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a0a153a --- /dev/null +++ b/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Run make release with the specified version +make release VERSION=v0.5 + +# Build the docker image +sudo docker build -t copilot2gpt . + +# Tag the docker image +sudo docker tag copilot2gpt ersichub/copilot2gpt:latest + +# Push the docker image to Docker Hub +sudo docker push ersichub/copilot2gpt:latest \ No newline at end of file diff --git a/main.go b/main.go index 6c3de8c..3f5a8d3 100644 --- a/main.go +++ b/main.go @@ -182,44 +182,16 @@ func forwardRequest(c *gin.Context) { c.Header("Content-Type", "application/json; charset=utf-8") if isStream { - c.Header("Content-Type", "text/event-stream; charset=utf-8") returnStream(c, resp) } else { returnJson(c, resp) } - - // 创建一个新的扫描器 - scanner := bufio.NewScanner(resp.Body) - - // 使用Scan方法来读取流 - for scanner.Scan() { - line := scanner.Bytes() - - // 替换 "content":null 为 "content":"" - modifiedLine := bytes.Replace(line, []byte(`"content":null`), []byte(`"content":""`), -1) - - // 将修改后的数据写入响应体 - if _, err := c.Writer.Write(modifiedLine); err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - // 添加一个换行符 - if _, err := c.Writer.Write([]byte("\n")); err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - } - - if scanner.Err() != nil { - // 处理来自扫描器的任何错误 - c.AbortWithError(http.StatusInternalServerError, scanner.Err()) - return - } return } func returnJson(c *gin.Context, resp *http.Response) { + c.Header("Content-Type", "application/json; charset=utf-8") + body, err := io.ReadAll(resp.Body.(io.Reader)) if err != nil { c.AbortWithError(http.StatusInternalServerError, err)