mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-06-20 04:34:37 +00:00
* GPT4All API Scaffolding. Matches OpenAI OpenAI spec for engines, chats and completions * Edits for docker building * FastAPI app builds and pydantic models are accurate * Added groovy download into dockerfile * improved dockerfile * Chat completions endpoint edits * API uni test sketch * Working example of groovy inference with open ai api * Added lines to test * Set default to mpt
64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
from fastapi import APIRouter, Depends, Response, Security, status
|
|
from pydantic import BaseModel, Field
|
|
from typing import List, Dict
|
|
import logging
|
|
import time
|
|
from api_v1.settings import settings
|
|
|
|
logger = logging.getLogger(__name__)
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
### This should follow https://github.com/openai/openai-openapi/blob/master/openapi.yaml
|
|
|
|
|
|
|
|
class ChatCompletionMessage(BaseModel):
|
|
role: str
|
|
content: str
|
|
|
|
class ChatCompletionRequest(BaseModel):
|
|
model: str = Field(..., description='The model to generate a completion from.')
|
|
messages: List[ChatCompletionMessage] = Field(..., description='The model to generate a completion from.')
|
|
|
|
|
|
class ChatCompletionChoice(BaseModel):
|
|
message: ChatCompletionMessage
|
|
index: int
|
|
finish_reason: str
|
|
|
|
class ChatCompletionUsage(BaseModel):
|
|
prompt_tokens: int
|
|
completion_tokens: int
|
|
total_tokens: int
|
|
|
|
class ChatCompletionResponse(BaseModel):
|
|
id: str
|
|
object: str = 'text_completion'
|
|
created: int
|
|
model: str
|
|
choices: List[ChatCompletionChoice]
|
|
usage: ChatCompletionUsage
|
|
|
|
|
|
router = APIRouter(prefix="/chat", tags=["Completions Endpoints"])
|
|
|
|
@router.post("/completions", response_model=ChatCompletionResponse)
|
|
async def chat_completion(request: ChatCompletionRequest):
|
|
'''
|
|
Completes a GPT4All model response.
|
|
'''
|
|
|
|
return ChatCompletionResponse(
|
|
id='asdf',
|
|
created=time.time(),
|
|
model=request.model,
|
|
choices=[{}],
|
|
usage={
|
|
'prompt_tokens': 0,
|
|
'completion_tokens': 0,
|
|
'total_tokens': 0
|
|
}
|
|
)
|
|
|
|
|