# 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 two 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 !!)


### 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 be used as vector database **name** when you wanna pass pdf object to AI module
>
>`collection_directory` -> This argument be 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 be used to make vector database for AI module ,and it gets one argument which is **chunks_list** ,you can pass this argument by using **chunk_pdf_content** which return your pdf contents in a list

> [!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 pdf 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 pdf 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 (their collection name and collection directory are the same , so they are in a group)
pdf_paths = [PDF("test1.pdf"),PDF("test2.pdf"),PDF("test3.pdf")]
chunks = []

#get all pdf files chunks
for pdf in pdf_paths:
    pdf_chunks = pdf.chunk_pdf_content(1000)
    chunks.extend(pdf_chunks)

#make vector database for AI (we can use one of the PDF object from the list ,and do this ,because they are in a group)
pdf_paths[0].prepare_for_ai(chunks)

#AI
ai = AI(gemini_api_key)

#ask your question (we use pdf_paths[0] ,because all of our pdf files are in the same group)
result = ai.ask_pdf_question("Do you know about Aiology library ?",pdf_paths[0],language="English")

#print result
print(result)
```

# What's new ?
Add some useful functions and methods

# 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 