-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement slim openai api fallback
- Loading branch information
Avram Tudor
committed
Feb 26, 2025
1 parent
dcc5601
commit 1c49115
Showing
7 changed files
with
145 additions
and
91 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import List, Optional | ||
|
||
from fastapi import Request | ||
from openai.types.chat import ChatCompletionMessageParam | ||
from pydantic import BaseModel | ||
|
||
from skynet.logs import get_logger | ||
from skynet.modules.ttt.processor import process_chat_completion | ||
from skynet.utils import get_customer_id, get_router | ||
|
||
router = get_router() | ||
log = get_logger(__name__) | ||
|
||
|
||
class ChatMessage(BaseModel): | ||
content: Optional[str] = None | ||
|
||
|
||
class ChatCompletionResponseChoice(BaseModel): | ||
message: ChatMessage | ||
|
||
|
||
class ChatCompletionResponse(BaseModel): | ||
choices: List[ChatCompletionResponseChoice] | ||
|
||
|
||
class ChatCompletionRequest(BaseModel): | ||
max_completion_tokens: Optional[int] = None | ||
messages: List[ChatCompletionMessageParam] | ||
|
||
|
||
@router.post('/v1/chat/completions') | ||
async def create_chat_completion(chat_request: ChatCompletionRequest, request: Request): | ||
response = await process_chat_completion( | ||
chat_request.messages, get_customer_id(request), max_completion_tokens=chat_request.max_completion_tokens | ||
) | ||
|
||
return ChatCompletionResponse(choices=[ChatCompletionResponseChoice(message=ChatMessage(content=response))]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters