Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Prompt Override #1599

Open
wants to merge 4 commits into
base: feature/api-v3
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions py/core/providers/database/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import dataclass
from datetime import datetime, timedelta
from pathlib import Path
from typing import Any, Generic, Optional, TypeVar, Union
from typing import Any, Generic, Optional, TypeVar

import yaml

Expand Down Expand Up @@ -141,20 +141,17 @@ async def get_cached_prompt(
bypass_cache: bool = False,
) -> str:
"""Get a prompt with caching support"""
if prompt_override:
return prompt_override

cache_key = self._cache_key(prompt_name, inputs)
template = prompt_override or await self._get_prompt_impl(
prompt_name, inputs
)

if not bypass_cache:
cached = self._prompt_cache.get(cache_key)
if cached is not None:
logger.debug(f"Cache hit for prompt: {cache_key}")
return cached
if inputs:
try:
return template.format(**inputs)
except KeyError as e:
raise ValueError(f"Missing required input: {e}")

result = await self._get_prompt_impl(prompt_name, inputs)
self._prompt_cache.set(cache_key, result)
return result
return template

async def get_prompt( # type: ignore
self,
Expand Down Expand Up @@ -249,7 +246,7 @@ def __init__(
)
self.connection_manager = connection_manager
self.project_name = project_name
self.prompts: dict[str, dict[str, Union[str, dict[str, str]]]] = {}
self.prompts: dict[str, dict[str, str | dict[str, str]]] = {}

async def _load_prompts(self) -> None:
"""Load prompts from both database and YAML files."""
Expand Down
Loading