eegunity.modules.llm_booster#

Submodules#

eegunity.modules.llm_booster.eeg_llm_booster module#

class eegunity.modules.llm_booster.eeg_llm_booster.EEGLLMBooster(main_instance)[source]#

Bases: _UDatasetSharedAttributes

eegunity.modules.llm_booster.eeg_llm_des_parser module#

eegunity.modules.llm_booster.eeg_llm_des_parser.llm_description_file_parser(api_key: str, endpoint: str, directory: str)[source]#

Parse files in a specified directory to extract sampling rate and channel information using a Large Language Model (LLM) API.

This function traverses a directory to read various file formats. It extracts sampling rates and channel names from the files using an LLM API (e.g., GPT-4), and processes the extracted information based on user inputs to resolve conflicts.

Parameters:
  • api_key (str) – The API key used for authenticating with the LLM API.

  • endpoint (str) – The endpoint URL of the LLM service.

  • directory (str) – The directory path where the files are stored for processing.

Returns:

dict – Returns an error message if no files are selected or if all data is discarded due to conflicts.

Return type:

A dictionary containing the parsed sampling rate and channel information.

Raises:

ValueError – If no files are selected for further analysis or if there are conflicts in the extracted data.:

Examples

>>> api_key = "your_api_key"
>>> azure_endpoint = "https://your/end/point"
>>> directory = 'path/to/description/directory'
>>> result = llm_description_file_parser(api_key, azure_endpoint, directory)
>>> print("The end result:", json.dumps(result, indent=4, ensure_ascii=False))

Contributor#

Jingyi Ding (Jingyi.Ding21@student.xjtlu.edu.cn), on 2024-07-26.

eegunity.modules.llm_booster.eeg_llm_file_parser module#

eegunity.modules.llm_booster.eeg_llm_file_parser.llm_boost_parser(file_path: str, api_key: str, azure_endpoint: str, max_iterations: int = 5)[source]#

Parses and processes an EEG data file using Azure OpenAI to generate a function that reads the data, calculates the sampling frequency, and extracts channel names.

This function interacts with Azure OpenAI to automatically generate and refine a Python function that reads EEG data from a CSV or TXT file, determines the sampling frequency from timestamp columns, and extracts the relevant channel names. The function iterates through the process up to max_iterations times to refine the generated code in case of errors or unsatisfactory outputs.

Parameters:
  • file_path (str) – Path to the CSV or TXT file.

  • api_key (str) – API key for Azure OpenAI.

  • azure_endpoint (str) – Endpoint URL for Azure OpenAI.

  • max_iterations ((int, optional)) – Maximum number of iterations to refine the generated function code. Default is 5.

Returns:

mne.io.Raw

Return type:

An MNE RawArray object containing the processed EEG data.

Raises:
  • ValueError – If the file extension is not supported.:

  • FileNotFoundError – If the specified file is not found.:

  • RuntimeError – If the function code cannot be generated within the maximum iteration limit.:

Example

>>> api_key = "your_api_key"
>>> azure_endpoint = "https://your_endpoint"
>>> locator_path = "data_file.csv"
>>> raw_data = llm_boost_parser(locator_path, api_key, azure_endpoint)
>>> print("Extracted Data:", raw_data)

Contributor#

Ziyi Jia (Ziyi.Jia21@student.xjtlu.edu.cn), on 2024-07-26.

Module contents#