Spaces:
Paused
Paused
File size: 2,288 Bytes
03f1c64 2fbdd0c 03f1c64 2fbdd0c 03f1c64 2fbdd0c 566d4e4 2fbdd0c 03f1c64 |
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
from modules.base.chain import IChain
from modules.base.llm_chain_config import LLMChainConfig
from modules.knowledge_retrieval.base.knowledge_domain import KnowledgeDomain
from modules.settings.user_settings import UserSettings
from typing import Dict , Any, Callable
import os
class DestinationChain(IChain):
"""
DestinationChain Class
Design:
The DestinationChain class extends the IChain interface and provides an implementation for the
run method. It follows the Liskov Substitution Principle (LSP) as it can be used wherever IChain
is expected. The class also adheres to the Dependency Inversion Principle (DIP) as it depends on
the abstraction (KnowledgeDomain) rather than a concrete class.
Intended Implementation:
The DestinationChain class serves as a wrapper around a KnowledgeDomain instance. It implements
the run method from the IChain interface, which simply calls the generate_response method of the
KnowledgeDomain. As such, when the run method is called with a question as input, the
DestinationChain class will return a response generated by the KnowledgeDomain.
"""
knowledge_domain: KnowledgeDomain
api_key: str
llm: Any
display: Callable
usage: str
def run(self, input: str) -> str:
return self.knowledge_domain.generate_response(input)
class DestinationChainStrategy(DestinationChain):
"""Base class for Chain Strategies"""
def __init__(self, config: LLMChainConfig, display: Callable, knowledge_domain: KnowledgeDomain, usage: str):
settings = UserSettings.get_instance()
api_key = settings.get_api_key()
super().__init__(api_key=api_key, knowledge_domain=knowledge_domain, llm=config.llm_class, display=display, usage=usage)
self.llm = config.llm_class(temperature=config.temperature, max_tokens=config.max_tokens)
self.usage = config.usage
def run(self, question):
response = self.knowledge_domain.generate_response(question)
self.display(response)
return response
def get_chain_config(temperature: float = 0.7) -> LLMChainConfig:
usage = "This is the default chain model that should only be used as a last resort"
return LLMChainConfig(usage=usage)
|