Skip to content

Commit

Permalink
Merge branch 'dev' into dependabotchanges
Browse files Browse the repository at this point in the history
  • Loading branch information
Roopan-Microsoft committed Dec 27, 2024
2 parents 34e6c27 + c572154 commit 604f14a
Show file tree
Hide file tree
Showing 14 changed files with 510 additions and 230 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r ClientAdvisor/App/requirements.txt
- name: Run flake8
run: flake8 --config=ClientAdvisor/App/.flake8 ClientAdvisor/App
pip install -r ResearchAssistant/App/requirements.txt
- name: Run flake8 and pylint
run: |
flake8 --config=ClientAdvisor/App/.flake8 ClientAdvisor/App
flake8 --config=ResearchAssistant/App/.flake8 ResearchAssistant/App
5 changes: 3 additions & 2 deletions ClientAdvisor/App/.flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[flake8]
max-line-length = 88
extend-ignore = E501, E203
exclude = .venv, frontend,
extend-ignore = E501
exclude = .venv, frontend
ignore = E203, W503, G004, G200
6 changes: 3 additions & 3 deletions ClientAdvisor/App/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ httpx==0.28.0
flake8==7.1.1
black==24.8.0
autoflake==2.3.1
isort==5.13.2pytest-asyncio==0.24.0
pytest-cov==5.0.0
isort==5.13.2
isort==5.13.2
pytest-asyncio==0.24.0
pytest-cov==5.0.0
8 changes: 7 additions & 1 deletion ClientAdvisor/App/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Core requirements
azure-identity==1.15.0
# Flask[async]==2.3.2
openai==1.55.3
Expand All @@ -12,9 +13,14 @@ aiohttp==3.10.2
quart-session==3.0.0
pymssql==2.3.0
httpx==0.28.0

# Linting and formatting tools
flake8==7.1.1
black==24.8.0
autoflake==2.3.1
isort==5.13.2

# Testing tools
pytest>=8.2,<9 # Compatible version for pytest-asyncio
pytest-asyncio==0.24.0
pytest-cov==5.0.0
pytest-cov==5.0.0
73 changes: 41 additions & 32 deletions ClientAdvisor/AzureFunction/function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,33 @@ def get_SQL_Response(
)
deployment = os.environ.get("AZURE_OPEN_AI_DEPLOYMENT_MODEL")

sql_prompt = f'''A valid T-SQL query to find {query} for tables and columns provided below:
1. Table: Clients
Columns: ClientId,Client,Email,Occupation,MaritalStatus,Dependents
2. Table: InvestmentGoals
Columns: ClientId,InvestmentGoal
3. Table: Assets
Columns: ClientId,AssetDate,Investment,ROI,Revenue,AssetType
4. Table: ClientSummaries
Columns: ClientId,ClientSummary
5. Table: InvestmentGoalsDetails
Columns: ClientId,InvestmentGoal,TargetAmount,Contribution
6. Table: Retirement
Columns: ClientId,StatusDate,RetirementGoalProgress,EducationGoalProgress
7.Table: ClientMeetings
Columns: ClientId,ConversationId,Title,StartTime,EndTime,Advisor,ClientEmail
Use Investement column from Assets table as value always.
Assets table has snapshots of values by date. Do not add numbers across different dates for total values.
Do not use client name in filter.
Do not include assets values unless asked for.
Always use ClientId = {clientid} in the query filter.
Always return client name in the query.
Only return the generated sql query. do not return anything else'''
sql_prompt = os.environ.get("AZURE_SQL_SYSTEM_PROMPT")
if sql_prompt:
sql_prompt = sql_prompt.replace("{query}", query)
sql_prompt = sql_prompt.replace("{clientid}", clientid)
else:
sql_prompt = f'''A valid T-SQL query to find {query} for tables and columns provided below:
1. Table: Clients
Columns: ClientId,Client,Email,Occupation,MaritalStatus,Dependents
2. Table: InvestmentGoals
Columns: ClientId,InvestmentGoal
3. Table: Assets
Columns: ClientId,AssetDate,Investment,ROI,Revenue,AssetType
4. Table: ClientSummaries
Columns: ClientId,ClientSummary
5. Table: InvestmentGoalsDetails
Columns: ClientId,InvestmentGoal,TargetAmount,Contribution
6. Table: Retirement
Columns: ClientId,StatusDate,RetirementGoalProgress,EducationGoalProgress
7.Table: ClientMeetings
Columns: ClientId,ConversationId,Title,StartTime,EndTime,Advisor,ClientEmail
Use Investement column from Assets table as value always.
Assets table has snapshots of values by date. Do not add numbers across different dates for total values.
Do not use client name in filter.
Do not include assets values unless asked for.
Always use ClientId = {clientid} in the query filter.
Always return client name in the query.
Only return the generated sql query. do not return anything else'''
try:

