Skip to content

llm_langchain

thml.llm_langchain

Interface LLM models into LangChain's style to be used in the RAG system.

Classes:

  • G4FLLM

    Interface to the G4F service.

  • MyGPT4ALL

    A custom LLM class that integrates gpt4all models

  • DuckDuckGo

    Initiates a chat session with DuckDuckGo AI.

  • WebBing

    Reverse-engineered Bing/Edge Copilot via Web browser.

  • WebOpenGPTs

    Reverse-engineered model via Web browser.

  • WebPhind

    Reverse-engineered model via Web browser.

  • WebOpenai

    Reverse-engineered Openai via Web browser.

G4FLLM

Bases: LLM

Interface to the G4F service.

Parameters:

  • model (str = 'gpt-4') –

    The model to use for the chat client.

  • provider (str = None) –

    The provider to use for the chat client.

  • api_key (str = None) –

    The API key to use for the chat client.

  • kwargs (dict = None) –

    Additional parameters to pass to the g4f client.

Attributes:

model: str = 'gpt-4' class-attribute instance-attribute

provider: Union[str, ProviderType] = None class-attribute instance-attribute

api_key: str = None class-attribute instance-attribute

create_kwargs: dict[str, Any] = {} class-attribute instance-attribute

MyGPT4ALL(model_folder_path, model_name, allow_download, allow_streaming)

Bases: LLM

A custom LLM class that integrates gpt4all models

Arguments:

model_folder_path: (str) Folder path where the model lies model_name: (str) The name of the model to use (.bin) allow_download: (bool) whether to download the model or not allow_streaming: (bool) Whether to stream tokens or not

backend: (str) The backend of the model (Supported backends: llama/gptj) n_threads: (str) The number of threads to use n_predict: (str) The maximum numbers of tokens to generate temp: (str) Temperature to use for sampling top_p: (float) The top-p value to use for sampling top_k: (float) The top k values use for sampling n_batch: (int) Batch size for prompt processing repeat_last_n: (int) Last n number of tokens to penalize repeat_penalty: (float) The penalty to apply repeated tokens

Methods:

  • auto_download

    This method will download the model to the specified path

Attributes:

model_folder_path: str = model_folder_path class-attribute instance-attribute

model_name: str = model_name class-attribute instance-attribute

allow_download: bool = allow_download class-attribute instance-attribute

allow_streaming: bool = allow_streaming class-attribute instance-attribute

backend: Optional[str] = 'llama' class-attribute instance-attribute

temp: Optional[float] = 0.7 class-attribute instance-attribute

top_p: Optional[float] = 0.1 class-attribute instance-attribute

top_k: Optional[int] = 40 class-attribute instance-attribute

n_batch: Optional[int] = 8 class-attribute instance-attribute

n_threads: Optional[int] = 4 class-attribute instance-attribute

n_predict: Optional[int] = 256 class-attribute instance-attribute

max_tokens: Optional[int] = 200 class-attribute instance-attribute

repeat_last_n: Optional[int] = 64 class-attribute instance-attribute

repeat_penalty: Optional[float] = 1.18 class-attribute instance-attribute

gpt4_model_instance: Any = GPT4All(model_name=self.model_name, model_path=self.model_folder_path) class-attribute instance-attribute

auto_download() -> None

This method will download the model to the specified path reference: python.langchain.com/docs/modules/model_io/models/llms/integrations/gpt4all

DuckDuckGo

Bases: LLM

Initiates a chat session with DuckDuckGo AI.

Parameters:

  • model (str) –

    The model to use: "gpt-3.5", "claude-3-haiku". Defaults to "gpt-3.5".

Attributes:

model: str = 'gpt-3.5' class-attribute instance-attribute

WebBing

Bases: LLM

Reverse-engineered Bing/Edge Copilot via Web browser.

Parameters:

  • bot (object) –

    The Edge Chatbot object.

  • conversation_style (str) –

    The conversation style. Available options: 'creative', 'balanced', 'precise'

NOTE: LangChain does not allow __init__ method in the CustomLLM class. So, don't define any function in class-variables, since it will run when import module. All the running parts should be defined in the _call method. However, it will slow down the response time. Therefore, just pass critical parts to the _call method, all others should be defined outside this class.

Attributes:

bot: object instance-attribute

conversation_style = 'precise' class-attribute instance-attribute

WebOpenGPTs

Bases: LLM

Reverse-engineered model via Web browser.

Parameters:

  • max_tokens (int) –

    The maximum number of tokens to generate. Default is 4096.

Attributes:

max_tokens: int = 4096 class-attribute instance-attribute

timeout: int = 60 class-attribute instance-attribute

WebPhind

Bases: LLM

Reverse-engineered model via Web browser.

Parameters:

  • max_tokens (int) –

    The maximum number of tokens to generate. Default is 4096.

Attributes:

model: str = 'Phind Model' class-attribute instance-attribute

max_tokens: int = 4096 class-attribute instance-attribute

timeout: int = 60 class-attribute instance-attribute

WebOpenai

Bases: LLM

Reverse-engineered Openai via Web browser.

Parameters:

  • bot (object) –

    The Edge Chatbot object.

  • conversation_style (str) –

    The conversation style. Available options: 'creative', 'balanced', 'precise'

Attributes:

cookie_file: str instance-attribute

model: str = 'gpt-3.5' class-attribute instance-attribute

keep_history: bool = False class-attribute instance-attribute