Financial Advisor Demo
WorqHat AI Financial Advisor: Documentation
This documentation provides an overview of the WorqHat AI Financial Advisor, a Streamlit-based conversational app designed to interact with users through chat and file uploads. Leveraging the WorqHat AI API, this app is specifically tailored to assist with financial-related queries, simulating responses from an expert financial analyst named "Alex." The tool allows users to upload files and engage in conversations with the AI to receive insightful, data-driven answers.
Purpose:
The WorqHat AI Financial Advisor enables users to get instant responses to financial questions by either uploading relevant documents or engaging in a direct conversation with the AI. This is especially useful for financial professionals, investors, or anyone looking for expert insights based on provided financial data.
Key Features:
- File Upload: Upload multiple files (PDF, PNG, JPG) related to financial data or any other context that might aid in answering your query.
- Conversational Chat Interface: Users can ask questions through the chat interface and receive expert responses from "Alex," the AI-powered financial advisor.
- AI-Powered Responses: The WorqHat AI API processes uploaded files (if provided) and user queries to deliver relevant and insightful answers based on the expertise of the financial analyst model.
- Session-Based Conversations: Each conversation is assigned a unique
conversation_id
, ensuring a seamless flow of chat and context retention throughout the session. - First Message File Processing: The first user interaction may include the upload of documents to provide context, which the AI will analyze for a more informed response.
Benefits:
- Enhanced Financial Insights: Whether you're analyzing market trends or looking for expert financial advice, the AI-powered financial analyst provides data-backed answers, improving decision-making.
- Quick and Easy Setup: With a simple API key input, you can start asking financial questions right away. Uploading documents further improves the AI's understanding and response quality.
- Customizable and Scalable: While this application is set up for financial analysis, the core logic can easily be adapted for various other domains by adjusting the AI's training data.
- Efficient Conversations: The AI retains context across the conversation, allowing for deeper interactions and better responses over time.
How it Works:
API Key Input: Users must first enter their WorqHat API key into the sidebar input field to activate the app.
Unique Conversation ID: Each session is assigned a unique
conversation_id
to track the chat history and provide context-based responses.File Upload (Optional): Users can upload multiple files (PDF, PNG, JPG) via the sidebar. If uploaded, these files will be used by the AI to help process and respond to the initial query.
Chat Interface: Users can input questions in the chat box. If files are uploaded with the first question, the AI will analyze the documents alongside the query. Future interactions will be based solely on chat inputs.
AI-Powered Responses: The AI (trained as "Alex," a financial expert) responds to user queries based on the provided files and the content of the conversation. All chat messages are stored and displayed for reference.
Session Continuity: Each conversation is retained in the session state, so users can review previous interactions with the AI.
Procedure to Follow:
Enter API Key: Obtain and enter your WorqHat API key via the sidebar input field. The app will not function without a valid API key. If you do not have an API Key please visit our website WorqHat to get your own API Key.
Upload Files (Optional): If you have financial documents or images that can assist the AI in responding to your question, upload them in the sidebar before asking your first question.
Start the Conversation: Ask a question in the chat input. If you uploaded files, the AI will analyze them and respond accordingly.
Continue the Chat: Keep asking follow-up questions, and the AI will respond with context-aware answers.
Review Responses: The chat history is displayed for easy reference throughout the session.
Code Explanation:
The core functionality of this app revolves around sending files and questions to the WorqHat AI API for processing. Here's a breakdown of the primary function:
def send_files_and_question(files, question, training_data, first_message):
url = 'https://api.worqhat.com/api/ai/content/v4'
headers = {'Authorization': f'Bearer {api_key}'}
data = {
'question': question,
'training_data': training_data,
'model': 'aicon-v4-nano-160824',
'conversation_id': st.session_state.conversation_id
}
if first_message:
files_to_send = [('files', (file.name, file, file.type)) for file in files]
response = requests.post(url, headers=headers, files=files_to_send, data=data)
else:
headers['Content-Type'] = 'application/json'
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
response_data = response.json()
content = response_data.get('content', '')
if content:
st.session_state.chat_history.append({'sender': 'Bot', 'message': content})
else:
st.error(f"Error: {response.status_code}, {response.text}")
Code Walkthrough:
API Key Input: The user provides their API key via a sidebar input field. The key is essential for authenticating with the WorqHat AI API.
File Uploads: Users can upload files (PDF, PNG, JPG) through the sidebar, which will be processed in the first message.
First Message Handling: The app processes files on the first interaction. After the initial file upload and question, future queries are text-only.
Chat Session Handling: The app stores the entire conversation in
st.session_state.chat_history
, ensuring users can view previous interactions throughout the session.Error Handling: If an error occurs during API calls, the app handles exceptions and displays appropriate error messages.
Conclusion:
The WorqHat AI Financial Advisor provides a seamless and interactive way to engage with AI for expert-level financial analysis. The ability to upload documents enhances the AI’s understanding, making it ideal for professionals and individuals seeking reliable financial advice. The straightforward integration with WorqHat API ensures that users can quickly start receiving valuable insights.
Start exploring financial insights with WorqHat AI Financial Advisor today!
Try it Yourself:
Visit: WorqHat AI Financial Advisor App
Checkout the Code:
GitHub: WorqHat AI Financial Advisor Code