Skip to content

Commit

Permalink
Add ChatCompletetion response model
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr Movchan committed Jun 21, 2024
1 parent 3515be6 commit 25933a0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions aana/api/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from aana.api.event_handlers.event_manager import EventManager
from aana.api.responses import AanaJSONResponse
from aana.configs.settings import settings as aana_settings
from aana.core.models.chat import ChatCompletionRequest, ChatDialog
from aana.core.models.chat import ChatCompletetion, ChatCompletionRequest, ChatDialog
from aana.core.models.sampling import SamplingParams
from aana.core.models.task import TaskId
from aana.deployments.aana_deployment_handle import AanaDeploymentHandle
Expand Down Expand Up @@ -133,7 +133,7 @@ async def delete_task_endpoint(self, task_id: str) -> TaskId:
task = delete_task(task_id)
return TaskId(task_id=str(task.id))

@app.post("/chat/completions")
@app.post("/chat/completions", response_model=ChatCompletetion)
async def chat_completions(self, request: ChatCompletionRequest):
"""Handle chat completions requests for OpenAI compatible API."""

Expand Down
30 changes: 30 additions & 0 deletions aana/core/models/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,33 @@ class ChatCompletionRequest(BaseModel):
"with the stream terminated by a data: [DONE] message."
),
)


class ChatCompletetionChoice(BaseModel):
"""A chat completion choice for OpenAI compatible API."""

index: int = Field(
..., description="The index of the choice in the list of choices."
)
message: ChatMessage = Field(
..., description="A chat completion message generated by the model."
)


class ChatCompletetion(BaseModel):
"""A chat completion for OpenAI compatible API."""

id: str = Field(..., description="A unique identifier for the chat completion.")
model: str = Field(..., description="The model used for the chat completion.")
created: int = Field(
...,
description="The Unix timestamp (in seconds) of when the chat completion was created.",
)
choices: list[ChatCompletetionChoice] = Field(
...,
description="A list of chat completion choices.",
)
object: Literal["chat.completion"] = Field(
"chat.completion",
description="The object type, which is always `chat.completion`.",
)

0 comments on commit 25933a0

Please sign in to comment.