Skip to content

Commit

Permalink
Merge pull request xiangsx#18 from choogoo/master
Browse files Browse the repository at this point in the history
Fixed issue where regular requests cannot return data
  • Loading branch information
xiangsx authored May 9, 2023
2 parents 3ff993a + 33a9700 commit 2fc4ddf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# docker-image.yml
name: Publish Docker image # workflow名称,可以在Github项目主页的【Actions】中看到所有的workflow

on: # 配置触发workflow的事件
push:
tags: # tag更新时触发此workflow
- '*'

jobs: # workflow中的job

push_to_registry: # job的名字
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest # job运行的基础环境

steps: # 一个job由一个或多个step组成
- name: Check out the repo
uses: actions/checkout@v2 # 官方的action,获取代码

- name: Log in to Docker Hub
uses: docker/login-action@v1 # 三方的action操作, 执行docker login
with:
username: ${{ secrets.DOCKERHUB_USERNAME }} # 配置dockerhub的认证,在Github项目主页 【Settings】 -> 【Secrets】 添加对应变量
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3 # 抽取项目信息,主要是镜像的tag
with:
images: atorber/gpt4free-ts

- name: Build and push Docker image
uses: docker/build-push-action@v2 # docker build & push
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
19 changes: 10 additions & 9 deletions model/forefront/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,18 @@ export class Forefront extends Chat {
return new Promise(resolve => {
res.text.pipe(es.split(/\r?\n\r?\n/)).pipe(es.map(async (chunk: any, cb: any) => {
const str = chunk.replace('data: ', '');
if (!str || str === '[DONE]') {
if (!str || str === '[DONE]'.trim()) {
cb(null, '');
return;
}
const data = parseJSON(str, {}) as ChatCompletionChunk;
if (!data.choices) {
cb(null, '');
return;
}
const [{delta: {content}}] = data.choices;
cb(null, content);
// const data = parseJSON(str, {}) as ChatCompletionChunk;
// if (!data.choices) {
// cb(null, '');
// return;
// }
// const [{delta: {content}}] = data.choices;
// cb(null, content);
cb(null, str);
})).on('data', (data) => {
if (!data) {
return;
Expand Down Expand Up @@ -132,7 +133,7 @@ export class Forefront extends Chat {
);
const stream = response.data.pipe(es.split(/\r?\n\r?\n/)).pipe(es.map(async (chunk: any, cb: any) => {
const str = chunk.replace('data: ', '');
if (!str || str === '[DONE]') {
if (!str || str.trim() === '[DONE]') {
cb(null, '');
return;
}
Expand Down

0 comments on commit 2fc4ddf

Please sign in to comment.