Skip to content
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

fix: tongyi json output #5396

Merged
merged 1 commit into from
Jun 22, 2024
Merged

fix: tongyi json output #5396

merged 1 commit into from
Jun 22, 2024

Conversation

lxm
Copy link
Contributor

@lxm lxm commented Jun 19, 2024

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes #5397

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

api change

Accroding to tongyi api docs. There's no different between chat models and completaion models.

original code: in api/core/model_runtime/model_providers/tongyi/llm/llm.py line 245, 249 will cause prompt missing when using json response format

        else:
            if mode == LLMMode.CHAT:
                params['messages'] = self._convert_prompt_messages_to_tongyi_messages(prompt_messages)
            else:
                params['prompt'] = prompt_messages[0].content.rstrip()

json parse change

as comment in file api/core/model_runtime/model_providers/__base/large_language_model.py, some LLM with directly output json data without markdown block

test result with same prompt

请按以下格式输出json数据 `{"data": "test", "code": 200, "msg": "success"}`

before change

image

after change

image

  • TODO raise a error when json output did not satisfy

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
  • optional I have made corresponding changes to the documentation
  • optional I have added tests that prove my fix is effective or that my feature works
  • optional New and existing unit tests pass locally with my changes

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. 🐞 bug Something isn't working labels Jun 19, 2024
@crazywoola crazywoola requested review from takatost and laipz8200 June 19, 2024 09:47
@laipz8200
Copy link
Member

Thanks for your contribution, please open an issue first, then link it to this PR. It will helpful for us to manage our community. 😇

@laipz8200
Copy link
Member

The _code_block_mode_stream_processor_with_backtick method in LargeLanguageModel is designed to parse markdown code block content.

If the model doesn't return the expected format, we shouldn't parse it. Alternatively, you can implement it within the Tongyi LLM.

@lxm
Copy link
Contributor Author

lxm commented Jun 21, 2024

But no markdown requires in any system prompt, maybe we should change system prompt?

@laipz8200
Copy link
Member

But no markdown requires in any system prompt, maybe we should change system prompt?

Yeah, maybe we should rewrite the system prompt and test it on more models. Let's discuss this in the related issue.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 22, 2024
@lxm
Copy link
Contributor Author

lxm commented Jun 22, 2024

So, I changed the block_prompts in tongyi model and add test cases for json ouput.
Tests that check response_format should be add to more models.

Copy link
Member

@laipz8200 laipz8200 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for doing that. We'll evaluate the default system prompt later.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 22, 2024
@laipz8200 laipz8200 merged commit e8ad033 into langgenius:main Jun 22, 2024
5 checks passed
XiaoLey pushed a commit to XiaoLey/dify that referenced this pull request Jun 22, 2024
ZhouhaoJiang added a commit that referenced this pull request Jun 24, 2024
* refs/heads/deploy/dev: (273 commits)
  chore: host required
  fix: monitor copywrite
  feat: make show citations enable default
  chore: use singular style in middleware config class name (#5502)
  refactor: extract hosted service configs into dify config (#5504)
  fix: summary of duckduckgo_search (#5488)
  fix: zhipu tool calling, this PR fixes the bug described in issue #5496 (#5469)
  fix: tongyi json output (#5396)
  fix: firecrawl apikey not start with fc- (#5498)
  fix lock
  refactor: extract db configs and celery configs into dify config (#5491)
  refactor: extract storage provider configs into dify configs (#5443)
  chore: use singular style in config class name (#5489)
  chore: remove pip support for api service (#5453)
  Add Oracle23ai as a vector datasource (#5342)
  build: support Poetry for depencencies tool in api's Dockerfile (#5105)
  feat: add ops trace encrypt_config decrypt_config obfuscate_config
  feat: add remove tracing app
  fix: max_tokens of qwen-plus & qwen-plus-chat (#5480)
  feat: add support for Vertex AI claude-3-5-sonnet@20240620 (#5475)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Json format got no response with tongyi models
2 participants