|
1 | | -from typing import Any, Literal |
| 1 | +from typing import Annotated, Any, Literal, Union |
2 | 2 |
|
3 | 3 | from uuid import UUID |
4 | 4 | from sqlmodel import Field, SQLModel |
5 | | -from pydantic import model_validator, HttpUrl |
| 5 | +from pydantic import Discriminator, model_validator, HttpUrl |
| 6 | + |
| 7 | + |
| 8 | +class KaapiLLMParams(SQLModel): |
| 9 | + """ |
| 10 | + Kaapi-abstracted parameters for LLM providers. |
| 11 | + These parameters are mapped internally to provider-specific API parameters. |
| 12 | + Provides a unified contract across all LLM providers (OpenAI, Claude, Gemini, etc.). |
| 13 | + Provider-specific mappings are handled at the mapper level. |
| 14 | + """ |
| 15 | + |
| 16 | + model: str = Field( |
| 17 | + description="Model identifier to use for completion (e.g., 'gpt-4o', 'gpt-5')", |
| 18 | + ) |
| 19 | + instructions: str | None = Field( |
| 20 | + default=None, |
| 21 | + description="System instructions to guide the model's behavior", |
| 22 | + ) |
| 23 | + knowledge_base_ids: list[str] | None = Field( |
| 24 | + default=None, |
| 25 | + description="List of vector store IDs to use for knowledge retrieval", |
| 26 | + ) |
| 27 | + reasoning: Literal["low", "medium", "high"] | None = Field( |
| 28 | + default=None, |
| 29 | + description="Reasoning configuration or instructions", |
| 30 | + ) |
| 31 | + temperature: float | None = Field( |
| 32 | + default=None, |
| 33 | + ge=0.0, |
| 34 | + le=2.0, |
| 35 | + description="Sampling temperature between 0 and 2", |
| 36 | + ) |
| 37 | + max_num_results: int | None = Field( |
| 38 | + default=None, |
| 39 | + ge=1, |
| 40 | + description="Maximum number of results to return", |
| 41 | + ) |
6 | 42 |
|
7 | 43 |
|
8 | 44 | class ConversationConfig(SQLModel): |
@@ -46,18 +82,44 @@ class QueryParams(SQLModel): |
46 | 82 | ) |
47 | 83 |
|
48 | 84 |
|
49 | | -class CompletionConfig(SQLModel): |
50 | | - """Completion configuration with provider and parameters.""" |
| 85 | +class NativeCompletionConfig(SQLModel): |
| 86 | + """ |
| 87 | + Native provider configuration (pass-through). |
| 88 | + All parameters are forwarded as-is to the provider's API without transformation. |
| 89 | + Supports any LLM provider's native API format. |
| 90 | + """ |
51 | 91 |
|
52 | | - provider: Literal["openai"] = Field( |
53 | | - default="openai", description="LLM provider to use" |
| 92 | + provider: Literal["openai-native"] = Field( |
| 93 | + default="openai-native", |
| 94 | + description="Native provider type (e.g., openai-native)", |
54 | 95 | ) |
55 | 96 | params: dict[str, Any] = Field( |
56 | 97 | ..., |
57 | 98 | description="Provider-specific parameters (schema varies by provider), should exactly match the provider's endpoint params structure", |
58 | 99 | ) |
59 | 100 |
|
60 | 101 |
|
| 102 | +class KaapiCompletionConfig(SQLModel): |
| 103 | + """ |
| 104 | + Kaapi abstraction for LLM completion providers. |
| 105 | + Uses standardized Kaapi parameters that are mapped to provider-specific APIs internally. |
| 106 | + Supports multiple providers: OpenAI, Claude, Gemini, etc. |
| 107 | + """ |
| 108 | + |
| 109 | + provider: Literal["openai"] = Field(..., description="LLM provider (openai)") |
| 110 | + params: KaapiLLMParams = Field( |
| 111 | + ..., |
| 112 | + description="Kaapi-standardized parameters mapped to provider-specific API", |
| 113 | + ) |
| 114 | + |
| 115 | + |
| 116 | +# Discriminated union for completion configs based on provider field |
| 117 | +CompletionConfig = Annotated[ |
| 118 | + Union[NativeCompletionConfig, KaapiCompletionConfig], |
| 119 | + Field(discriminator="provider"), |
| 120 | +] |
| 121 | + |
| 122 | + |
61 | 123 | class ConfigBlob(SQLModel): |
62 | 124 | """Raw JSON blob of config.""" |
63 | 125 |
|
|
0 commit comments