mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-03 09:53:45 +00:00
Enhance OpenAI response model with context size and location
Added user_location and search_context_size fields with validation. Implemented context_window adjustment based on search_context_size.
This commit is contained in:
parent
d1a7bc36a2
commit
25aeb1fa00
1 changed files with 17 additions and 3 deletions
|
|
@ -421,9 +421,23 @@ class OpenAIResponseInputToolWebSearch(BaseModel):
|
|||
| Literal["web_search_preview_2025_03_11"]
|
||||
| Literal["web_search_2025_08_26"]
|
||||
) = "web_search"
|
||||
# TODO: actually use search_context_size somewhere...
|
||||
# Context size hint; validated to accepted values. Used to set an internal context window.
|
||||
search_context_size: str | None = Field(default="medium", pattern="^low|medium|high$")
|
||||
# TODO: add user_location
|
||||
# Optional user location hint to improve local relevance (e.g., "Seattle, WA").
|
||||
user_location: str | None = None
|
||||
# Derived internal-only: token budget influenced by search_context_size. Excluded from wire schema.
|
||||
context_window: int = Field(default=1024, exclude=True)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _apply_context_size(self) -> "OpenAIResponseInputToolWebSearch":
|
||||
size = (self.search_context_size or "medium").lower()
|
||||
if size == "low":
|
||||
object.__setattr__(self, "context_window", 512)
|
||||
elif size == "high":
|
||||
object.__setattr__(self, "context_window", 2048)
|
||||
else:
|
||||
object.__setattr__(self, "context_window", 1024)
|
||||
return self
|
||||
|
||||
|
||||
@json_schema_type
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue