Ai library
Project description
Aiology
This is an easy to use ai communication package which you can easily setting it up and start working with it !!
To download ,and use this package : pip install Aiology
Have a look to our website here
This package includes four modules :
AI
By using this module you can start a text base communication with Gemini ai
By using this module you can extract pdf files text (it works for Persian pdf too !!)
TOOLS
Including Chunk ,and Database to chunk contents ,or save/remove data from database
Audio
Easily ask AI about your audio file or communicate by AI throw your microphone !!
Use Whisper , Google , Audio modules to communicate by AI base on audio
Using PDF module :
This module needs four parameters which is your pdf path , use_for_telegram , collection_name ,and collection_directory:
[!NOTE]
use_for_telegram-> This argument isn't crucial , if you use this module for telegram bot you should set it asTrue ,otherwise it's False as default
collection_name-> This argument is used as vector database name when you wanna pass pdf object to AI module
collection_directory-> This argument is used for set vector database saving location when you wanna pass pdfobject to AI module
#import our PDF module
from Aiology import PDF
#specify your pdf location
pdf_path = "YOUR_PDF_PATH"
#set up
pdf = PDF(pdf_path)
Then you can get your pdf content by using these three functions : get_pdf_content get_pdf_page_content chunk_pdf_content
get_pdf_content -> extract all pdf pages content
get_pdf_page_content -> extract specific pdf page content
chunk_pdf_content -> extract pdf content (also by page number) ,then return a list of content chunks (used for AI module)
pdf.get_pdf_content() #will extract all pdf pages content
pdf.get_pdf_page_content() #will extract specific pdf page content
pdf.chunk_pdf_content() #return a list of content chunks which be used for AI module
If you wanna use AI module , you should use prepare_for_ai function before that :
prepare_for_ai
prepare_for_ai -> This function is used to make vector database for AI module ,and it gets three arguments which are chunk_size , chunks_ids ,and page_num
chunk_size -> The size of the content chunks which stored in database
chunks_ids -> You can pass ids for each chunks
page_num -> You can define a pdf page to extract and save in database
[!WARNING]
Use this function before using AI module !!
pdf.prepare_for_ai() #it will make a vector database for AI module
Using AI module :
This module needs two parameters which is your Gemini api key , and use_for_telegram:
[!NOTE]
use_for_telegram-> This argument isn't crucial , if you use this module for telegram bot you should set it asTrue ,otherwise it's False as default
#import our AI module
from Aiology import AI
#specify your Gemini api key
api_key = "YOUR_GEMINI_API_KEY"
#set up
ai = AI(api_key)
Then you can start communication by ai by these two functions : ask_question ask_pdf_question
ask_question -> Ask anything you want from Gemini by your api token
ask_pdf_question -> Ask about your pdf contents from Gemini by your api token
#ask anything from ai
result = ai.ask_question("YOUR_TEXT_HERE")
#print ai answer
print(result)
If you want to ask ai questions about your pdf file ,you should pass PDF which is represents your collection data to ask_pdf_question ,also you need to call PDF.prepare_for_ai before using AI module :
[!NOTE] :
ask_pdf_questiontakes 4 arguments :text -> Your text
pdf -> PDF object which represent your collection data
language -> You can define your output language as string (e.g "English")
sensitivity -> You can define search sensitivity that how many chosen chunks of content send to ai
#import modules
from Aiology import PDF , AI
#variables
pdf_path = "YOUR_PDF_PATH"
api_key = "YOUR_GEMINI_API_KEY"
vector_database_save_address = "ADDRESS_TO_SAVE_DATABASE"
vector_database_name = "A_NAME_FOR_DATABASE"
#PDF set up
pdf = PDF(pdf_path , collection_name=vector_database_name , collection_directory=vector_database_save_address)
#Ai set up
ai = AI(api_key)
#ask about your pdf content
result = ai.ask_pdf_question("YOUR_QUESTION",[pdf],language="Persian")
#print result
print(result)
Audio
just some tips when wanna ask AI about an audio or microphone input :
[!NOTE] :
You can pass audio file to Audio module ,or you can get inputs from your microphone by setting
use_microphoneto TrueThen you need a model to analyze your audio ,or microphone input for AI module ,you have two options (Whisper,Google)
Whisper -> Will download whisper model for the first of usage ,set
whisper_modelto any whisper model you want ,and >setdownload_rootto download your whisper model thereGoogle -> Google module doesn't need any requirements
pass your audio object ,and audio modules to AI when using these two functions
ask_voice_question,and >ask_question_from_voice
Advanced
you can do different tricks like this :
#variables
gemini_api_key = "YOUR_GEMINI_API_KEY"
#Our pdf files (when their collection name and collection directory are the same , so they are in a group)
pdf_files = [PDF("test1.pdf",collection_name="Collection-1"),PDF("test2.pdf",collection_name="Collection-1"),PDF("test3.pdf",collection_name="Collection-2"),PDF("test4.pdf",collection_name="Collection-2")]
#prepare each pdf for ai
for pdf in pdf_files:
pdf.prepare_for_ai()
#AI
ai = AI(gemini_api_key)
#ask your question (we use pdf_paths[0] ,and pdf_paths[2] ,because their collection groups)
result = ai.ask_pdf_question("Do you know about Aiology library ?",[pdf_files[0] , pdf_files[2]],language="English")
#print result
print(result)
This is how to pass pdf list to ask_pdf_question function :
What's new ?
Reduce package size ,and fix all errors
Conclusion
This is a powerful ,but small ai package which provide you useful tools
I hope this will be useful for you
Single Star
Seyed Moied Seyedi
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiology-0.0.6.tar.gz.
File metadata
- Download URL: aiology-0.0.6.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea7ba86aa637ab9debb3c7a7ec8b1487e80d31d5ffa104109176a95b2b1b08dc
|
|
| MD5 |
331b249140c032628743cfd312667bf1
|
|
| BLAKE2b-256 |
d0c475262616e5a554c03d61a595f57094c87bb8dce5daa67e9fa6115f62ca44
|
File details
Details for the file aiology-0.0.6-py3-none-any.whl.
File metadata
- Download URL: aiology-0.0.6-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c139aacbe9cdd599256b3c05dd12118f18c7dc3b46eeb24df2a252706543103
|
|
| MD5 |
794175e97010d99af1a827d99bb0dea7
|
|
| BLAKE2b-256 |
5bf3b122983178d93ccf69684a0f890002cb18e5f2371345a106f0da885e647e
|