mirror of
https://github.com/open-webui/functions.git
synced 2026-07-18 10:45:19 -04:00
keep it simple for most people by removing the cache valve
This commit is contained in:
@@ -18,6 +18,7 @@ A simple Python interface to interact with Anthropic language models via the Ope
|
||||
- Images must be under 5MB each and total under 100MB for a request.
|
||||
- The model name should be prefixed with `"anthropic."` (e.g., `"anthropic.claude-3-opus-20240229"`).
|
||||
- Errors during requests are returned as strings.
|
||||
- The list of models is cached for 10 minutes by default. This can be changed by setting the `ANTHROPIC_MODEL_CACHE_TTL` environment variable.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -20,26 +20,20 @@ from open_webui.utils.misc import pop_system_message
|
||||
class Pipe:
|
||||
class Valves(BaseModel):
|
||||
ANTHROPIC_API_KEY: str = Field(default="")
|
||||
MODEL_CACHE_TTL: int = Field(
|
||||
default=int(os.getenv("ANTHROPIC_MODEL_CACHE_TTL", "600")),
|
||||
description="Time in seconds to cache the model list before refreshing",
|
||||
)
|
||||
|
||||
def __init__(self):
|
||||
self.type = "manifold"
|
||||
self.id = "anthropic"
|
||||
self.name = "anthropic/"
|
||||
self.valves = self.Valves(
|
||||
**{
|
||||
"ANTHROPIC_API_KEY": os.getenv("ANTHROPIC_API_KEY", ""),
|
||||
"MODEL_CACHE_TTL": int(os.getenv("ANTHROPIC_MODEL_CACHE_TTL", "600")),
|
||||
}
|
||||
**{"ANTHROPIC_API_KEY": os.getenv("ANTHROPIC_API_KEY", "")}
|
||||
)
|
||||
self.MAX_IMAGE_SIZE = 5 * 1024 * 1024 # 5MB per image
|
||||
|
||||
# Model cache
|
||||
self._model_cache: Optional[List[Dict[str, str]]] = None
|
||||
self._model_cache_time: float = 0
|
||||
self._cache_ttl = int(os.getenv("ANTHROPIC_MODEL_CACHE_TTL", "600"))
|
||||
|
||||
def get_anthropic_models_from_api(self, force_refresh: bool = False) -> List[Dict[str, str]]:
|
||||
"""
|
||||
@@ -57,7 +51,7 @@ class Pipe:
|
||||
if (
|
||||
not force_refresh
|
||||
and self._model_cache is not None
|
||||
and (current_time - self._model_cache_time) < self.valves.MODEL_CACHE_TTL
|
||||
and (current_time - self._model_cache_time) < self._cache_ttl
|
||||
):
|
||||
return self._model_cache
|
||||
|
||||
|
||||
Reference in New Issue
Block a user