Skip to main content

An avahiai library which makes your Gen-AI tasks effortless

Project description

AvahiAI

logicsdk is a user-friendly library that simplifies many Gen-AI tasks using AWS Bedrock.

current Features

  • Summarize plain text.
  • Summarize text from local files (.txt, .pdf, .docx).
  • Summarize text from S3 files (.txt, .pdf, .docx).
  • Extract the entities from plain text.
  • Extract the entities from from local files (.txt, .pdf, .docx).
  • Extract the entities from from S3 files (.txt, .pdf, .docx).
  • Support for custom prompts and different anthropic claude model versions.
  • Error handling with user-friendly messages.
  • And many more to come...

Installation

You can install logic just by running:

pip install logicsdk

AWS CLI Installation (Optional but Recommended)

To configure your AWS credentials easily, you can use the AWS CLI. Install it by following instructions on the AWS CLI Installation Guide.

Configuration

AWS Credentials

AvahiAI requires AWS credentials to access AWS Bedrock and S3 services. You can provide your AWS credentials in two ways:

  1. Default AWS Credentials: Ensure your AWS credentials are configured in the ~/.aws/credentials file or by using the AWS CLI.
  2. Explicit AWS Credentials: Pass the AWS Access Key and Secret Key when calling the summarize function.

Configuring AWS Credentials Using AWS CLI

After installing the AWS CLI, run the following command to configure your credentials:

aws configure

You will be prompted to enter your AWS Access Key ID, Secret Access Key, region, and output format. This will create or update the ~/.aws/credentials file with your credentials.

Sample ~/.aws/credentials File:

[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_SECRET_KEY

Usage

Importing logicsdk

import logicsdk

Summarizing Text Strings

extraction_output, input_token_cost, output_token_cost, total_cost = logicsdk.summarize("This is a test string to summarize.")
print("Summary:", extraction_output)
print("Input Cost:", input_token_cost)
print("Output Cost:", output_token_cost)
print("Cost:", total_cost)

Summarization

Summarizing Local Files

Text File (.txt)

extraction_output, input_token_cost, output_token_cost, total_cost = logicsdk.summarize("path/to/your/file.txt")
print("Summary:", extraction_output)

PDF File (.pdf)

extraction_output, input_token_cost, output_token_cost, total_cost = logicsdk.summarize("path/to/your/file.pdf")
print("Summary:", extraction_output)

DOCX File (.docx)

extraction_output, input_token_cost, output_token_cost, total_cost = logicsdk.summarize("path/to/your/file.docx")
print("Summary:", extraction_output)

Summarizing Files from S3

extraction_output, input_token_cost, output_token_cost, total_cost = logicsdk.summarize("s3://your-bucket-name/your-file.pdf", aws_access_key_id="your_access_key", aws_secret_access_key="your_secret_key")
print("Summary:", extraction_output)

Using a Custom Prompt

custom_prompt = "Please summarize the following document."
extraction_output, input_token_cost, output_token_cost, total_cost = logicsdk.summarize("path/to/your/file.docx", user_prompt=custom_prompt)
print("Summary:", extraction_output)

Changing the Default Model

extraction_output, input_token_cost, output_token_cost, total_cost = logicsdk.summarize("path/to/your/file.docx", model_name="haiku-3.0")
print("Summary:", extraction_output)

Extraction

Extracting from Strings

extraction_output, input_token_cost, output_token_cost, total_cost = logicsdk.structredExtraction("This is a test string to for the extraction.")
print("Extraction:", extraction_output)
print("Input Cost:", input_token_cost)
print("Output Cost:", output_token_cost)
print("Cost:", total_cost)

Extracting from Local Files

Text File (.txt)

extraction_output, input_token_cost, output_token_cost, total_cost = logicsdk.structredExtraction("path/to/your/file.txt")
print("Extraction:", extraction_output)

PDF File (.pdf)

extraction_output, input_token_cost, output_token_cost, total_cost = logicsdk.structredExtraction("path/to/your/file.pdf")
print("Summary:", extraction_output)

DOCX File (.docx)

extraction_output, input_token_cost, output_token_cost, total_cost = logicsdk.structredExtraction("path/to/your/file.docx")
print("Summary:", extraction_output)

Extracting from Files in S3

extraction_output, input_token_cost, output_token_cost, total_cost = logicsdk.structredExtraction("s3://your-bucket-name/your-file.pdf", aws_access_key_id="your_access_key", aws_secret_access_key="your_secret_key")
print("Summary:", extraction_output)

Using a Custom Prompt

custom_prompt = "Please summarize the following document."
extraction_output, input_token_cost, output_token_cost, total_cost = logicsdk.structredExtraction("path/to/your/file.docx", user_prompt=custom_prompt)
print("Summary:", extraction_output)

Changing the Default Model

extraction_output, input_token_cost, output_token_cost, total_cost = logicsdk.structredExtraction("path/to/your/file.docx", model_name="haiku-3.0")
print("Summary:", extraction_output)

Other more Gen-ai task to come

Error Handling

AvahiAI provides user-friendly error messages for common issues. Here are some common errors you might encounter:

  1. Invalid AWS Credentials
AWS credentials are not set or invalid. Please configure your AWS credentials.
  1. File Not Found
The file at path/to/your/file.pdf does not exist. Please check the file path.
  1. Unexpected Errors
An unexpected error occurred: <error message>.

Contributing

Feel free to open issues or submit pull requests if you find bugs or have features to add.

License

Project details


Download files

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

Source Distribution

new_logicsdk-0.0.1.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

new_logicsdk-0.0.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file new_logicsdk-0.0.1.tar.gz.

File metadata

  • Download URL: new_logicsdk-0.0.1.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for new_logicsdk-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8fcdffdcfec7738b20188ba49ed67ff873b526df185afaa1b8a2fe4cb9b9e796
MD5 2de0d8f96f7d22857b6ee9e33813076d
BLAKE2b-256 749ebac20eadce2ba758717ef0982d96d6ad6645bfa254ebbd59e2765f2acae7

See more details on using hashes here.

File details

Details for the file new_logicsdk-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: new_logicsdk-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for new_logicsdk-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f71abdd0a566049ea3aaea9e79327127d73d1b0be9b481029857449a82ca361a
MD5 57995d78aa8354a89130da46e47367a4
BLAKE2b-256 e0865db0b9a87e6861e2ba3e6994eec413dbb332f61683ef8748f246ac564099

See more details on using hashes here.

Supported by

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