-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ feat: Support reasoning output for OpenRouter reasoning models (like deepseek-r1). | 支持读取和展示OpenRouter深度思考输出 #5903
base: main
Are you sure you want to change the base?
Conversation
@deephbz is attempting to deploy a commit to the LobeHub Team on Vercel. A member of the Team first needs to authorize it. |
👍 @deephbz Thank you for raising your pull request and contributing to our Community |
TestGru AssignmentSummary
Tip You can |
ca6d009
to
d579c59
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this implement is not ok ,please refer to https://github.com/lobehub/lobe-chat/blob/main/src/libs/agent-runtime/utils/streams/openai.ts#L90-L100 ,make OpenRouter 's chunk parser into openai stream
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done please review.
its "reasoning" to be consistent with most other platforms: reasoning outputs wrapped by <think> XML tag.
87b944d
to
bb8bcfa
Compare
bb8bcfa
to
e471961
Compare
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
Business Description
Get reasoning (i.e. deep thinking) outputs for all OpenRouter reasoning models, and display them in lobe-chat UI.
Fully tested: unittests as well as integration testing.
Technical Description
Unlike most other DeepSeek-R1 providers which simply return
<think> ... </think>
inside reply messages. OpenRouter use a separate"reasoning"
key to return reasoning outputs. Besides it requires addinclude_reasoning=True
in payload. See their docs.Therefore, to support it we need two changes:
include_reasoning=True
by usinghandlePayload
callback. This does not affect non-reasoning models at all. Verification:-you could see reasoning outputs in response:
to
This transformed content is consistent with other platforms - a single 'content' stream of thinking then normal output tokens. Therefore, the part gets automatically picked up and displayed.
Verification:
![image](https://private-user-images.githubusercontent.com/13776377/411286534-0829849c-14c7-47ee-8cf3-4e2dd31ab3fd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNzc3MzYsIm5iZiI6MTczOTI3NzQzNiwicGF0aCI6Ii8xMzc3NjM3Ny80MTEyODY1MzQtMDgyOTg0OWMtMTRjNy00N2VlLThjZjMtNGUyZGQzMWFiM2ZkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDEyMzcxNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTIwMzQxNmMwMTIzNTY2ZmQxOGE0MGJlYjZkNTM5NDExYzRhOTRkM2YyZGVjOTE0ZTM4Y2NmMGQyNDkwZGYyYmImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.RPMJ6GxSyKEOlNJlywpFJduZRS5Tfz2-XTGEtYo6mO0)
📝 补充信息 | Additional Information
Solves #5766 , related #5860