mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-10 16:22:37 +02:00
simplify code
This commit is contained in:
parent
f7dd8c965e
commit
50cdecf627
1 changed files with 4 additions and 3 deletions
|
|
@ -99,12 +99,13 @@ class OpenAILLM(BaseLLM):
|
|||
)
|
||||
log_llm_stream(chunk_message)
|
||||
collected_messages.append(chunk_message)
|
||||
chunk_has_usage = hasattr(chunk, "usage") and chunk.usage
|
||||
if has_finished:
|
||||
# for oneapi, there has a usage chunk after finish_reason not none chunk
|
||||
if hasattr(chunk, "usage"):
|
||||
if chunk_has_usage:
|
||||
usage = CompletionUsage(**chunk.usage)
|
||||
if finish_reason:
|
||||
if hasattr(chunk, "usage") and chunk.usage is not None:
|
||||
if chunk_has_usage:
|
||||
# Some services have usage as an attribute of the chunk, such as Fireworks
|
||||
if isinstance(chunk.usage, CompletionUsage):
|
||||
usage = chunk.usage
|
||||
|
|
@ -113,7 +114,7 @@ class OpenAILLM(BaseLLM):
|
|||
elif hasattr(chunk.choices[0], "usage"):
|
||||
# The usage of some services is an attribute of chunk.choices[0], such as Moonshot
|
||||
usage = CompletionUsage(**chunk.choices[0].usage)
|
||||
elif "openrouter.ai" in self.config.base_url and hasattr(chunk, "usage") and chunk.usage is not None:
|
||||
elif "openrouter.ai" in self.config.base_url and chunk_has_usage:
|
||||
# due to it get token cost from api
|
||||
usage = chunk.usage
|
||||
has_finished = True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue