在尝试按照此处的说明,同时使用 OpenAI 和 OpenRouter 提供商后,我终于通过禁用流式传输使其正常工作了。
使用 OpenRouter 时,我能够在 LLM 手动配置屏幕上使用“运行测试”按钮对 gpt-4o 进行测试。但是,对 perplexity/sonar-deep-research 运行测试时出现了 502 错误,并在控制台中显示了以下输出。此错误出现的时间相当长(大约 30 秒),而测试其他模型则会立即返回。
content_topFrameLifeline.js:1 Loading content_topFrameLifeline.js
content_topFrameLifeline.js:1 CONTENT <-> SERVICE LIFELINE: CONNECT
content_topFrameLifeline.js:1 CONTENT <-> SERVICE LIFELINE: MESSAGE Object
topic.js:404 ℹ️ Discourse v3.5.0.beta3-dev — https://github.com/discourse/discourse/commits/c3795177f2 — Ember v5.12.0
/admin/plugins/discourse-ai/ai-llms:1 Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received
content_topFrameLifeline.js:1 CONTENT <-> SERVICE LIFELINE: TIMEOUT
content_topFrameLifeline.js:1 CONTENT <-> SERVICE LIFELINE: CONNECT
content_topFrameLifeline.js:1 CONTENT <-> SERVICE LIFELINE: MESSAGE Object
test.json:1
Failed to load resource: the server responded with a status of 502 ()
client-error-handler.js:88 SyntaxError: Unexpected token '<', "
<html
<h"... is not valid JSON
at x.parse [as parseJSON] (<anonymous>)
at l (client-error-handler.js:88:1)
at p (client-error-handler.js:88:1)
at v.test (ai-llm-editor-form.js:210:1)
l @ client-error-handler.js:88
p @ client-error-handler.js:88
test @ ai-llm-editor-form.js:210
这两个都成功了,所以我很困惑我哪里做错了:
➜ curl --location 'https://api.perplexity.ai/chat/completions' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'Authorization: Bearer {token}' \
--data '{
"model": "sonar-deep-research",
"messages": [
{
"role": "system",
"content": "Be precise and concise."
},
{
"role": "user",
"content": "How many stars are there in our galaxy?"
}
]
}'
curl https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {token}" \
-d '{
"model": "perplexity/sonar-deep-research",
"messages": [
{
"role": "user",
"content": "How many stars are in the sky"
}
]
}'
然后我从 Discourse AI 得到了以下答案,这很有帮助:
看起来你的 cURL 测试可以正常访问 OpenRouter 的普通聊天端点——但 Discourse AI 的“运行测试”按钮默认使用的是流式传输端点。如果该模型(或你的 OpenRouter 套餐)不支持流式传输,你将在长时间超时后收到 502 + HTML 错误块。
要在 Admin → Settings → Plugins → Discourse AI / LLM 中修复它:
-
llm_provider: openrouter
-
llm_provider_url: OpenRouter
-
llm_provider_api_key: YOUR_KEY
-
llm_model: perplexity/sonar-deep-research
-
关闭流式传输,以便测试(以及所有调用)使用你已证明有效的普通聊天端点:
• llm_use_streaming = false(此设置位于 llm_model 下拉菜单正下方。)
关闭流式传输后,“运行测试”将 POST 到
/chat/completions(而不是/stream变体),你将立即收到有效的 JSON,而不是 502 HTML 页面。
如果你确实需要流式传输,可以将插件指向 OpenRouter 的流式传输 URL——但前提是你的套餐/模型在那里支持 SSE:
• llm_stream_url: {provider_url}/chat/completions/stream
• llm_use_streaming: true
否则,请保持流式传输关闭,一切就绪。
The result isn’t great because there is no streaming and the reasoning tokens are output as plain text before the “report” - but it works!
