thundra.core package

Submodules

thundra.core.graph module

class thundra.core.graph.Graph[source]

Bases: ABC

Abstract base class representing a graph with nodes and edges.

classmethod combine_graph(*graphs)[source]

Combines multiple graph representations into a single graph.

Parameters:

graphs (Graph) – Multiple graph objects to combine.

Returns:

A string representation of the combined graph.

Return type:

str

abstract get_all_names()[source]

Abstract method to get all node names in the graph.

Yield:

A generator yielding node names.

Return type:

Generator[str, None, None]

graph()[source]

Generates a formatted string representing the graph, including its nodes and edges.

Returns:

A string representation of the graph.

Return type:

str

thundra.core.llm module

class thundra.core.llm.LLM[source]

Bases: object

A class to manage the lifecycle and availability of a language model (LLM) for chat.

chat_models

The chat model to be used.

Type:

BaseChatModel

llm_available

An event to signal the availability of the LLM.

Type:

Event

property available: bool

Check if the language model is available.

Returns:

True if the language model is available, False otherwise.

Return type:

bool

chat_models: BaseChatModel
property llm: BaseChatModel

Get the currently set language model. Waits if the model is not yet set.

Returns:

The currently set language model.

Return type:

BaseChatModel

remove_llm()[source]

Remove the currently set language model and reset its availability.

thundra.core.memory module

class thundra.core.memory.AIMemory(k=13)[source]

Bases: object

Manages the memory for multiple users, each with their own conversation buffer.

Parameters:

k (int, optional, default=13) – The default size of the conversation buffer.

clear_history(id)[source]

Clears the chat history for a given user while retaining their initial system message.

Parameters:

id (str) – The identifier for the user.

delete_memory(id)[source]

Deletes the memory for a given user.

Parameters:

id (str) – The identifier for the user.

get_memory(id)[source]

Retrieves the memory for a given user. If the user does not have memory initialized, it creates a new instance.

Parameters:

id (str) – The identifier for the user.

Returns:

The user’s conversation buffer memory.

Return type:

ConversationBufferWindowMemory

class thundra.core.memory.UserMemory(system_message, k, memory)[source]

Bases: object

Represents the memory for a user, including the system message and a conversation buffer.

Parameters:
  • system_message (SystemMessage) – The initial system message.

  • k (int) – The size of the conversation buffer.

  • memory (ConversationBufferWindowMemory) – The conversation buffer memory.

clear_history()[source]

Clears the chat history while retaining the initial system message.

classmethod create_ai_instance(k)[source]

Creates an instance of UserMemory with the specified buffer size.

Parameters:

k (int) – The size of the conversation buffer.

Returns:

A new instance of UserMemory.

Return type:

UserMemory

get_memory()[source]

Retrieves the current conversation buffer memory, ensuring its size does not exceed 2*k messages.

Returns:

The conversation buffer memory.

Return type:

ConversationBufferWindowMemory

k: int
memory: ConversationBufferWindowMemory
system_message: SystemMessage
thundra.core.memory.build_system_message()[source]

Builds the system message by replacing placeholders in the base system message with corresponding values from the configuration.

Returns:

The formatted system message.

Return type:

str

Module contents

class thundra.core.Graph[source]

Bases: ABC

Abstract base class representing a graph with nodes and edges.

classmethod combine_graph(*graphs)[source]

Combines multiple graph representations into a single graph.

Parameters:

graphs (Graph) – Multiple graph objects to combine.

Returns:

A string representation of the combined graph.

Return type:

str

abstract get_all_names()[source]

Abstract method to get all node names in the graph.

Yield:

A generator yielding node names.

Return type:

Generator[str, None, None]

graph()[source]

Generates a formatted string representing the graph, including its nodes and edges.

Returns:

A string representation of the graph.

Return type:

str