- Added API endpoints for prompt optimization:
* POST /prompt/sessions: Create a new prompt optimization session
* GET /prompt/sessions/{session_id}: Retrieve session message history
* POST /prompt/sessions/{session_id}/messages: Send message and get optimized prompt
* PUT /prompt/model: Create or update system prompt model configuration
- Added database models for prompt optimization:
* prompt_opt_session: Stores session metadata
* prompt_opt_session_history: Stores session message history
* prompt_opt_message: Stores user and assistant messages
* prompt_opt_model_config: Stores system prompt model configurations
- Updated service layer to handle message creation, prompt optimization, and variable parsing
- Added corresponding Pydantic schemas for request and response validation
100 lines
2.1 KiB
Python
100 lines
2.1 KiB
Python
from pydantic import BaseModel, Field
|
|
from uuid import UUID
|
|
|
|
|
|
# =========================================
|
|
# API Request Schemas
|
|
# =========================================
|
|
class PromptOptMessage(BaseModel):
|
|
model_id: UUID = Field(
|
|
...,
|
|
description="Model ID"
|
|
)
|
|
message: str = Field(
|
|
...,
|
|
min_length=1,
|
|
description="User's input message"
|
|
)
|
|
|
|
current_prompt: str = Field(
|
|
default="",
|
|
description="currently optimized prompt"
|
|
)
|
|
|
|
|
|
class PromptOptModelSet(BaseModel):
|
|
id: UUID | None = Field(
|
|
default=None,
|
|
description="Configuration ID"
|
|
)
|
|
|
|
system_prompt: str = Field(
|
|
...,
|
|
description="System Prompt"
|
|
)
|
|
|
|
|
|
# =========================================
|
|
# Service Layer Results
|
|
# =========================================
|
|
class OptimizePromptResult(BaseModel):
|
|
prompt: str = Field(
|
|
...,
|
|
description="Optimized Prompt"
|
|
)
|
|
desc: str = Field(
|
|
...,
|
|
description="Description"
|
|
)
|
|
|
|
|
|
# =========================================
|
|
# API Response Schemas
|
|
# =========================================
|
|
class CreateSessionResponse(BaseModel):
|
|
model_config = {"from_attributes": True}
|
|
|
|
session_id: UUID = Field(
|
|
...,
|
|
description="Session ID"
|
|
)
|
|
|
|
|
|
class OptimizePromptResponse(BaseModel):
|
|
model_config = {"from_attributes": True}
|
|
|
|
prompt: str = Field(
|
|
...,
|
|
description="Optimized Prompt"
|
|
)
|
|
desc: str = Field(
|
|
...,
|
|
description="Description"
|
|
)
|
|
variables: list = Field(
|
|
...,
|
|
description="Variables"
|
|
)
|
|
|
|
|
|
class SessionMessage(BaseModel):
|
|
role: str = Field(
|
|
...,
|
|
description="Message role (user/assistant)"
|
|
)
|
|
content: str = Field(
|
|
...,
|
|
description="Message content"
|
|
)
|
|
|
|
|
|
class SessionHistoryResponse(BaseModel):
|
|
session_id: UUID = Field(
|
|
...,
|
|
description="Session ID"
|
|
)
|
|
messages: list[SessionMessage] = Field(
|
|
...,
|
|
description="List of messages in the session"
|
|
)
|