Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ljnchn committed Jan 25, 2024
1 parent 906716b commit 71a5eaf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
13 changes: 13 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
32 changes: 2 additions & 30 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 71a5eaf

Please sign in to comment.