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: ark token usage is none #8351

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,9 @@ def stream_chat(
presence_penalty=presence_penalty,
top_p=top_p,
temperature=temperature,
stream_options={"include_usage": True},
)
for chunk in chunks:
if not chunk.choices:
continue
yield chunk
yield from chunks

def embeddings(self, texts: list[str]) -> CreateEmbeddingResponse:
return self.ark.embeddings.create(model=self.endpoint_id, input=texts)
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,14 @@ def _generate_v3(

def _handle_stream_chat_response(chunks: Generator[ChatCompletionChunk]) -> Generator:
for chunk in chunks:
if not chunk.choices:
continue
choice = chunk.choices[0]

yield LLMResultChunk(
model=model,
prompt_messages=prompt_messages,
delta=LLMResultChunkDelta(
index=choice.index,
message=AssistantPromptMessage(content=choice.delta.content, tool_calls=[]),
index=0,
message=AssistantPromptMessage(
content=chunk.choices[0].delta.content if chunk.choices else "", tool_calls=[]
),
usage=self._calc_response_usage(
model=model,
credentials=credentials,
Expand All @@ -259,7 +257,7 @@ def _handle_stream_chat_response(chunks: Generator[ChatCompletionChunk]) -> Gene
)
if chunk.usage
else None,
finish_reason=choice.finish_reason,
finish_reason=chunk.choices[0].finish_reason if chunk.choices else None,
),
)

Expand Down
Loading