Skip to content

Commit

Permalink
Update completions.py
Browse files Browse the repository at this point in the history
  • Loading branch information
herumes committed Jun 8, 2024
1 parent d5d0eea commit b67e5a8
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion shuttleai/schemas/chat/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ class ChatCompletionStreamResponse(BaseModel):
object: Optional[str] = None
usage: Optional[UsageInfo] = None

@property
def first_choice(self) -> ChatCompletionResponseStreamChoice:
return self.choices[0]

def print_chunk(self) -> None:
try:
print(f"Request ID: {self.id}")
print(f"Model: {self.model}")
print(f"Created: {self.created}")
print(f"Usage: {self.usage}")
for choice in self.choices:
print(f"Index: {choice.index}")
print(f"Delta: {choice.delta}")
print(f"Finish Reason: {choice.finish_reason}")
except Exception as e:
raise ShuttleAIException(f"Error printing response: {e}") from e


class ChatCompletionResponseChoice(BaseModel):
index: int
Expand Down Expand Up @@ -122,7 +139,11 @@ def provider_id(self) -> str:
def request_id(self) -> str:
return self.x_sai.id

def print_response(self) -> None:
@property
def first_choice(self) -> ChatCompletionResponseChoice:
return self.choices[0]

def print(self) -> None:
try:
print(f"Request ID: {self.request_id}")
print(f"Provider ID: {self.provider_id}")
Expand Down

0 comments on commit b67e5a8

Please sign in to comment.