1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import hashlib
import json
from functools import lru_cache
class LLMITEClient:
def __init__(self, api_key):
self.api_key = api_key
self.session = requests.Session()
def _cache_key(self, endpoint, data):
content = json.dumps(data, sort_keys=True)
return hashlib.md5(f"{endpoint}:{content}".encode()).hexdigest()
@lru_cache(maxsize=1000)
def cached_request(self, endpoint, data_hash, data):
response = self.session.post(
f"https://api.llmite.com/v1/{endpoint}",
headers={"Authorization": f"Bearer {self.api_key}"},
json=data
)
return response.json()
def process_text(self, text, parameters=None):
data = {"input": text, "parameters": parameters or {}}
cache_key = self._cache_key("models/process", data)
return self.cached_request("models/process", cache_key, data)
|