completion = client.chat.completions.create(
Expand Down Expand Up @@ -156,9 +161,11 @@ def get_answers_from_calltranscripts(
)

query = question
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.
You can use this information to answer questions about the clients'''
system_message = os.environ.get("AZURE_CALL_TRANSCRIPT_SYSTEM_PROMPT")
if not system_message:
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.
You can use this information to answer questions about the clients'''

completion = client.chat.completions.create(
model = deployment,
Expand Down Expand Up @@ -259,13 +266,15 @@ async def stream_openai_text(req: Request) -> StreamingResponse:
settings.max_tokens = 800
settings.temperature = 0

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 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.
Only use the client name returned from database in the response.
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.
'''
system_message = os.environ.get("AZURE_OPENAI_STREAM_TEXT_SYSTEM_PROMPT")
if not system_message:
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 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.
Only use the client name returned from database in the response.
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.
'''

user_query = query.replace('?',' ')

Expand Down
167 changes: 167 additions & 0 deletions ClientAdvisor/Deployment/bicep/deploy_azure_function.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
@description('Specifies the location for resources.')
param solutionName string
param solutionLocation string
@secure()
param azureOpenAIApiKey string
param azureOpenAIApiVersion string
param azureOpenAIEndpoint string
@secure()
param azureSearchAdminKey string
param azureSearchServiceEndpoint string
param azureSearchIndex string
param sqlServerName string
param sqlDbName string
param sqlDbUser string
@secure()
param sqlDbPwd string
param functionAppVersion string
@description('Azure Function App SQL System Prompt')
param sqlSystemPrompt string
@description('Azure Function App CallTranscript System Prompt')
param callTranscriptSystemPrompt string
@description('Azure Function App Stream Text System Prompt')
param streamTextSystemPrompt string

var functionAppName = '${solutionName}fn'
var azureOpenAIDeploymentModel = 'gpt-4'
var azureOpenAIEmbeddingDeployment = 'text-embedding-ada-002'
var valueOne = '1'

resource storageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' = {
name: '${solutionName}fnstorage'
location: solutionLocation
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {
allowSharedKeyAccess: false
}
}

resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {
name: 'workspace-${solutionName}'
location: solutionLocation
}

resource ApplicationInsights 'Microsoft.Insights/components@2020-02-02' = {
name: functionAppName
location: solutionLocation
kind: 'web'
properties: {
Application_Type: 'web'
publicNetworkAccessForIngestion: 'Enabled'
publicNetworkAccessForQuery: 'Enabled'
WorkspaceResourceId: logAnalyticsWorkspace.id
}
}

resource containerAppEnv 'Microsoft.App/managedEnvironments@2022-06-01-preview' = {
name: '${solutionName}env'
location: solutionLocation
sku: {
name: 'Consumption'
}
properties: {
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: logAnalyticsWorkspace.properties.customerId
sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey
}
}
}
}

resource functionApp 'Microsoft.Web/sites@2024-04-01' = {
name: functionAppName
location: solutionLocation
kind: 'functionapp'
identity: {
type: 'SystemAssigned'
}
properties: {
managedEnvironmentId: containerAppEnv.id
siteConfig: {
linuxFxVersion: 'DOCKER|bycwacontainerreg.azurecr.io/byc-wa-fn:${functionAppVersion}'
appSettings: [
{
name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
value: reference(ApplicationInsights.id, '2015-05-01').InstrumentationKey
}
{
name: 'AZURE_OPEN_AI_API_KEY'
value: azureOpenAIApiKey
}
{
name: 'AZURE_OPEN_AI_DEPLOYMENT_MODEL'
value: azureOpenAIDeploymentModel
}
{
name: 'AZURE_OPEN_AI_ENDPOINT'
value: azureOpenAIEndpoint
}
{
name: 'AZURE_OPENAI_EMBEDDING_DEPLOYMENT'
value: azureOpenAIEmbeddingDeployment
}
{
name: 'OPENAI_API_VERSION'
value: azureOpenAIApiVersion
}
{
name: 'AZURE_AI_SEARCH_API_KEY'
value: azureSearchAdminKey
}
{
name: 'AZURE_AI_SEARCH_ENDPOINT'
value: azureSearchServiceEndpoint
}
{
name: 'AZURE_SEARCH_INDEX'
value: azureSearchIndex
}
{
name: 'PYTHON_ENABLE_INIT_INDEXING'
value: valueOne
}
{
name: 'PYTHON_ISOLATE_WORKER_DEPENDENCIES'
value: valueOne
}
{
name: 'SQLDB_CONNECTION_STRING'
value: 'TBD'
}
{
name: 'SQLDB_SERVER'
value: sqlServerName
}
{
name: 'SQLDB_DATABASE'
value: sqlDbName
}
{
name: 'SQLDB_USERNAME'
value: sqlDbUser
}
{
name: 'SQLDB_PASSWORD'
value: sqlDbPwd
}
{
name: 'AZURE_SQL_SYSTEM_PROMPT'
value: sqlSystemPrompt
}
{
name: 'AZURE_CALL_TRANSCRIPT_SYSTEM_PROMPT'
value: callTranscriptSystemPrompt
}
{
name: 'AZURE_OPENAI_STREAM_TEXT_SYSTEM_PROMPT'
value: streamTextSystemPrompt
}
]
}
}
}
42 changes: 0 additions & 42 deletions ClientAdvisor/Deployment/bicep/deploy_azure_function_script.bicep

This file was deleted.

Loading

0 comments on commit 604f14a

Please sign in to comment.