Skip to content

Commit

Permalink
Merge branch 'feat/llm-few-shot' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Jan 22, 2024
2 parents 728e1c3 + 4c21ed5 commit d47649c
Show file tree
Hide file tree
Showing 27 changed files with 4,649 additions and 75 deletions.
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Extract of the data stored during the call:
> [!NOTE]
> This project is a proof of concept. It is not intended to be used in production. This demonstrates how can be combined Azure Communication Services, Azure Cognitive Services and Azure OpenAI to build an automated call center solution.
- [x] Access the claim on a public website
- [x] Access to customer conversation history
- [x] Bot can be called from a phone number
- [x] Company products (= lexicon) can be understood by the bot (e.g. a name of a specific insurance product)
Expand All @@ -53,10 +54,10 @@ Extract of the data stored during the call:
- [x] Disengaging from a human agent when needed
- [x] Fine understanding of the customer request with GPT-4 Turbo
- [x] Follow a specific data schema for the claim
- [x] Has access to a documentation database (few-shot training / RAG)
- [x] Help the user to find the information needed to complete the claim
- [x] Send a SMS report after the call
- [x] Take back a conversation after a disengagement
- [ ] Access the claim on a public website
- [ ] Call back the user when needed
- [ ] Simulate a IVR workflow

Expand Down Expand Up @@ -95,14 +96,16 @@ graph LR
subgraph "Claim AI"
api["API"]
communication_service["Call gateway\n(Communication Services)"]
ai_search[("RAG\n(AI Search)")]
communication_service_sms["SMS gateway\n(Communication Services)"]
communication_service["Call gateway\n(Communication Services)"]
db[("Conversations and claims\n(Cosmos DB or SQLite)")]
event_grid[("Broker\n(Event Grid)")]
gpt["GPT-4 Turbo\n(OpenAI)"]
end
api -- Answer with text --> communication_service
api -- Few-shot training --> ai_search
api -- Generate completion --> gpt
api -- Save conversation --> db
api -- Send SMS report --> communication_service_sms
Expand Down Expand Up @@ -160,6 +163,12 @@ openai:
endpoint: https://xxx.openai.azure.com
gpt_deployment: gpt
gpt_model: gpt-4-1106-preview

ai_search:
access_key: xxx
endpoint: https://xxx.search.windows.net
index: trainings
semantic_configuration: default
```
If you want to use a Service Principal to authenticate to Azure, you can also add the following in a `.env` file:
Expand Down Expand Up @@ -229,6 +238,10 @@ cognitive_service:
endpoint: https://xxx.cognitiveservices.azure.com
openai: {}
ai_search:
index: trainings
semantic_configuration: default
```

Steps to deploy:
Expand All @@ -238,10 +251,17 @@ Steps to deploy:
3. Connect to your Azure environment (e.g. `az login`)
4. Run deployment with `make deploy name=my-instance`
5. Wait for the deployment to finish
6. Get the logs with `make logs name=my-instance`
6. Create the AI Search index
7. Get the logs with `make logs name=my-instance`

## Advanced usage

### Add my custom training data

Training data is stored on AI Search to be retrieved by the bot, on demand.

An exampe is [available at `examples/import-training.ipynb`](examples/import-training.ipynb). It shows how to import training data from a PDF files dataset.

### Customize the prompts

