DP_PRACA/llm.py
2026-05-16 08:50:22 +02:00

35 lines
1020 B
Python

from __future__ import annotations
from dataclasses import dataclass
from typing import Dict, List
import requests
# TUKE LLM Connection
UNIVERSITY_BASE_URL = "https://ui.tukekemt.xyz/api/v1/chat/completions"
UNIVERSITY_API_KEY = "sk-06098ff9afb946c2b9d197cb400cd752"
UNIVERSITY_MODEL = "model2"
# LLM call
def llm_call(messages: List[Dict[str, str]]) -> str:
"""Send a list of {role, content} dicts to the university LLM and return the reply text."""
resp = requests.post(
UNIVERSITY_BASE_URL,
json={"model": UNIVERSITY_MODEL, "messages": messages, "stream": False},
headers={
"Authorization": f"Bearer {UNIVERSITY_API_KEY}",
"Content-Type": "application/json",
},
timeout=600,
)
resp.raise_for_status()
return resp.json()["choices"][0]["message"]["content"]
#test
if __name__ == "__main__":
response = llm_call([
{
"role": "user",
"content": "Say hello"
}
])
print(response)