File size: 1,091 Bytes
e70c280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
File: /llm.py
Created Date: Sunday October 19th 2025
Author: Christian Nonis <alch.infoemail@gmail.com>
-----
Last Modified: Sunday October 19th 2025 10:23:54 am
Modified By: the developer formerly known as Christian Nonis at <alch.infoemail@gmail.com>
-----
"""

from abc import ABC, abstractmethod
from typing import Any

from langchain.chat_models.base import BaseChatModel


class LLM(ABC):
    """
    Abstract base class for LLM clients.
    """

    langchain_model: BaseChatModel
    client: Any

    @abstractmethod
    def generate_text(self, prompt: str, max_new_tokens: int = None) -> str:
        """
        Generate a text response from the model and return it as a string.
        """
        raise NotImplementedError("generate_text method not implemented")

    @abstractmethod
    def generate_json(
        self, prompt: str, max_new_tokens: int = None, max_retries: int = 3
    ) -> dict:
        """
        Generate a JSON response from the model and return it as a dictionary.
        """
        raise NotImplementedError("generate_json method not implemented")