Skip to content

Commit

Permalink
fix: api 调用异常 #101
Browse files Browse the repository at this point in the history
  • Loading branch information
weaigc committed Nov 25, 2023
1 parent 1ab582f commit 6ba23b7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
__pycache__
8 changes: 7 additions & 1 deletion src/pages/api/sydney.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
})

const closeDog = new WatchDog()
const timeoutDog = new WatchDog()
ws.onmessage = (event) => {
timeoutDog.watch(() => {
debug(id, 'timeout')
ws.send(websocketUtils.packMessage({ type: 6 }))
}, 6000)
closeDog.watch(() => {
debug(id, 'timeout close')
ws.close()
}, 20000)
}, 40000)
res.write(event.data)
if (/\{"type":([367])\b/.test(String(event.data))) {
const type = parseInt(RegExp.$1, 10)
Expand All @@ -48,6 +53,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}

ws.onclose = () => {
timeoutDog.reset()
closeDog.reset()
debug(id, 'ws close')
res.end()
Expand Down
9 changes: 9 additions & 0 deletions tests/openai-stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import openai
openai.api_key = "dummy"
openai.api_base = "https://copilot.github1s.tk" # 这里可以改为你自己部署的服务,bingo 服务版本需要 >= 0.9.0

# create a chat completion
completion = openai.ChatCompletion.create(model="Creative", stream=True, messages=[{"role": "user", "content": "Hello"}])
for chat_completion in completion:
# print the completion
print(chat_completion.choices[0].message.content, end="", flush=True)
10 changes: 4 additions & 6 deletions tests/openaipy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import openai
openai.api_key = "dummy"
openai.api_base = "https://hf4all-bingo-api.hf.space" # 这里可以改为你自己部署的服务,bingo 服务版本需要 >= 0.9.0

openai.api_key = "dummy"
openai.api_base = "https://copilot.github1s.tk" # 这里可以改为你自己部署的服务,bingo 服务版本需要 >= 0.9.0
# create a chat completion
completion = openai.ChatCompletion.create(model="Creative", stream=True, messages=[{"role": "user", "content": "Hello"}])
for chat_completion in completion:
# print the completion
print(chat_completion.choices[0].message.content, end="", flush=True)
completion = openai.ChatCompletion.create(model="gpt-4", stream=False, messages=[{"role": "user", "content": "Hello"}])
print(completion.choices[0].message.content)

0 comments on commit 6ba23b7

Please sign in to comment.