[PR #13299] chore: refactor the OpenAICompatible and improve thinking display #27913

Closed
opened 2026-02-21 20:42:26 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/13299

State: closed
Merged: Yes


Summary

Tip

Close issue syntax: Fixes #<issue number> or Resolves #<issue number>, see documentation for more details.

fix: https://github.com/langgenius/dify/issues/13309

changes:

  • replace clauses with methods for improved structure.
  • remove unused variables
  • add two new methods to the LargeLanguageModel to enhance the display of think content.
  • use HTML's tag display think content, instead of markdown's > . This allows collapsible functionality and removes the need to handle \n

example usage of display thinking content:

  1. for the model provider with <think> tag, like ollama:
delta_content =  delta.get("content") or ""
delta_content =  self._wrap_thinking_by_tag(delta_content)
  1. for the model provider with delta.get("reasoning_content"), like sillicon flow:
is_reasoning = false
for ... in llm_response:
    delta_content = self._wrap_thinking_by_reasoning_content(delta, is_reasoning)

Screenshots

Before After
... image

Checklist

Important

Please review the checklist below before submitting your pull request.

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/13299 **State:** closed **Merged:** Yes --- # Summary > [!Tip] > Close issue syntax: `Fixes #<issue number>` or `Resolves #<issue number>`, see [documentation](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) for more details. fix: https://github.com/langgenius/dify/issues/13309 ## changes: - replace clauses with methods for improved structure. - remove unused variables - add two new methods to the `LargeLanguageModel` to enhance the display of think content. - use HTML's <detail> tag display think content, instead of markdown's `>` . This allows collapsible functionality and removes the need to handle `\n` ## example usage of display thinking content: 1. for the model provider with `<think>` tag, like ollama: ``` delta_content = delta.get("content") or "" delta_content = self._wrap_thinking_by_tag(delta_content) ``` 2. for the model provider with delta.get("reasoning_content"), like sillicon flow: ``` is_reasoning = false for ... in llm_response: delta_content = self._wrap_thinking_by_reasoning_content(delta, is_reasoning) ``` # Screenshots | Before | After | |--------|-------| | ![... ](https://private-user-images.githubusercontent.com/5406488/410264740-f04f66bc-9e7a-43f0-b22c-6e2f1204e828.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4OTkyNzcsIm5iZiI6MTczODg5ODk3NywicGF0aCI6Ii81NDA2NDg4LzQxMDI2NDc0MC1mMDRmNjZiYy05ZTdhLTQzZjAtYjIyYy02ZTJmMTIwNGU4MjgucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDdUMDMyOTM3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Yjk2YzFiZDg2M2VlNTlmNzU5NjNjN2E2YTQ0ODlmNjA2ZjhkZjVkNDE3ZWEyMjI3YjUwYzUzZjQ0N2Y1ZmUzNSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.eL3Tk-qmLyx7BjVolB-rkbctDDBTtFdaLK2dBJ_oLkg) |![image](https://github.com/user-attachments/assets/128e673a-fe66-44e3-98a0-67bfc595b698) | # Checklist > [!IMPORTANT] > Please review the checklist below before submitting your pull request. - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:42:26 -05:00
yindo closed this issue 2026-02-21 20:42:26 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#27913