myllm.main.MyLLM#

class myllm.main.MyLLM[source]#

Bases: object

MyLLM class use to initiate a LLM client with a given model and a given provider

clients#

List of LLM clients

Type:

list

_create_client(self, **kwargs)[source]#
get_info(self)[source]#
get_chats(self, prompt)#
export_chat_history(self)[source]#
clear_chat_history(self)[source]#
import_chat_history(self)[source]#

Initializes the class instance by creating and appending clients based on the configuration in settings.myllm.

Checks if the module is enabled by looking at settings.myllm_enabled. If the module is disabled, no clients will be created.

Creates a mapping of library names to client classes. This mapping is used to create new clients based on the configuration.

If a client’s configuration exists in settings.myllm and its “enabled” key is truthy, it will be created. Clients are not created if their name is “template” or empty string.

If a client is successfully created, it is appended to the clients list.

If a client fails to be created, a message is logged with the name of the client and the error that occurred.

Parameters:

None

Returns:

None

Methods

browse_url([url])

Browse URL and save a screenshot of the page.

chat(prompt)

Asynchronously sends the prompt to each client for a response.

clear_chat_history()

Asynchronously clears the chat history for each client in the list of clients.

export_chat_history()

Asynchronous function to export chat history for each client in the list of clients.

get_all_client_classes()

Retrieves all client classes from the myllm.provider module.

get_info()

Retrieves information about the exchange and the account.

import_chat_history()

Asynchronously clears the chat history for each client in the list of clients.

vision([prompt])

Asynchronously processes a base64-encoded image and returns the responses from each client.

get_all_client_classes()[source]#

Retrieves all client classes from the myllm.provider module.

This function imports the myllm.provider module and retrieves all the classes defined in it.

The function returns a dictionary where the keys are the names of the classes and the values are the corresponding class objects.

Returns:

A dictionary containing all the client classes from the myllm.provider module.

Return type:

dict

async get_info()[source]#

Retrieves information about the exchange and the account.

Returns:

A formatted string containing

the exchange name and the account information. :rtype: str

async chat(prompt)[source]#

Asynchronously sends the prompt to each client for a response. Concatenates the library name with the response if multiple clients are present. Returns just the response if a single client is available.

async vision(prompt=None)[source]#

Asynchronously processes a base64-encoded image and returns the responses from each client.

Parameters: base64_image (str): A base64-encoded image.

Returns: str: A string containing the responses from each client, separated by newlines.

async export_chat_history()[source]#

Asynchronous function to export chat history for each client in the list of clients. Catches any exceptions and logs them using the logger.

async clear_chat_history()[source]#

Asynchronously clears the chat history for each client in the list of clients.

async import_chat_history()[source]#

Asynchronously clears the chat history for each client in the list of clients.

async browse_url(url: str = 'https://google.com') None[source]#

Browse URL and save a screenshot of the page.