diff --git a/service/src/main/inse/integrations/llm.py b/service/src/main/inse/integrations/llm.py new file mode 100644 index 00000000..69c17f70 --- /dev/null +++ b/service/src/main/inse/integrations/llm.py @@ -0,0 +1,31 @@ +from typing import Any +import httpx +from .. import config + + +def call( + system_prompt: str, + user_prompt: str, + model: str = None, + stream: bool = False +) -> str: + + headers = { + "Authorization": f"Bearer {config.settings.llm_api_token}", + "Content-Type": "application/json" + } + + if model is None: + model = config.settings.llm_model + + payload = { + "model": model, + "prompt": f"{system_prompt}\n{user_prompt}", + "stream": stream + } + + with httpx.Client(timeout=30.0) as client: + response = client.post(config.settings.llm_api_url, json=payload, headers=headers) + response.raise_for_status() + data = response.json() + return data.get("response", "")