From 043a39187bb1f030795a08090217e55b7a4967dc Mon Sep 17 00:00:00 2001 From: Somesh Joshi Date: Mon, 28 Oct 2024 15:57:43 +0530 Subject: [PATCH 1/4] update prompt --- ClientAdvisor/AzureFunction/function_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ClientAdvisor/AzureFunction/function_app.py b/ClientAdvisor/AzureFunction/function_app.py index 9f6368cd..bc1292f0 100644 --- a/ClientAdvisor/AzureFunction/function_app.py +++ b/ClientAdvisor/AzureFunction/function_app.py @@ -277,7 +277,7 @@ async def stream_openai_text(req: Request) -> StreamingResponse: system_message = '''you are a helpful assistant to a wealth advisor. Do not answer any questions not related to wealth advisors queries. - **If the client name in the question does not match the selected client's name**, always return: "Please ask questions only about the selected client." Do not provide any other information. + **If the client name in the question does not match the selected client's name or client name and client id do not match**, always return: "Please ask questions only about the selected client." Do not provide any other information. Always consider to give selected client full name only in response and do not use other example names also consider my client means currently selected client. If you cannot answer the question, always return - I cannot answer this question from the data available. Please rephrase or add more details. ** Remove any client identifiers or ids or numbers or ClientId in the final response. From 828e11994b2e6fb093106122c1ce6f51a873b867 Mon Sep 17 00:00:00 2001 From: Somesh Joshi Date: Tue, 29 Oct 2024 19:44:28 +0530 Subject: [PATCH 2/4] "Updated AzureOpenAI API version, removed client investment risk tolerance query, and modified system messages and query prompts in ChatWithDataPlugin." --- ClientAdvisor/AzureFunction/function_app.py | 38 +++++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/ClientAdvisor/AzureFunction/function_app.py b/ClientAdvisor/AzureFunction/function_app.py index bc1292f0..abf42780 100644 --- a/ClientAdvisor/AzureFunction/function_app.py +++ b/ClientAdvisor/AzureFunction/function_app.py @@ -20,6 +20,8 @@ import pymssql # Azure Function App app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS) +from dotenv import load_dotenv +load_dotenv() endpoint = os.environ.get("AZURE_OPEN_AI_ENDPOINT") api_key = os.environ.get("AZURE_OPEN_AI_API_KEY") @@ -33,13 +35,14 @@ class ChatWithDataPlugin: @kernel_function(name="Greeting", description="Respond to any greeting or general questions") def greeting(self, input: Annotated[str, "the question"]) -> Annotated[str, "The output is a string"]: + query = input.split(':::')[0] endpoint = os.environ.get("AZURE_OPEN_AI_ENDPOINT") api_key = os.environ.get("AZURE_OPEN_AI_API_KEY") client = openai.AzureOpenAI( azure_endpoint=endpoint, api_key=api_key, - api_version=api_version + api_version="2023-09-01-preview" ) deployment = os.environ.get("AZURE_OPEN_AI_DEPLOYMENT_MODEL") try: @@ -71,10 +74,11 @@ def get_SQL_Response( endpoint = os.environ.get("AZURE_OPEN_AI_ENDPOINT") api_key = os.environ.get("AZURE_OPEN_AI_API_KEY") + client = openai.AzureOpenAI( azure_endpoint=endpoint, api_key=api_key, - api_version=api_version + api_version="2023-09-01-preview" ) deployment = os.environ.get("AZURE_OPEN_AI_DEPLOYMENT_MODEL") @@ -102,7 +106,6 @@ def get_SQL_Response( If a question involves date and time, always use FORMAT(YourDateTimeColumn, 'yyyy-MM-dd HH:mm:ss') in the query. If asked, provide information about client meetings according to the requested timeframe: give details about upcoming meetings if asked for "next" or "upcoming" meetings, and provide details about past meetings if asked for "previous" or "last" meetings including the scheduled time and don't filter with "LIMIT 1" in the query. If asked about the number of past meetings with this client, provide the count of records where the ConversationId is neither null nor an empty string and the EndTime is before the current date in the query. - If asked, provide information on the client's investment risk tolerance level in the query. If asked, provide information on the client's portfolio performance in the query. If asked, provide information about the client's top-performing investments in the query. If asked, provide information about any recent changes in the client's investment allocations in the query. @@ -162,16 +165,18 @@ def get_answers_from_calltranscripts( client = openai.AzureOpenAI( azure_endpoint= endpoint, #f"{endpoint}/openai/deployments/{deployment}/extensions", api_key=apikey, - api_version=api_version + api_version="2024-02-01" ) query = question - system_message = '''You are an assistant who provides wealth advisors with helpful information to prepare for client meetings and provide details on the call transcripts. - You have access to the client’s meetings and call transcripts - When asked about action items from previous meetings with the client, **ALWAYS provide information only for the most recent dates**. - Always return time in "HH:mm" format for the client in response. + + system_message = '''You are an assistant who provides wealth advisors with helpful information to prepare for client meetings. + You have access to the client’s meeting call transcripts. If requested for call transcript(s), the response for each transcript should be summarized separately and Ensure all transcripts for the specified client are retrieved and format **must** follow as First Call Summary,Second Call Summary etc. - Your answer must **not** include any client identifiers or ids or numbers or ClientId in the final response.''' + First name and Full name of the client mentioned in prompt should give same response for both. + You can use this information to answer questions about the clients + when asked about action items from previous meetings with the client, ** Always provide information only for most recent dates** + ''' completion = client.chat.completions.create( model = deployment, @@ -257,6 +262,7 @@ async def stream_openai_text(req: Request) -> StreamingResponse: deployment_name=deployment ) + kernel.add_service(ai_service) kernel.add_plugin(ChatWithDataPlugin(), plugin_name="ChatWithData") @@ -274,23 +280,25 @@ async def stream_openai_text(req: Request) -> StreamingResponse: # Read the HTML file with open("table.html", "r") as file: html_content = file.read() - - system_message = '''you are a helpful assistant to a wealth advisor. + + system_message = '''you are a wealth advisor assistant. Do not answer any questions not related to wealth advisors queries. - **If the client name in the question does not match the selected client's name or client name and client id do not match**, always return: "Please ask questions only about the selected client." Do not provide any other information. + + **If the normalized client name in the question does not match the normalized selected client name or client name and client id do not match**, always return: "Please ask questions only about the selected client." Do not provide any other information. Always consider to give selected client full name only in response and do not use other example names also consider my client means currently selected client. If you cannot answer the question, always return - I cannot answer this question from the data available. Please rephrase or add more details. ** Remove any client identifiers or ids or numbers or ClientId in the final response. Client name **must be** same as retrieved from database. + Always return time in "HH:mm" format for the client in response. + If asked, response should **always be** consistent everytime. ''' system_message += html_content - user_query = query.replace('?',' ') + user_query = query.replace('?','') user_query_prompt = f'''{user_query}. Always send clientId as {user_query.split(':::')[-1]} ''' query_prompt = f'''{system_message}{user_query_prompt}''' - sk_response = kernel.invoke_prompt_stream( function_name="prompt_test", plugin_name="weather_test", @@ -298,4 +306,4 @@ async def stream_openai_text(req: Request) -> StreamingResponse: settings=settings ) - return StreamingResponse(stream_processor(sk_response), media_type="text/event-stream") + return StreamingResponse(stream_processor(sk_response), media_type="text/event-stream") \ No newline at end of file From 95706d4c24437d026a8a3f52f8a89bd93ef50747 Mon Sep 17 00:00:00 2001 From: Somesh Joshi Date: Tue, 5 Nov 2024 16:51:40 +0530 Subject: [PATCH 3/4] update transcript prompt --- ClientAdvisor/AzureFunction/function_app.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ClientAdvisor/AzureFunction/function_app.py b/ClientAdvisor/AzureFunction/function_app.py index abf42780..43d80e73 100644 --- a/ClientAdvisor/AzureFunction/function_app.py +++ b/ClientAdvisor/AzureFunction/function_app.py @@ -20,8 +20,6 @@ import pymssql # Azure Function App app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS) -from dotenv import load_dotenv -load_dotenv() endpoint = os.environ.get("AZURE_OPEN_AI_ENDPOINT") api_key = os.environ.get("AZURE_OPEN_AI_API_KEY") @@ -175,7 +173,8 @@ def get_answers_from_calltranscripts( If requested for call transcript(s), the response for each transcript should be summarized separately and Ensure all transcripts for the specified client are retrieved and format **must** follow as First Call Summary,Second Call Summary etc. First name and Full name of the client mentioned in prompt should give same response for both. You can use this information to answer questions about the clients - when asked about action items from previous meetings with the client, ** Always provide information only for most recent dates** + when asked about action items from previous meetings with the client, ** Always provide information only for most recent dates** + **If the normalized client name in the question does not match the normalized selected client name or client name and client id do not match**, always return: "Please ask questions only about the selected client." Do not provide any other information. ''' completion = client.chat.completions.create( @@ -283,7 +282,6 @@ async def stream_openai_text(req: Request) -> StreamingResponse: system_message = '''you are a wealth advisor assistant. Do not answer any questions not related to wealth advisors queries. - **If the normalized client name in the question does not match the normalized selected client name or client name and client id do not match**, always return: "Please ask questions only about the selected client." Do not provide any other information. Always consider to give selected client full name only in response and do not use other example names also consider my client means currently selected client. If you cannot answer the question, always return - I cannot answer this question from the data available. Please rephrase or add more details. From 7250e3dba05bea86e2076a008085097f1abbe4f8 Mon Sep 17 00:00:00 2001 From: Somesh Joshi Date: Wed, 6 Nov 2024 14:07:21 +0530 Subject: [PATCH 4/4] Update the code as per PR raise --- ClientAdvisor/AzureFunction/function_app.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ClientAdvisor/AzureFunction/function_app.py b/ClientAdvisor/AzureFunction/function_app.py index 59a3a24c..e61e0a13 100644 --- a/ClientAdvisor/AzureFunction/function_app.py +++ b/ClientAdvisor/AzureFunction/function_app.py @@ -174,8 +174,6 @@ def get_answers_from_calltranscripts( If requested for call transcript(s), the response for each transcript should be summarized separately and Ensure all transcripts for the specified client are retrieved and format **must** follow as First Call Summary,Second Call Summary etc. First name and Full name of the client mentioned in prompt should give same response for both. You can use this information to answer questions about the clients - when asked about action items from previous meetings with the client, ** Always provide information only for most recent dates** - **If the normalized client name in the question does not match the normalized selected client name or client name and client id do not match**, always return: "Please ask questions only about the selected client." Do not provide any other information. ''' completion = client.chat.completions.create( @@ -279,9 +277,9 @@ async def stream_openai_text(req: Request) -> StreamingResponse: # Read the HTML file with open("table.html", "r") as file: - html_content = file.read() - - system_message = '''you are a wealth advisor assistant. + html_content = file.read() + + system_message = '''you are a helpful assistant to a wealth advisor. Do not answer any questions not related to wealth advisors queries. **If the normalized client name in the question does not match the normalized selected client name or client name and client id do not match**, always return: "Please ask questions only about the selected client." Do not provide any other information. Always consider to give selected client full name only in response and do not use other example names also consider my client means currently selected client.