Skip to content

Commit 6ba23b7

Browse files
committed
fix: api 调用异常 #101
1 parent 1ab582f commit 6ba23b7

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ yarn-error.log*
3333
# typescript
3434
*.tsbuildinfo
3535
next-env.d.ts
36+
__pycache__

src/pages/api/sydney.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
3030
})
3131

3232
const closeDog = new WatchDog()
33+
const timeoutDog = new WatchDog()
3334
ws.onmessage = (event) => {
35+
timeoutDog.watch(() => {
36+
debug(id, 'timeout')
37+
ws.send(websocketUtils.packMessage({ type: 6 }))
38+
}, 6000)
3439
closeDog.watch(() => {
3540
debug(id, 'timeout close')
3641
ws.close()
37-
}, 20000)
42+
}, 40000)
3843
res.write(event.data)
3944
if (/\{"type":([367])\b/.test(String(event.data))) {
4045
const type = parseInt(RegExp.$1, 10)
@@ -48,6 +53,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
4853
}
4954

5055
ws.onclose = () => {
56+
timeoutDog.reset()
5157
closeDog.reset()
5258
debug(id, 'ws close')
5359
res.end()

tests/openai-stream.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import openai
2+
openai.api_key = "dummy"
3+
openai.api_base = "https://copilot.github1s.tk" # 这里可以改为你自己部署的服务,bingo 服务版本需要 >= 0.9.0
4+
5+
# create a chat completion
6+
completion = openai.ChatCompletion.create(model="Creative", stream=True, messages=[{"role": "user", "content": "Hello"}])
7+
for chat_completion in completion:
8+
# print the completion
9+
print(chat_completion.choices[0].message.content, end="", flush=True)

tests/openaipy.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import openai
2-
openai.api_key = "dummy"
3-
openai.api_base = "https://hf4all-bingo-api.hf.space" # 这里可以改为你自己部署的服务,bingo 服务版本需要 >= 0.9.0
42

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

0 commit comments

Comments
 (0)