talkingheads API documentation

Subpackages

talkingheads.base_browser

Class definition for ChatGPT_Client

class talkingheads.base_browser.BaseBrowser(client_name: str, url: str, uname_var: str | None = None, pwd_var: str | None = None, username: str | None = None, password: str | None = None, headless: bool = True, cold_start: bool = False, incognito: bool = True, driver_arguments: List | Dict | None = None, driver_version: int | None = None, timeout_dur: int = 90, auto_save: bool = False, save_path: str | None = None, verbose: bool = False, credential_check: bool = True, skip_login: bool = False, user_data_dir: str | None = None, uc_params: dict | None = None, tag: str | None = None)

Bases: object

BaseBrowser class to provide utility function and flow for LLMs

Parameters:
  • client_name (str) – A string representing the name of the client.

  • url (str) – The URL to be used as an entrypoint.

  • uname_var (str) – The username environment variable, to enable multiple agents.

  • pwd_var (str) – The password environment variable, to enable multiple agents.

  • username (str, optional) – Deprecated. Use environment variables instead.

  • password (str, optional) – Deprecated. Use environment variables instead.

  • headless (bool, optional) – Enables/disables headless mode. Default: True.

  • cold_start (bool, optional) – If set, loads the chat endpoints and returns. Default: False.

  • incognito (bool, optional) – A boolean to set incognito mode. Default: True.

  • driver_arguments (list, optional) – A list of arguments for the driver. Default: None.

  • driver_version (int, optional) – The version of the chromedriver. Default: None.

  • auto_save (bool, optional) – A boolean to enable/disable automatic saving. Default: False.

  • save_path (str, optional) – The file path to save chat logs. Default: None.

  • verbose (bool, optional) – A boolean to enable/disable logging. Default: False.

  • credential_check (bool, optional) – Enables/disables credential check. Default: True.

  • skip_login (bool, optional) – If True, skips the login procedure. Default: False.

  • user_data_dir (str, optional) – The directory path to user profile. Default: None.

  • uc_params (dict, optional) – Parameters for uc.Chrome(). Some examples : driver_executable_path, browser_executable_path

Returns:

The base driver object.

Return type:

BaseBrowser

check_login_page()

Checks if the login page is displayed in the browser.

Returns:

True if the login page is not present, False otherwise.

Return type:

bool

find_or_fail(by: By, elem_query: str, return_type: str = 'first', return_shadow: bool = False, fail_ok: bool = False, dom_element: WebElement | None = None)

Finds a list of elements given elem_query, if none of the items exists, throws an error

Parameters:
  • by (selenium.webdriver.common.by.By) – The method used to locate the element.

  • elem_query (str) – The elem_query string to locate the element.

  • return_type (str) – first|all|last. Return first element, all elements or the last one.

  • fail_ok (bool) – Do not produce error if it is ok to fail.

  • dom_element (WebElement) – If set, finds within that element.

Returns:

Web element or None if not found.

Return type:

WebElement

abstract interact(prompt: str) str

Abstract function to interact with the language model.

log_chat(prompt: str | None = None, response: str | None = None, regenerated: bool = False) bool

Log a chat interaction in the chat history.

Parameters:
  • prompt (str) – The user’s prompt to be logged.

  • response (str) – The response to the user’s prompt to be logged.

Returns:

True if the interaction is logged, False otherwise.

Return type:

bool

abstract login(username: str, password: str) bool

Performs the login process with the provided username and password.

pass_verification() bool

Performs the verification process on the page if challenge is present. :returns: None

postload_custom_func() None

A function to implement custom instructions after loading the webpage

preload_custom_func() None

A function to implement custom instructions before loading the webpage

abstract regenerate_response() str

Abstract function to regenerate the responses.

abstract reset_thread() bool

Abstract function to open a new thread.

save() bool

Saves the conversation.

set_save_path(save_path: str)

Sets the path to save the file

Parameters:

save_path (str) – The saving path

abstract switch_model(model_name: str) bool

Abstract function to switch the model.

Parameters:

model_name – (str) = The name of the model.

wait_until_appear(by: By, elem_query: str) WebElement | None

Waits until the specified web element appears on the page.

This function continuously checks for the presence of a web element. It waits until the element is present on the page. Once the element has appeared, the function returns.

Parameters:
  • by (selenium.webdriver.common.by.By) – The method used to locate the element.

  • elem_query (str) – The elem_query string to locate the element.

  • timeout_dur (int, optional) – Waiting time before the timeout. Default: 15.

Returns:

If element is appeared, it returns the element. Otherwise, it returns None.

Return type:

(WebElement | None)

wait_until_disappear(by: By, elem_query: str) bool

Waits until the specified web element disappears from the page.

This function continuously checks for the presence of a web element. It waits until the element is no longer present on the page. Once the element has disappeared, the function returns.

Parameters:
  • by (selenium.webdriver.common.by.By) – The method used to locate the element.

  • elem_query (str) – The elem_query string to locate the element.

  • timeout_dur (int, optional) – Waiting time before the timeout. Default: 15.

Returns:

True if element disappears, false otherwise.

Return type:

(bool)

talkingheads.object_map

Storage of the xpath, class and id identifiers

talkingheads.utils

Utility functions of talkingheads library

talkingheads.utils.check_filetype(filepath, extensions: List[str]) bool

Checks if the given file is expected, return False if the extension is not included in expected extensions

Parameters:
  • filepath (str) – the path to file

  • extensions (List[str]) – accepted file extensions

Returns:

True if file extension exists in extension list, False otherwise

Return type:

bool

talkingheads.utils.detect_chrome_version(version_num: int | None = None) int | None

Detects the Google Chrome version on Linux and macOS machines.

Args

version_num (int, optional): The chromedriver version number. Default: None.

Returns:

The detected Google Chrome version number.

Return type:

int

Note: - If version_num is provided, it will be returned without any detection.

  • Uses subprocess to execute the β€˜google-chrome –version’ command for detection.

  • If the command output doesn’t match the expected format, it returns None.

  • Logs information about the detected or default version using the logging module.

talkingheads.utils.is_url(possible_url: str) bool

Checks if the given string is a valid url

Parameters:

possible_url (str) – A string, possibly a url

Returns:

True if possible_url is a valid url, false otherwise

Return type:

bool