Note that prompt examples contains `{xxx}` placeholders. These placeholders are replaced by the bot with the corresponding data. For example, `{bot_name}` is internally replaced by the bot name.
Expand Down Expand Up @@ -297,13 +317,16 @@ prompts:
4. Gather additional information if needed (e.g. error messages, screenshots)
5. Be proactive and create reminders for follow-up or further assistance
Assistant requires data from the employee to provide IT support. The assistant's role is not over until the issue is resolved or the request is fulfilled.
Support status:
{claim}
Reminders:
{reminders}
Documentation and training material:
{trainings}
Assistant requires data from the employee to provide IT support. The assistant's role is not over until the issue is resolved or the request is fulfilled.
```

### Customize the claim data schema
Expand Down
44 changes: 44 additions & 0 deletions bicep/app.bicep
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
param adaModel string
param adaVersion string
param config string
param gptModel string
param gptVersion string
param imageVersion string
param location string
param openaiLocation string
param searchLocation string
param tags object

var prefix = deployment().name
var appUrl = 'https://claim-ai.${acaEnv.properties.defaultDomain}'
var gptModelFullName = toLower('${gptModel}-${gptVersion}')
var adaModelFullName = toLower('${adaModel}-${adaVersion}')

output appUrl string = appUrl
output blobStoragePublicName string = storageAccount.name
Expand Down Expand Up @@ -118,6 +122,14 @@ resource containerApp 'Microsoft.App/containerApps@2023-05-01' = {
name: 'OPENAI_GPT_MODEL'
value: gptModel
}
{
name: 'AI_SEARCH_ENDPOINT'
value: 'https://${search.name}.search.windows.net'
}
{
name: 'AI_SEARCH_ACCESS_KEY'
value: search.listAdminKeys().primaryKey
}
]
resources: {
cpu: 1
Expand Down Expand Up @@ -289,6 +301,23 @@ resource contentfilter 'Microsoft.CognitiveServices/accounts/raiPolicies@2023-06
}
}

resource ada 'Microsoft.CognitiveServices/accounts/deployments@2023-10-01-preview' = {
parent: cognitiveOpenai
name: adaModelFullName
sku: {
capacity: 50
name: 'Standard'
}
properties: {
raiPolicyName: contentfilter.name
model: {
format: 'OpenAI'
name: adaModel
version: adaVersion
}
}
}

resource cosmos 'Microsoft.DocumentDB/databaseAccounts@2023-11-15' = {
name: prefix
location: location
Expand Down Expand Up @@ -385,3 +414,18 @@ resource container 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/container
}
}
}

resource search 'Microsoft.Search/searchServices@2023-11-01' = {
name: prefix
location: searchLocation
tags: tags
sku: {
name: 'basic'
}
identity: {
type: 'SystemAssigned'
}
properties: {
semanticSearch: 'free'
}
}
8 changes: 7 additions & 1 deletion bicep/main.bicep
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
param adaModel string = 'text-embedding-ada-002'
param adaVersion string = '2'
param config string
param imageVersion string = 'develop'
param gptModel string = 'gpt-4'
param gptVersion string = '1106-Preview'
param imageVersion string = 'develop'
param instance string = deployment().name
param location string = 'westeurope'
param openaiLocation string = 'swedencentral'
param searchLocation string = 'northeurope'

targetScope = 'subscription'

Expand All @@ -30,12 +33,15 @@ module app 'app.bicep' = {
name: instance
scope: sub
params: {
adaModel: adaModel
adaVersion: adaVersion
config: config
gptModel: gptModel
gptVersion: gptVersion
imageVersion: imageVersion
location: location
openaiLocation: openaiLocation
searchLocation: searchLocation
tags: tags
}
}
Binary file added examples/dataset/20210300_CG_GH_3350-56221.pdf
Binary file not shown.
Binary file added examples/dataset/CG MRH GROUPAMA.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added examples/dataset/Groupama-Offre.pdf
Binary file not shown.
Binary file added examples/dataset/Groupama-URD2021-FR-ecobook.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4,326 changes: 4,326 additions & 0 deletions examples/import-training.ipynb

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions helpers/config_models/ai_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pydantic import SecretStr
from pydantic_settings import BaseSettings


class AiSearchModel(BaseSettings, env_prefix="ai_search_"):
access_key: SecretStr
endpoint: str
index: str
semantic_configuration: str
top_k: int = 5
Loading

0 comments on commit d47649c

Please sign in to comment.