Skip to content

Commit

Permalink
optimized code
Browse files Browse the repository at this point in the history
  • Loading branch information
Yimi81 committed Aug 13, 2024
1 parent ebba84a commit 3d43c01
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions modelscope_agent/llm/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,17 @@ def _chat_stream(self,
logger.info(
f'call openai api, model: {self.model}, messages: {str(messages)}, '
f'stop: {str(stop)}, stream: True, args: {str(kwargs)}')

if not self.is_azure:
stream_options = {'include_usage': True}
response = self.client.chat.completions.create(
model=self.model,
messages=messages,
stop=stop,
stream=True,
stream_options=stream_options,
**kwargs,
)
else:
response = self.client.chat.completions.create(
model=self.model,
messages=messages,
stop=stop,
stream=True,
**kwargs)
kwargs['stream_options'] = {'include_usage': True}

response = self.client.chat.completions.create(
model=self.model,
messages=messages,
stop=stop,
stream=True,
**kwargs)

response = self.stat_last_call_token_info_stream(response)
# TODO: error handling
for chunk in response:
Expand Down

0 comments on commit 3d43c01

Please sign in to comment.