yowot0088

yowot0088

V2EX member #431234, joined on 2019-07-22 22:52:38 +08:00
Per yowot0088's settings, the topics list is hidden
Deals info, including closed deals, is not hidden
yowot0088's recent replies
同样的问题,每次加载首屏都会卡很久。例如看 Netflix 剧,片头的“噔噔”画面一般会卡在 3s 的位置,但是声音正常,3s 之后音画才同步
试试选下驱动模式?之前碰到过好多问题选驱动模式就解决了
May 17, 2025
Replied to a topic by lnbiuc 宽带症候群 西安联通宽带怎么样
我这边新装的西安电信,检测下来是 NAT3 :(
Dec 25, 2024
Replied to a topic by spike0100 macOS macos chatgpt app 原生拼音输入法打字丢字
same
附上我做的 ws api 的源码

```js
wss.on('connection', ws => {
let isConnected = true

ws.on('message', async e => {
let message = JSON.parse(e.toString())
if(message.type == 'conversation') {
let es = await fetch('https://api.openai.com/v1/chat/completions', {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + 'YOUR_OPENAI_API_KEY'
},
method: 'POST',
body: JSON.stringify({
model: message.data.model,
messages: message.data.messages,
stream: true
})
})

const reader = es.body.pipeThrough(new TextDecoderStream()).getReader()

let errObj = ''

while(true) {
if(!isConnected) {
process.stdout.write('\n')
break
}
const res = await reader.read()
if(res.done) {
break
}
let chunk = res.value
chunk = chunk.replace(/data: /g, '').split('\n')

chunk.map(item => {
if(item != '[DONE]' && item != '' && item != undefined) {
let json

try {
if(errObj != '') {
item = errObj + item
errObj = ''
}

json = JSON.parse(item)

if(json.choices[0].delta.content == undefined) return
ws.send(JSON.stringify({
type: 'conversation',
data: {
type: 'continue',
text: json.choices[0].delta.content
}
}))
process.stdout.write(json.choices[0].delta.content)
}catch {
errObj = item
return
}

}else if(item == '[DONE]') {
ws.send(JSON.stringify({
type: 'conversation',
data: {
type: 'done',
text: null
}
}))
process.stdout.write('\n')
}
})
}
}
})

ws.onclose = () => {
isConnected = false
}
})
```
我的解决方法是,先判断一个 chunk 里最后的 data: 是否为一个合法的 json ,如果不是,则将下一次最开始接收到的字符串与前一次的非法 json 拼接,可以完美解决
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2905 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 12ms · UTC 13:23 · PVG 21:23 · LAX 06:23 · JFK 09:23
♥ Do have faith in what you're doing.