Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements in code and readme #123

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions scenarios/Assistants/bfsi-bot-in-a-box/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Contoso Financial Assistant caters to below types of queries:
## Installation

1. Clone the repository.
2. cd azureai-samples\scenarios\Assistants\bfsi-bot-in-a-box\src\backend
2. Install the necessary dependencies for the backend using requirements.txt
3. Create a .env file in backend folder and specify values of following variables
OPEN_AI_EMBEDDING_ENDPOINT=<your_open_ai_embedding_endpoint>
Expand All @@ -50,11 +51,22 @@ Contoso Financial Assistant caters to below types of queries:
## Usage

1. Create AI Search index for user query categorization by executing get_intent_init.py
python bfsi_config\tools\get_intent_init.py
2. Start the backend server using command flask run --host 0.0.0.0 --port 5007
3. Launch the frontend application by opening `assistant.html` file in your browser.
cd azureai-samples\scenarios\Assistants\bfsi-bot-in-a-box\src\frontend
python -m http.server 8000
Browse to http://localhost:8000/assistant.html
4. Sample conversation:
Tell me about performance of contoso financials in 2023.
Or
I purchased a Washing Machine on EMI Card.
My EMI is 1000 Rs for 12 months.
I missed my last EMI. How much do i pay now?
- Hi
- Can you tell me more about contoso?
- Can you create html table with all details?
- Super, I missed my installment for washing machine last month.
Do I need to pay interest?
- I have taken loan for 2 years. Every Month I pay 1000.
If I miss all my payments, how much will I pay finally?
- I need detailed calculation for each month showing
how you arrived at the final figure.
Can you create html table showing details for each of the 24 months?
- Please show for all months
- Thanks - this is super helpful!
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ You handle only following type of queries:
You follow below mentioned guidelines to answer user queries:
1. Responses should be concise, simple, clear and easy to understand.
2. Enable user to get answers in minimal iterations.
3. If the text response is long, organize it as list of points for better readability.
3. If the text response is long, return response as a table.
4. Do not have non ascii characters in the response.
5. If any table data is requested, present it in the form of a tabular chart image.
5. For tables, use readable fonts, left aligned text, return as html text.
6. When asked for table, do not create an image, return as html text.
-----------------------------------------------------------------------------
7. If the user thanks you, you revert with a summary, category & subcategory of the summary
8. You Identify category and sub-category using func categorize_user_query only after user thanks.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
from dotenv import load_dotenv
from azure.core.credentials import AzureKeyCredential
from azure.search.documents import SearchClient
Expand All @@ -19,6 +20,8 @@
SemanticField,
)
import json
cwd = os.path.dirname(__file__)
sys.path.append(os.path.abspath(os.path.join(cwd, '..', '..')))
from bfsi_config.tools.open_ai_response import get_embeddings

# Use this when running the code in the same directory as open_ai_response.py
Expand Down Expand Up @@ -87,7 +90,8 @@ def get_index(name: str) -> SearchIndex:


def get_intent_documents() -> list:
file_path = "get_intent_data.json"

file_path = os.path.join(cwd, "get_intent_data.json")
with Path(file_path).open("r") as file:
intent_data = json.load(file)
docs = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

tools_list = [
{"type": "code_interpreter"},

# {"type": "retrieval"},
{
"type": "function",
"function": {
"name": "search_web_with_freshness_filter",
"module": "functions.user_functions",
"description": """Generates response to the query using knowledgebase
it retrives by searching the web for information related to the input
query and filters results by freshness if specified.""",
Expand All @@ -34,18 +34,13 @@
},
},
"required": ["query"],
},
"returns": {
"type": "string",
"description": "Response to the query on the basis of web search.",
},
}
},
},
{
"type": "function",
"function": {
"name": "categorize_user_query",
"module": "functions.user_functions",
"description": "Determines and returns the Category & Subcategory for the input user query.",
"parameters": {
"type": "object",
Expand All @@ -56,11 +51,7 @@
}
},
"required": ["user_query"],
},
"returns": {
"type": "string",
"description": "String containing Category & Subcategory for the input query",
},
}
},
},
]
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,18 @@
prv_messages.push(decodedContent)
assistantResponse = decodedContent;

let tableStartIndex = assistantResponse.indexOf('<table');
let tableEndIndex = assistantResponse.indexOf('</table>') + 8; // 8 is the length of '</table>'
if (tableStartIndex !== -1 && tableEndIndex !== -1) {
assistantResponse = assistantResponse.substring(tableStartIndex, tableEndIndex);
}

var chatArea = document.getElementById('chatArea');
var assistantDiv = document.createElement('div');

assistantDiv.className = 'chat-message assistant-message';
assistantDiv.style.flexGrow = '1';
assistantDiv.textContent = assistantResponse;
assistantDiv.innerHTML = assistantResponse;

// add image called assistant_icon.png
var img = document.createElement('img');
Expand Down
Loading