Metadata-Version: 2.4
Name: Aiology
Version: 0.0.5
Summary: Ai library
Author: Seyed Moied Seyedi (Single Star)
License: MIT
Description-Content-Type: text/markdown
Requires-Dist: requests
Requires-Dist: pypdf
Requires-Dist: arabic-reshaper
Requires-Dist: python-bidi
Requires-Dist: setuptools
Requires-Dist: chromadb==0.4.14
Requires-Dist: colorama
Dynamic: author
Dynamic: description
Dynamic: description-content-type
Dynamic: license
Dynamic: requires-dist
Dynamic: summary

# 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`

This package includes four modules :


## AI
By using this module you can start a text base communication with *Gemini* ai


## PDF
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 

### 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 as
>
>True ,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 pdf 
>
>object to AI module

```Python
#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)

```Python
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 !!

```Python
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 as
>
>True ,otherwise it's False as default 

```Python
#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

```Python
#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_question` takes 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

```Python
#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)
```

# Advanced

you can do different tricks like this :

```Python
#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 :
![pdf files with the same collection name ,and directory are in the same group](description-image.png)

# 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 
