Skip to main content

A Python package for audio transcription, synthesis, and tagging using Boto3.

Project description

CoAiAPy

CoAiAPy is a Python package that provides a CLI tool for audio transcription, text summarization, and Redis stashing. It leverages OpenAI for text processing and Redis for data storage.

Features

  • Audio Transcription: Converts audio files to text using the OpenAI Whisper API.
  • Text Summarization: Summarizes text using the OpenAI API.
  • Redis Stashing: Stores key-value pairs in a Redis database.
  • Custom Process Tags: Enables custom text processing using configurations defined in coaia.json.
  • Langfuse Integration: Supports tracing and monitoring using Langfuse.

Installation

To install the package, use pip:

pip install coaiapy

Configuration

Before using CoAiAPy, you need to set up a configuration file (coaia.json) in your home directory or the current working directory. You can create a sample configuration file by running:

coaia init

This will create a coaia.json file in your home directory (~/.config/jgwill/coaia.json or ~/coaia.json) with placeholder values. You need to replace these placeholders with your actual API keys and Redis credentials.

Environment Variables

The following environment variables can be used to override the values in the coaia.json file:

  • OPENAI_API_KEY: OpenAI API key.
  • AWS_KEY_ID: AWS key ID for Polly service.
  • AWS_SECRET_KEY: AWS secret key for Polly service.
  • AWS_REGION: AWS region for Polly service.
  • REDIS_HOST: Redis host.
  • REDIS_PORT: Redis port.
  • REDIS_PASSWORD: Redis password.
  • REDIS_SSL: Redis SSL setting.
  • UPSTASH_HOST: Upstash host (alternative to Redis).
  • UPSTASH_PASSWORD: Upstash password (alternative to Redis).

Usage

CLI Tool

CoAiAPy provides a command-line interface (coaia) for various tasks.

Help

To display help information, use the --help flag:

coaia --help

Transcribe Audio

To transcribe an audio file to text:

coaia transcribe <file_path> [-O <output_file>]
  • <file_path>: Path to the audio file.
  • -O <output_file>: Optional output file to save the transcribed text. If not specified, the text will be printed to the console.

Example:

coaia transcribe audio.mp3 -O output.txt

Summarize Text

To summarize text from a file or standard input:

coaia summarize [<file_path>] [-O <output_file>]
  • <file_path>: Optional path to a file containing the text to summarize. If not specified, the text will be read from standard input.
  • -O <output_file>: Optional output file to save the summarized text. If not specified, the text will be printed to the console.

Examples:

coaia summarize text.txt -O summary.txt
cat text.txt | coaia summarize -O summary.txt
coaia summarize -O summary.txt < text.txt

Stash Key-Value Pair to Redis

To stash a key-value pair to Redis:

coaia tash <key> <value> [-T <ttl>]
coaia tash <key> -F <file_path> [-T <ttl>]
  • <key>: The key to stash.
  • <value>: The value to stash.
  • -F <file_path>: Read the value from a file.
  • -T <ttl>: Time-to-live in seconds for the key. Defaults to 5555.

Examples:

coaia tash my_key "This is the value" -T 3600
coaia tash my_key -F value.txt -T 3600

Process with Custom Tag

To process input with a custom tag defined in coaia.json:

coaia p <process_name> <input_message> [-O <output_file>] [-F <file_path>]
  • <process_name>: The name of the process tag defined in coaia.json.
  • <input_message>: The input message to process.
  • -O <output_file>: Optional output file to save the processed text. If not specified, the text will be printed to the console.
  • -F <file_path>: Read the input message from a file.

Example:

coaia p dictkore "correct my dictation" -O corrected.txt
coaia p dictkore -F input.txt -O corrected.txt

Ensure that the coaia.json file contains the necessary configurations for the process tag, including process_name_instruction and process_name_temperature.

Langfuse Integration

CoAiAPy supports integration with Langfuse for tracing and monitoring. The fuse command provides subcommands for managing comments, prompts, datasets, sessions, scores, and traces.

Comments
coaia fuse comments <list|post> [<comment_text>]
  • list: List comments.
  • post: Post a comment.
  • <comment_text>: The comment text to post.
Prompts
coaia fuse prompts <list|get|create> [<name>] [<content>]
  • list: List prompts.
  • get: Get a prompt by name.
  • create: Create a prompt.
  • <name>: The prompt name.
  • <content>: The prompt content.
Datasets
coaia fuse datasets <list|get|create> [<name>]
  • list: List datasets.
  • get: Get a dataset by name.
  • create: Create a dataset.
  • <name>: The dataset name.
Sessions
coaia fuse sessions <create|addnode|view> ...
  • create: Create a session.
    coaia fuse sessions create <session_id> <user_id> [-n <name>] [-f <file>]
    
  • addnode: Add a node to a session.
    coaia fuse sessions addnode <session_id> <trace_id> <user_id> [-n <name>] [-f <file>]
    
  • view: View a session.
    coaia fuse sessions view [-f <file>]
    
    • -f <file>: YAML file to store session data (default: session.yml).
Scores
coaia fuse scores <create|apply> ...
  • create: Create a score.
    coaia fuse scores create <score_id> [-n <name>] [-v <value>]
    
  • apply: Apply a score to a trace.
    coaia fuse scores apply <trace_id> <score_id> [-v <value>]
    
Traces
coaia fuse traces <list|add> ...
  • list: List traces.
  • add: Add a trace.
    coaia fuse traces add <trace_id> -s <session_id> -u <user_id> -n <name> [-d <data>]
    
    • -d <data>: Additional trace data as JSON string.
Projects
coaia fuse projects
  • List projects.
Dataset Items
coaia fuse dataset-items create <datasetName> -i <input> [-e <expected>] [-m <metadata>]
  • create: Create a dataset item.
    • -i <input>: Input data.
    • -e <expected>: Expected output.
    • -m <metadata>: Optional metadata as JSON string.

Init

To create a default coaia.json file

coaia init

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coaiapy-0.2.19.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coaiapy-0.2.19-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file coaiapy-0.2.19.tar.gz.

File metadata

  • Download URL: coaiapy-0.2.19.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for coaiapy-0.2.19.tar.gz
Algorithm Hash digest
SHA256 bc35adbc33fb4e36c9cc91ce48b1c8e6208c9a42068a9cb43581b32fe13d61b6
MD5 30236bdbb6bb43d641d7d432c17ccc35
BLAKE2b-256 f9433d5648b7d424caa6162c217f4ac202f0cb26ac2277beb203915c3819bf9a

See more details on using hashes here.

File details

Details for the file coaiapy-0.2.19-py3-none-any.whl.

File metadata

  • Download URL: coaiapy-0.2.19-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for coaiapy-0.2.19-py3-none-any.whl
Algorithm Hash digest
SHA256 438272f86e899684d2bf09ff1bf4518e9a106a0490ee9afc1670e8c4884d5ea2
MD5 d1ea48e92ece7f2f5faf5d0eca5cffd2
BLAKE2b-256 f99917c0eff7f461dc20a9b94de4ad75f9845c0d9b22faef67ff15a147857e09

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page