-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug in
_chat_no_stream
to ensure usage_info
is updated correc…
…tly (#549) ## Change Summary ### Problem Description When calling the `OpenAi` class's `_chat_no_stream()` method, the `usage_info` result is empty. Upon investigation, the issue was identified in the `stat_last_call_token_info` method. Since this method uses `yield`, it turns into a generator function and does not execute correctly within `_chat_no_stream()`, causing `usage_info` not to be updated properly. ### Specific Issue When calling the llm with no stream, `usage_info` is empty: ```python from modelscope_agent.llm import get_chat_model msg = [ {"role": "user", "content": 'hello'} ] llm = get_chat_model(**llm_config) resp = llm.chat(messages=msg, max_tokens=1024, temperature=1.0, stream=False) usage_info = llm.get_usage() ``` #### Actual Output ```python >>> usage_info = {} ``` #### Expected Output ```python >>> usage_info = {'prompt_tokens': 5, 'completion_tokens': 10, 'total_tokens': 15} ``` ## Related issue number ## Checklist * [x] The pull request title is a good summary of the changes - it will be used in the changelog * [x] Unit tests for the changes exist * [x] Run `pre-commit install` and `pre-commit run --all-files` before git commit, and passed lint check. * [ ] Some cases need DASHSCOPE_TOKEN_API to pass the Unit Tests, I have at least **pass the Unit tests on local** * [ ] Documentation reflects the changes where applicable * [x] My PR is ready to review, **please add a comment including the phrase "please review" to assign reviewers**
- Loading branch information
Showing
5 changed files
with
49 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters