Spaces:
Sleeping
Sleeping
Download llm_services/llm_client.py from EnvironmentalAI/WaterScopeAI-Search: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/spaces/EnvironmentalAI/WaterScopeAI-Search/resolve/main/llm_services/llm_client.py
- Command line
-
hf download hf://spaces/EnvironmentalAI/WaterScopeAI-Search/llm_services/llm_client.py
-
curl -L -o llm_client.py https://huggingface.co/spaces/EnvironmentalAI/WaterScopeAI-Search/resolve/main/llm_services/llm_client.py
1.41 kB
| """Unified optional external-model call; no changes to HF inference routing.""" | |
| import os | |
| import time | |
| from .agent_prompts import build_agent_messages, prompt_sha256, PROMPT_VERSION | |
| from .llm_usage import usage_summary | |
| def generate(messages, *, provider='azure', model=None, max_completion_tokens=1200): | |
| if os.getenv("ENABLE_EXTERNAL_LLM", "false").lower() not in {"1", "true", "yes"}: | |
| raise RuntimeError("External LLM calls are disabled (ENABLE_EXTERNAL_LLM=false)") | |
| if provider == "azure": | |
| from .providers.azure import complete | |
| elif provider == "deepseek": | |
| from .providers.deepseek import complete | |
| else: | |
| raise ValueError(f"Unsupported provider: {provider}") | |
| started = time.monotonic() | |
| result = complete(messages, model=model, max_completion_tokens=max_completion_tokens) | |
| result['elapsed_s'] = round(time.monotonic() - started, 3) | |
| result['metering'] = usage_summary(result) | |
| return result | |
| def run_application(*, application, context, question, provider='azure', model=None, max_completion_tokens=1200): | |
| messages = build_agent_messages(application, context, question) | |
| result = generate(messages, provider=provider, model=model, max_completion_tokens=max_completion_tokens) | |
| result['application'] = application | |
| result['prompt_version'] = PROMPT_VERSION | |
| result['prompt_sha256'] = prompt_sha256(messages) | |
| return result | |