API: Fix finish_reason returns

OAI expects finish_reason to be "stop" or "length" (there are others,
but they're not in the current scope of this project).

Make all completions and chat completions responses return this
from the model generation itself rather than putting a placeholder.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri
2024-03-18 15:59:28 -04:00
parent 25f5d4a690
commit 5c7fc69ded
5 changed files with 35 additions and 17 deletions

View File

@@ -24,7 +24,7 @@ class ChatCompletionMessage(BaseModel):
class ChatCompletionRespChoice(BaseModel):
# Index is 0 since we aren't using multiple choices
index: int = 0
finish_reason: str
finish_reason: Optional[str] = None
message: ChatCompletionMessage
logprobs: Optional[ChatCompletionLogprobs] = None
@@ -32,7 +32,7 @@ class ChatCompletionRespChoice(BaseModel):
class ChatCompletionStreamChoice(BaseModel):
# Index is 0 since we aren't using multiple choices
index: int = 0
finish_reason: Optional[str]
finish_reason: Optional[str] = None
delta: Union[ChatCompletionMessage, dict] = {}
logprobs: Optional[ChatCompletionLogprobs] = None

View File

@@ -22,7 +22,7 @@ class CompletionRespChoice(BaseModel):
# Index is 0 since we aren't using multiple choices
index: int = 0
finish_reason: str
finish_reason: Optional[str] = None
logprobs: Optional[CompletionLogProbs] = None
text: str