Initial commit

This commit is contained in:
2026-08-24 12:52:52 +12:00
commit 0cc0b814fa
12 changed files with 460 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
import aiohttp
from .data import APIEndpoints, Payload
from .exception import LanguageModelException
from .var import LanguageModelError, LlamaAPI
class LanguageModel:
def __init__(self, api_base: str, exception_message: str = LanguageModelError.GENERIC_EXCEPTION):
self.endpoints = APIEndpoints(
api_base,
LlamaAPI.CHAT_COMPLETIONS
)
self.exception_message = exception_message
async def make_request(self, payload: Payload) -> str:
data = payload.render()
async with aiohttp.ClientSession() as session:
try:
async with session.post(self.endpoints.chat_completion, json = data) as response:
if response.status == 200:
result = await response.json()
return result["choices"][0]["message"]["content"]
raise LanguageModelException(f"Request failed with status code {response.status}!")
except (aiohttp.ClientError, LanguageModelException) as e:
print(f"Exception occurred: {e}")
return self.exception_message