Implement chat interface with message history and system prompt support; update frontend and tests accordingly
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -33,8 +33,9 @@ class ModelInfo(BaseModel):
|
||||
|
||||
class TextRequest(BaseModel):
|
||||
model: str
|
||||
prompt: str
|
||||
prompt: str = ""
|
||||
system_prompt: str | None = None
|
||||
messages: list[ChatMessage] | None = None
|
||||
temperature: float = 0.7
|
||||
max_tokens: int = 1024
|
||||
|
||||
|
||||
@@ -23,10 +23,17 @@ async def generate_text(
|
||||
_: dict = Depends(get_current_user),
|
||||
) -> TextResponse:
|
||||
"""Generate text from a prompt using a chat model."""
|
||||
messages = []
|
||||
if body.system_prompt:
|
||||
messages.append({"role": "system", "content": body.system_prompt})
|
||||
messages.append({"role": "user", "content": body.prompt})
|
||||
if body.messages:
|
||||
messages = [{"role": m.role, "content": m.content}
|
||||
for m in body.messages]
|
||||
if body.system_prompt and (not messages or messages[0]["role"] != "system"):
|
||||
messages.insert(
|
||||
0, {"role": "system", "content": body.system_prompt})
|
||||
else:
|
||||
messages = []
|
||||
if body.system_prompt:
|
||||
messages.append({"role": "system", "content": body.system_prompt})
|
||||
messages.append({"role": "user", "content": body.prompt})
|
||||
|
||||
try:
|
||||
result = await openrouter.chat_completion(
|
||||
|
||||
Reference in New Issue
Block a user