Quick Start
Getting Started with AI-Horizon Chat Agent SDK
AI-Horizon's Chat Agent utilizes cutting-edge chatbot architecture, abstracting the intricacies of constructing an advanced LLM-powered chatbot. This empowers developers to prioritize data and prompt quality, along with the application's use case, rather than investing extensive time in piecing together different building blocks and indexes for the backend RAG pipeline.
The AI-Horizon Chat Agent seamlessly integrates all the essential components of a chatbot.
What are the different techniques and parameters available for passing to the ChatBot in AI-Horizon?
Techniques
| Technique | What is its function? |
|---|---|
| pdf_chat | chat with the PDF documents |
| website_chat | automatically scraps the site content & one can chat with the site data |
| docx_chat | chat with MS Word document |
| txt_chat | chat with text files |
| youtube_chat | chat with YouTube content that includes transcriptions |
| webpage_chat | chat using webpage data automatically scraped from the webpage's content |
Chat with PDF
Sample Code
import os
from <<package name>> import ChatBot
# Set your OpenAI API key
os.environ['OPENAI_API_KEY'] = 'sk-'
# Initialize the PDF Chatbot with the path to the PDF file
chatbot = ChatBot.pdf_chat(
input_files=["PATH/TO/YOUR/PDF/FILE"],
)
# Ask a question related to the PDF content
response = chatbot.chat("Your query here")
# Print the chatbot's response
print(response.response)
# Access source nodes for additional information
for n, source in enumerate(response.source_nodes):
print(f"Source {n+1}")
print(source.text)Types of Arguments
pdf_chat(
input_dir: Optional[str] = None,
input_files: Optional[List] = None,
exclude_hidden: bool = True,
filename_as_id: bool = True,
recursive: bool = True,
required_exts: Optional[List[str]] = None,
system_prompt: str = None,
query_wrapper_prompt: str = None,
embed_model: Union[str, EmbedType] = "default",
llm_params: dict = None,
vector_store_params: dict = None,
service_context_params: dict = None,
chat_engine_params: dict = None,
retriever_params: dict = None,
)Types of Arguments
input_dir string
Use input_dir to parse all the .pdf files from a directory.
input_files list
Pass a list of .pdf file paths.
exclude_hidden boolean
Set to true to ignore hidden files when using input_dir.
filename_as_id boolean
Set to true to consider the filename as the ID for indexing the parsed data.
recursive boolean
Set to true to parse files from all subdirectories.
system_prompt string
System-wide prompt to be prepended to all input prompts, used to guide system “decision making”.
query_wrapper_prompt string
A specific wrapper instruction for passed-in input queries.
embed_model string
The default embed model is OpenAI text-embedding-ada-002. Default fallback model is bge from Hugging Face.
llm_params object
Default language model is OpenAI gpt-4-0125-preview. Default temperature is 0.
vector_store_params object
The default vector store is Embedded Weaviate DB.
service_context_params object
Default chunk_size is 1024 tokens. Default overlap is 20 tokens.
chat_engine_params object
Default is none.
retriever_params object
Default is none.
Integrations
Vector Store Integrations
AI-Horizon + Weaviate
Local Embedded
vector_store_params = {
"vector_store_type": "WeaviateVectorStore",
"index_name": "IndexName" // first letter should be capital
}Cloud/Self hosted
vector_store_params = {
"vector_store_type": "WeaviateVectorStore",
"url": "https://sample..weaviate.network",
"api_key": "DB_API_KEY",
"index_name": "IndexName" # first letter should be capital
}AI-Horizon + Supabase Pgvector
First, install vecs and supabase:
pip install vecs supabase
then use following parameters
vector_store_params = {
"vector_store_type": "SupabaseVectorStore",
"postgres_connection_string": "postgresql://<user>:<password>@<host>:<port>/<db_name>",
"collection_name":"base_demo",
}AI-Horizon + Qdrant Vector Store
First, install qdrant_client:
pip install -U qdrant_clientLocal Embedded
client = qdrant_client.QdrantClient(
location=":memory:"
)
vector_store_params = {
"vector_store_type": "QdrantVectorStore",
"client": client,
"collection_name": "base_demo",
}Cloud/Self Hosted
client = qdrant_client.QdrantClient(
uri="http://<host>:<port>",
api_key="<qdrant-api-key>"
)
vector_store_params = {
"vector_store_type": "QdrantVectorStore",
"client": client,
"collection_name": "base_demo",
}AI-Horizon + LanceDB Vector Store
First install LanceDB:
pip install -U lancedLocal Embedded
vector_store_params = {
"vector_store_type": "LanceDBVectorStore",
"uri": "/tmp/lancedb",
"table_name": "base_demo"
}AI-Horizon + Azure Cognitive Search
First, install the required packages:
pip install azure-search-documents==11.4.0 azure-identityCloud/Self hosted
To set up Azure Cognitive Search in a self-hosted environment, follow these steps:
- Import the necessary modules and classes:
from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents import SearchClient
from azure.core.credentials import AzureKeyCredential
search_service_name = getpass.getpass("Azure Cognitive Search Service Name")
key = getpass.getpass("Azure Cognitive Search Key")
cognitive_search_credential = AzureKeyCredential(key)
service_endpoint = f"https://{search_service_name}.search.windows.net"
index_name = "quickstart"
index_client = SearchIndexClient(
endpoint=service_endpoint,
credential=cognitive_search_credential,
)
vector_store_params = {
"vector_store_type": "CognitiveSearchVectorStore",
"search_or_index_client": index_client),
"index_name":index_name,
}LLM Integration
For integrating OpenAI's language model (LLM) with AI-Horizon, follow these steps:
- Define the parameters for LLM integration:
llm_params = {
"model": "gpt-4-0125-preview",
"api_key": "sk-",
"temperature": 0,
"top_p": 0,
}AI-Horizon + Azure OpenAI Integration
To integrate Azure's OpenAI model with AI-Horizon, follow these steps:
- Define the parameters for Azure OpenAI integration:
llm_params = {
"model": "azure/gpt-35-turbo-16k",
"api_base": "https://<deployment_namer>.azure.com/",
"api_version": "2024-02-15-preview",
"api_key": "<YOUR-API-KEY>",
"max_retries": 1
}B. Usage
Installation
You can install our package simply by running:
pip install <<package name>>C. Data Sources
a) Overview
- Add PDF
- Add Docx
- Add Text
- Add YouTube
- Add Webpage
- Add Website
b) Data Types
i. PDF
Incorporating PDF Content into Your Chat Agent
Enhancing your chat agent with PDF content broadens its conversational abilities, tapping into the wealth of information housed within PDF documents. This feature is pivotal for crafting a chat agent capable of furnishing precise, detailed responses sourced from diverse documents. The pdf_chat method streamlines the task of rendering PDF content searchable and available to your chat agent.
Overview of Function
Tailored for integrating PDF content into your chat agent, the pdf_chat function employs diverse parameters to enhance the processing and utilization of this content throughout conversations.
Parameters
input_dir(Optional[str]): The directory containing PDF files to be added. If specified, the function scans this directory for PDF files.input_files(Optional[List]): A list of specific PDF file paths to be added. If provided,input_diris ignored.exclude_hidden(bool): When set to True, hidden files or files starting with a dot (.) ininput_dirare excluded.filename_as_id(bool): Uses the filename as the unique identifier for each PDF document if set to True.recursive(bool): If True, includes files from subdirectories withininput_dir.required_exts(Optional[List[str]]): Specifies file extensions to include, with the default targeting PDF files.system_prompt(str): An optional prompt to guide the system in processing PDF content.query_wrapper_prompt(str): An optional prompt to enhance query relevance by wrapping user queries in a specific context.embed_model(Union[str, EmbedType]): The embedding model used for text extraction and embedding from PDF documents. Defaults to a predefined model.llm_params(dict): Parameters for integrating Large Language Models to augment content understanding and query processing.vector_store_params(dict): Configuration for vector storage, specifying how and where the extracted content embeddings are stored.service_context_params(dict): Additional parameters for customizing the service context for PDF content.chat_engine_params(dict): Customization parameters for the chat engine, influencing how the chat agent utilizes the PDF content during conversations.retriever_params(dict): Configuration for the document retriever component, determining how PDF content is indexed and retrieved based on user queries.
Example Usage
Adding PDF Files from a Directory
chat_agent.pdf_chat(
input_dir="/path/to/your_pdf/documents",
recursive=True
)Adding Specific PDF Files
chat_agent.pdf_chat(
input_files=["/path/to/your_specific/document1.pdf", "/path/to/your_specific/document2.pdf"],
)ii. Docx File
Integration of DOCX Content into Your Chat Agent
Incorporating DOCX files into your chat agent enhances its conversational capabilities by accessing the vast information stored in this commonly used document format. The docx_chat method streamlines the process of adding DOCX content, empowering your chat agent to utilize the detailed information from these files for more precise and informed interactions.
Overview of Function
The docx_chat function is precisely designed to ingest DOCX content into your chat agent, employing various parameters to regulate how this content is handled, organized, and employed during conversations.
Parameters
- input_dir (Optional[str]): Directory path containing DOCX files to be added. If specified, the function scans this directory for eligible DOCX files.
- input_files (Optional[List]): A list of specific DOCX file paths to be added. This parameter takes precedence over
input_dirif provided. - exclude_hidden (bool): If True, hidden files or files starting with a dot (.) in
input_dirare excluded from processing. - filename_as_id (bool): Uses the filename as the unique identifier for each DOCX document if set to True.
- recursive (bool): If True, includes files from subdirectories within
input_dir. - required_exts (Optional[List[str]]): Specifies file extensions to include, typically set to [".docx"] to target DOCX files.
- system_prompt (str): An optional prompt guiding the system in processing DOCX content.
- query_wrapper_prompt (str): An optional prompt to enhance the relevance of user queries by providing specific context related to the DOCX content.
- embed_model (Union[str, EmbedType]): The embedding model used for text extraction and embedding from DOCX documents. Defaults to a standard model optimized for document content.
- llm_params (dict): Parameters for integrating Large Language Models to enhance content understanding and query processing.
- vector_store_params (dict): Configuration for vector storage, detailing how and where the content embeddings are stored.
- service_context_params (dict): Additional parameters to customize the service context for DOCX content.
- chat_engine_params (dict): Customization parameters for the chat engine, influencing how the chat agent utilizes the DOCX content in conversations.
- retriever_params (dict): Configuration for the document retriever component, determining how DOCX content is indexed and retrieved in response to user queries.
Example Usage
Adding DOCX Files from a Directory
chat_agent.docx_chat(
input_dir="/path/to/your_docx/documents",
recursive=True
)
This code snippet adds DOCX documents from the specified directory (and its subdirectories, if `recursive` is set to `True`) to the chat agent’s database.
#### Adding Specific DOCX Files
```python
chat_agent.docx_chat(
input_files=["/path/to/your/document1.docx", "/path/to/your/document2.docx"],
)Here, specific DOCX files are directly added to the chat agent, enabling it to draw upon their content in conversation.
iii. Text
Integrate Text File Content into Your Chat Agent
Expanding your chat agent's capabilities by integrating plain text (.txt) files broadens its repository of knowledge, allowing it to leverage a wide array of textual content. The txt_chat method simplifies the process of incorporating text files into your chat agent, ensuring that this abundance of information is readily available to enhance the quality and relevance of conversations.
Overview of Function
The txt_chat function is crafted to intake content from text files into your chat agent, utilizing various parameters to guarantee that this process is both efficient and productive.
Parameters
input_dir(Optional[str]): Directory path containing text files to be added. If specified, the function will search this directory for eligible files.input_files(Optional[List]): A list of paths to specific text files to be added. When provided,input_diris bypassed.exclude_hidden(bool): If True, hidden files or those starting with a dot (.) withininput_dirare excluded.filename_as_id(bool): If True, the filename is used as the unique identifier for each text document.recursive(bool): If True, the function will also search subdirectories withininput_dirfor text files.required_exts(Optional[List[str]]): Specifies the file extensions to include. Defaults to text file extensions.system_prompt(str): An optional prompt to guide the system in processing text file content.query_wrapper_prompt(str): An optional prompt that can improve the relevance of search queries by providing context related to the text content.embed_model(Union[str, EmbedType]): The embedding model used for extracting and embedding text from the files. Defaults to a general-purpose model.llm_params(dict): Configuration parameters for integrating Large Language Models to enhance content comprehension and query processing.vector_store_params(dict): Configuration for vector storage, specifying how and where extracted content embeddings are stored.service_context_params(dict): Additional parameters to customize the service context for the text file content.chat_engine_params(dict): Customization parameters for the chat engine, influencing how the chat agent utilizes text file content in conversations.retriever_params(dict): Configuration for the document retriever component, determining how text file content is indexed and retrieved in response to user queries.
Example Usage
Adding Text Files from a Directory
chat_agent.txt_chat(
input_dir="/path/to/your_text/files",
recursive=True
)This snippet configures the chat agent to ingest text files from the specified directory and its subdirectories.
Adding Specific Text Files
chat_agent.txt_chat({
input_files: ["/path/to/your/file1.txt", "/path/to/your/file2.txt"],
})Here, specific text files are directly added to the chat agent, allowing it to leverage their content in conversations.
YouTube Video Integration
Integrate YouTube video content into your chat agent to broaden its abilities and captivate users with dynamic, multimedia-rich information. The youtube_chat method streamlines the integration of YouTube video content, allowing your chat agent to reference or cite video content in its responses.
Overview of Function
The youtube_chat function is specially crafted to intake content from YouTube videos into your chat agent. This integration not only diversifies the agent’s data pool but also empowers it to reference or cite video content in its responses.
Parameters
- urls (
List[str]): A list of YouTube video URLs that you wish to integrate into the chat agent. Each URL should point to a specific video from which content will be extracted. - system_prompt (
str, optional): An optional prompt guiding the system on how to process and integrate content from the YouTube videos. This can be particularly useful for emphasizing certain types of information within the videos. - query_wrapper_prompt (
str, optional): An optional prompt designed to enhance the relevance of user queries by providing a context specific to the YouTube content. - embed_model (
Union[str, EmbedType], optional): The embedding model used for processing and embedding textual content extracted from the videos. Defaults to a model suitable for video content analysis. - llm_params (
dict, optional): Configuration parameters for integrating Large Language Models, enhancing the agent’s understanding and interpretation of video content. - vector_store_params (
dict, optional): Configuration for vector storage, specifying how and where the extracted content embeddings are stored. - service_context_params (
dict, optional): Additional parameters to customize the service context specific to YouTube video content. - chat_engine_params (
dict, optional): Customization parameters for the chat engine, affecting how the agent utilizes YouTube content in conversations. - retriever_params (
dict, optional): Configuration for the document retriever component, determining how YouTube content is indexed and retrieved based on user queries.
Example Usage
Adding Multiple YouTube Videos
To add multiple YouTube videos to your chat agent, you can use the youtube_chat method and provide a list of YouTube video URLs.
chat_agent.youtube_chat({
urls: [
"https://www.youtube.com/watch?v=example1",
"https://www.youtube.com/watch?v=example2"
]
})Integrate Webpage Content into Your Chat Agent
Integrating content from particular web pages can greatly improve your chat agent's capacity to offer informative and contextually appropriate responses. Through the webpage_chat technique, you can seamlessly incorporate webpage content, thereby enriching the agent's knowledge base with current information accessible on the internet.
Overview of Function
The webpage_chat feature is designed to streamline the effortless inclusion of content from a single webpage into your chat agent, employing various parameters for efficient content processing and integration.
Parameters
- url (
Optional[str]): The URL of the webpage whose content you wish to make searchable by the chat agent. This specifies the exact source of the content to be integrated. - system_prompt (
str): An optional prompt to guide the system in processing the webpage content. It can be used to focus the content extraction on relevant information for the chat agent. - query_wrapper_prompt (
str): An optional prompt that can enhance the relevance of search queries by providing context related to the webpage content. - embed_model (
Union[str, EmbedType]): Specifies the embedding model used for text extraction and embedding from the webpage. Defaults to a model suitable for general web content. - llm_params (
dict): Configuration parameters for integrating Large Language Models to augment the agent’s understanding of the webpage content. - vector_store_params (
dict): Configuration for vector storage, detailing how and where the extracted content embeddings are stored. - service_context_params (
dict): Additional parameters to customize the service context for the integrated webpage content. - chat_engine_params (
dict): Customization parameters for the chat engine, influencing how the agent utilizes the webpage content in conversations. - retriever_params (
dict): Configuration for the document retriever component, determining how the webpage content is indexed and retrieved based on user queries.
Example Usage
To demonstrate adding content from a specific webpage to the chat agent, you can use the following example:
chat_agent.webpage_chat({
url: "https://www.example.com/specific-article",
})Integrate Entire Website Content into Your Chat Agent
Enabling your chat agent to seamlessly incorporate content from an entire website substantially boosts its knowledge reservoir and conversational prowess. The website_chat function is tailored precisely for this objective, facilitating the thorough integration of website information, thus amplifying the agent's capacity to furnish precise and detailed responses.
Overview of Function
The website_chat function empowers the incorporation of a website's complete content into the chat agent, employing a set of parameters to refine content processing and guarantee seamless integration.
Parameters
- url (
Optional[str]): The base URL of the website you want to integrate. This should point to the homepage or a major section of the site whose content you wish to make searchable. - system_prompt (
str): An optional prompt to guide the system’s approach to processing the website’s content. This can be useful for focusing on particular types of information. - query_wrapper_prompt (
str): An optional prompt that can improve the relevance of user queries by providing a context specific to the website’s content. - embed_model (
Union[str, EmbedType]): Specifies the embedding model used for extracting and embedding text from the website. Defaults to a model optimized for general web content. - llm_params (
dict): Configuration parameters for integrating Large Language Models, enhancing the chat agent’s comprehension of the website content. - vector_store_params (
dict): Configuration for vector storage, outlining how and where the extracted content embeddings are stored. - service_context_params (
dict): Additional parameters for customizing the service context for the integrated website content. - chat_engine_params (
dict): Customization parameters for the chat engine, affecting how the agent utilizes the website content in conversations. - retriever_params (
dict): Configuration for the document retriever component, determining how the website content is indexed and retrieved based on user queries.
Example Usage
To demonstrate adding the content from an entire website to the chat agent, you can use the following example:
chat_agent.website_chat({
url: "https://www.sample.com",
})