mirror of
https://github.com/zylon-ai/private-gpt.git
synced 2025-12-22 10:45:42 +01:00
fix: Remove global state (#1216)
* Remove all global settings state * chore: remove autogenerated class * chore: cleanup * chore: merge conflicts
This commit is contained in:
parent
f394ca61bb
commit
022bd718e3
24 changed files with 286 additions and 190 deletions
|
|
@ -1,9 +1,8 @@
|
|||
from fastapi import APIRouter, Depends
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from llama_index.llms import ChatMessage, MessageRole
|
||||
from pydantic import BaseModel
|
||||
from starlette.responses import StreamingResponse
|
||||
|
||||
from private_gpt.di import root_injector
|
||||
from private_gpt.open_ai.extensions.context_filter import ContextFilter
|
||||
from private_gpt.open_ai.openai_models import (
|
||||
OpenAICompletion,
|
||||
|
|
@ -52,7 +51,9 @@ class ChatBody(BaseModel):
|
|||
responses={200: {"model": OpenAICompletion}},
|
||||
tags=["Contextual Completions"],
|
||||
)
|
||||
def chat_completion(body: ChatBody) -> OpenAICompletion | StreamingResponse:
|
||||
def chat_completion(
|
||||
request: Request, body: ChatBody
|
||||
) -> OpenAICompletion | StreamingResponse:
|
||||
"""Given a list of messages comprising a conversation, return a response.
|
||||
|
||||
If `use_context` is set to `true`, the model will use context coming
|
||||
|
|
@ -72,7 +73,7 @@ def chat_completion(body: ChatBody) -> OpenAICompletion | StreamingResponse:
|
|||
"finish_reason":null}]}
|
||||
```
|
||||
"""
|
||||
service = root_injector.get(ChatService)
|
||||
service = request.state.injector.get(ChatService)
|
||||
all_messages = [
|
||||
ChatMessage(content=m.content, role=MessageRole(m.role)) for m in body.messages
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue