Skip to content

Commit 9cbfca2

Browse files
perf: Semantic Kernel and Prompt improvement (#415)
* Semantic Kernel and Prompt improvement * update dependencies and Azure OpenAI model configurations * fix: upgrade pip and setuptools before installing requirements * update SQL query placeholder from %s to ? for compatibility * update Azure OpenAI gpt4omini deployment type to globalstandard --------- Co-authored-by: Harsh-Microsoft <v-hbangera@microsoft.com>
1 parent 14c770f commit 9cbfca2

File tree

8 files changed

+329
-268
lines changed

8 files changed

+329
-268
lines changed

ClientAdvisor/App/WebApp.Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ RUN apk add --no-cache --virtual .build-deps \
2626
&& rm msodbcsql18_18.4.1.1-1_amd64.apk
2727

2828
COPY ./ClientAdvisor/App/requirements.txt /usr/src/app/
29-
RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt \
29+
30+
RUN pip install --upgrade pip setuptools wheel \
31+
&& pip install --no-cache-dir -r /usr/src/app/requirements.txt \
3032
&& rm -rf /root/.cache
3133

3234
COPY ./ClientAdvisor/App/ /usr/src/app/

ClientAdvisor/AzureFunction/function_app.py

Lines changed: 234 additions & 182 deletions
Large diffs are not rendered by default.

ClientAdvisor/AzureFunction/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
azure-functions
66
azurefunctions-extensions-http-fastapi==1.0.0b1
7-
openai==1.63.0
8-
semantic_kernel==1.0.4
7+
openai==1.64.0
8+
semantic_kernel==1.21.3
99
pymssql==2.3.2
1010
azure-search-documents==11.6.0b9
1111

ClientAdvisor/Deployment/bicep/deploy_app_service.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ param AzureOpenAIResource string
6767
param AzureOpenAIModel string
6868

6969
@description('Azure OpenAI Model Name')
70-
param AzureOpenAIModelName string = 'gpt-4'
70+
param AzureOpenAIModelName string = 'gpt-4o-mini'
7171

7272
@description('Azure Open AI Endpoint')
7373
param AzureOpenAIEndpoint string = ''

ClientAdvisor/Deployment/bicep/deploy_azure_function.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ param userassignedIdentityId string
2525
param userassignedIdentityClientId string
2626

2727
var functionAppName = '${solutionName}fn'
28-
var azureOpenAIDeploymentModel = 'gpt-4'
28+
var azureOpenAIDeploymentModel = 'gpt-4o-mini'
2929
var azureOpenAIEmbeddingDeployment = 'text-embedding-ada-002'
3030
var valueOne = '1'
3131

ClientAdvisor/Deployment/bicep/deploy_azure_open_ai.bicep

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ resource accounts_byc_openai_name_resource 'Microsoft.CognitiveServices/accounts
4545

4646
resource accounts_byc_openai_name_gpt_4 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
4747
parent: accounts_byc_openai_name_resource
48-
name: 'gpt-4'
48+
name: 'gpt-4o-mini'
4949
sku: {
50-
name: 'Standard'
51-
capacity: 10
50+
name: 'GlobalStandard'
51+
capacity: 45
5252
}
5353
properties: {
5454
model: {
5555
format: 'OpenAI'
56-
name: 'gpt-4'
57-
version: '0125-Preview'
56+
name: 'gpt-4o-mini'
57+
version: '2024-07-18'
5858
}
5959
versionUpgradeOption: 'OnceCurrentVersionExpired'
6060
raiPolicyName: 'Microsoft.Default'

ClientAdvisor/Deployment/bicep/main.bicep

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,53 @@ param cosmosLocation string
1212
// @description('Fabric Workspace Id if you have one, else leave it empty. ')
1313
// param fabricWorkspaceId string
1414

15+
//restricting to these regions because assistants api for gpt-4o-mini is available only in these regions
16+
// @allowed(['eastus', 'eastus2', 'westus', 'westus3', 'swedencentral'])
17+
// @description('Azure OpenAI Location')
18+
// param AzureOpenAILocation string
19+
1520
var resourceGroupLocation = resourceGroup().location
1621
// var subscriptionId = subscription().subscriptionId
1722

1823
var solutionLocation = resourceGroupLocation
1924
var baseUrl = 'https://raw.githubusercontent.com/microsoft/Build-your-own-copilot-Solution-Accelerator/main/ClientAdvisor/'
2025
var appversion = 'latest'
2126

22-
var functionAppSqlPrompt = '''A valid T-SQL query to find {query} for tables and columns provided below:
23-
1. Table: Clients
24-
Columns: ClientId,Client,Email,Occupation,MaritalStatus,Dependents
25-
2. Table: InvestmentGoals
26-
Columns: ClientId,InvestmentGoal
27-
3. Table: Assets
28-
Columns: ClientId,AssetDate,Investment,ROI,Revenue,AssetType
29-
4. Table: ClientSummaries
30-
Columns: ClientId,ClientSummary
31-
5. Table: InvestmentGoalsDetails
32-
Columns: ClientId,InvestmentGoal,TargetAmount,Contribution
33-
6. Table: Retirement
34-
Columns: ClientId,StatusDate,RetirementGoalProgress,EducationGoalProgress
35-
7.Table: ClientMeetings
36-
Columns: ClientId,ConversationId,Title,StartTime,EndTime,Advisor,ClientEmail
37-
Use Investement column from Assets table as value always.
38-
Assets table has snapshots of values by date. Do not add numbers across different dates for total values.
39-
Do not use client name in filter.
40-
Do not include assets values unless asked for.
41-
Always use ClientId = {clientid} in the query filter.
42-
Always return client name in the query.
43-
Only return the generated sql query. do not return anything else'''
44-
45-
var functionAppCallTranscriptSystemPrompt = '''You are an assistant who provides wealth advisors with helpful information to prepare for client meetings.
46-
You have access to the client’s meeting call transcripts.
47-
You can use this information to answer questions about the clients'''
27+
var functionAppSqlPrompt ='''Generate a valid T-SQL query to find {query} for tables and columns provided below:
28+
1. Table: Clients
29+
Columns: ClientId, Client, Email, Occupation, MaritalStatus, Dependents
30+
2. Table: InvestmentGoals
31+
Columns: ClientId, InvestmentGoal
32+
3. Table: Assets
33+
Columns: ClientId, AssetDate, Investment, ROI, Revenue, AssetType
34+
4. Table: ClientSummaries
35+
Columns: ClientId, ClientSummary
36+
5. Table: InvestmentGoalsDetails
37+
Columns: ClientId, InvestmentGoal, TargetAmount, Contribution
38+
6. Table: Retirement
39+
Columns: ClientId, StatusDate, RetirementGoalProgress, EducationGoalProgress
40+
7. Table: ClientMeetings
41+
Columns: ClientId, ConversationId, Title, StartTime, EndTime, Advisor, ClientEmail
42+
Always use the Investment column from the Assets table as the value.
43+
Assets table has snapshots of values by date. Do not add numbers across different dates for total values.
44+
Do not use client name in filters.
45+
Do not include assets values unless asked for.
46+
ALWAYS use ClientId = {clientid} in the query filter.
47+
ALWAYS select Client Name (Column: Client) in the query.
48+
Query filters are IMPORTANT. Add filters like AssetType, AssetDate, etc. if needed.
49+
If the result might return more than 100 rows, include TOP 100 to limit the row count.
50+
Only return the generated SQL query. Do not return anything else.'''
51+
52+
var functionAppCallTranscriptSystemPrompt = '''You are an assistant who supports wealth advisors in preparing for client meetings.
53+
You have access to the client’s past meeting call transcripts.
54+
When answering questions, especially summary requests, provide a detailed and structured response that includes key topics, concerns, decisions, and trends.
55+
If no data is available, state 'No relevant data found for previous meetings.'''
4856

49-
var functionAppStreamTextSystemPrompt = '''You are a helpful assistant to a wealth advisor.
50-
Do not answer any questions not related to wealth advisors queries.
51-
If the client name and client id do not match, only return - Please only ask questions about the selected client or select another client to inquire about their details. do not return any other information.
52-
Only use the client name returned from database in the response.
53-
If you cannot answer the question, always return - I cannot answer this question from the data available. Please rephrase or add more details.
54-
** Remove any client identifiers or ids or numbers or ClientId in the final response.'''
57+
var functionAppStreamTextSystemPrompt = '''You are a helpful assistant to a Wealth Advisor.
58+
The currently selected client's name is '{SelectedClientName}' (in any variation: ignoring punctuation, apostrophes, and case).
59+
If the user mentions no name, assume they are asking about '{SelectedClientName}'.
60+
If the user references a name that clearly differs from '{SelectedClientName}', respond only with: 'Please only ask questions about the selected client or select another client.' Otherwise, provide thorough answers for every question using only data from SQL or call transcripts.
61+
If no data is found, respond with 'No data found for that client.' Remove any client identifiers from the final response.'''
5562

5663
// ========== Managed Identity ========== //
5764
module managedIdentityModule 'deploy_managed_identity.bicep' = {
@@ -262,9 +269,9 @@ module appserviceModule 'deploy_app_service.bicep' = {
262269
AzureSearchUrlColumn:'sourceurl'
263270
AzureOpenAIResource:azOpenAI.outputs.openAIOutput.openAPIEndpoint
264271
AzureOpenAIEndpoint:azOpenAI.outputs.openAIOutput.openAPIEndpoint
265-
AzureOpenAIModel:'gpt-4'
272+
AzureOpenAIModel:'gpt-4o-mini'
266273
AzureOpenAIKey:azOpenAI.outputs.openAIOutput.openAPIKey
267-
AzureOpenAIModelName:'gpt-4'
274+
AzureOpenAIModelName:'gpt-4o-mini'
268275
AzureOpenAITemperature:'0'
269276
AzureOpenAITopP:'1'
270277
AzureOpenAIMaxTokens:'1000'

0 commit comments

Comments
 (0)