Skip to content

Commit 9d7c82a

Browse files
authored
format
1 parent 635923b commit 9d7c82a

1 file changed

Lines changed: 32 additions & 31 deletions

File tree

0_Azure/3_AzureAI/9_AzureOpenAI/demos/1_OptimizingChatbotEfficiency.md

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,29 @@ Last updated: 2024-11-19
1010

1111
----------
1212

13-
## Content
14-
15-
<!-- TOC -->
16-
17-
- [Optimizing Chatbot Efficiency](#optimizing-chatbot-efficiency)
18-
- [Content](#content)
19-
- [General Overview](#general-overview)
20-
- [Set Up Your Azure Environment](#set-up-your-azure-environment)
21-
- [Set Up a Database for Context Storage](#set-up-a-database-for-context-storage)
22-
- [Implement Contextual Memory in the Application](#implement-contextual-memory-in-the-application)
23-
- [Example](#example)
24-
- [Other considerations:](#other-considerations)
25-
- [Wiki](#wiki)
26-
27-
<!-- /TOC -->
2813

29-
Find below strategies to enhance process efficiency:
14+
<details>
15+
<summary><b>Table of Contents</b> (Click to expand)</summary>
16+
17+
- [General Overview](#general-overview)
18+
- [Set Up Your Azure Environment](#set-up-your-azure-environment)
19+
- [Set Up a Database for Context Storage](#set-up-a-database-for-context-storage)
20+
- [Implement Contextual Memory in the Application](#implement-contextual-memory-in-the-application)
21+
- [Example](#example)
22+
- [Other considerations:](#other-considerations)
23+
- [Wiki](#wiki)
24+
25+
</details>
26+
27+
28+
> Find below strategies to enhance process efficiency, these approaches can significantly reduce computational demands and enhance model efficiency in chatbot applications.
3029
3130
- [Contextual Memory](#implement-contextual-memory-in-the-application): Implement a server-side system that retains conversation context. This allows for sending only new user requests to the model, with the server adding necessary context before the API call.
3231
- **Prompt Compression**: Apply techniques to shorten the prompt by removing non-essential words, simplifying sentences, and concentrating on key context and instructions.
3332
- **Batch Processing**: For multiple queries, group them into a single API call to decrease request numbers and boost efficiency.
3433
- **Parameterization**: Use a parameterized format for prompts to allow dynamic input substitution, reducing prompt size while keeping it flexible.
3534
- **Preprocessing**: Clean and preprocess input data to eliminate unnecessary whitespace, punctuation, and formatting issues, optimizing prompt processing efficiency.
3635

37-
These approaches can significantly reduce computational demands and enhance model efficiency in chatbot applications.
38-
3936
## General Overview
4037
### Set Up Your Azure Environment
4138

@@ -45,7 +42,9 @@ These approaches can significantly reduce computational demands and enhance mode
4542
| **Deploy a Model** | 1. **Navigate to Azure OpenAI Studio**: <br> - Go to Azure OpenAI Studio. <br> - Sign in with your Azure credentials. <br> 2. **Create a Deployment**: <br> - Select your Azure OpenAI resource. <br> - Click on `Deployments` and then `Create new deployment`. <br> - Choose the model you want to deploy (e.g., GPT-4). <br> - Configure the deployment settings and click `Create`. |
4643

4744
### Set Up a Database for Context Storage
48-
Using Azure SQL Database:
45+
46+
> Using Azure SQL Database:
47+
4948
1. Create an Azure SQL Database:
5049
- In the Azure Portal, click on `Create a resource`.
5150
- Search for `SQL Database` and select it.
@@ -54,17 +53,17 @@ Using Azure SQL Database:
5453
2. Configure the Database:
5554
- Set up the firewall rules to allow your application to connect to the database.
5655
- Create a table to store conversation context.
57-
58-
```sql
59-
CREATE TABLE context (
60-
user_id NVARCHAR(50) PRIMARY KEY,
61-
conversation NVARCHAR(MAX)
62-
);
63-
```
56+
57+
```sql
58+
CREATE TABLE context (
59+
user_id NVARCHAR(50) PRIMARY KEY,
60+
conversation NVARCHAR(MAX)
61+
);
62+
```
6463

6564
## Implement Contextual Memory in the Application
6665

67-
To implement contextual memory, you'll need to store and manage the conversation context on the server. This way, you only have to send the user's most recent request with each request. Here's a step-by-step guide to getting started:
66+
> To implement contextual memory, you'll need to store and manage the conversation context on the server. This way, you only have to send the user's most recent request with each request. Here's a step-by-step guide to getting started:
6867
6968
- Set Up a Server: To store the conversation context. This can be done using a web server with a database.
7069
- Store Conversation Context: When a user sends a message, store the conversation context in a database. This context can include the user’s previous messages, the bot’s responses, and any other relevant information.
@@ -73,7 +72,7 @@ To implement contextual memory, you'll need to store and manage the conversation
7372
7473
### Example
7574
76-
Here’s a simplified example using Python and a database like Azure SQL. For more information on how to connect to the SQL database click [here](https://learn.microsoft.com/en-us/azure/azure-sql/database/azure-sql-python-quickstart?view=azuresql&tabs=windows%2Csql-auth#add-code-to-connect-to-azure-sql-database). For more about Azure OpenAI On Your Data API click [here](https://learn.microsoft.com/en-us/azure/ai-services/openai/references/on-your-data?tabs=python)
75+
> Here’s a simplified example using Python and a database like Azure SQL. For more information on how to connect to the SQL database click [here](https://learn.microsoft.com/en-us/azure/azure-sql/database/azure-sql-python-quickstart?view=azuresql&tabs=windows%2Csql-auth#add-code-to-connect-to-azure-sql-database). For more about Azure OpenAI On Your Data API click [here](https://learn.microsoft.com/en-us/azure/ai-services/openai/references/on-your-data?tabs=python)
7776
7877
```python
7978
import pyodbc
@@ -142,9 +141,10 @@ def retrieve_context(user_id):
142141
return result[0] if result else ""
143142
```
144143

145-
Integrating with Azure OpenAI:
144+
> Integrating with Azure OpenAI:
146145
147-
Use the Azure OpenAI API to send the prompt and receive the response. Click [here](https://learn.microsoft.com/en-us/azure/ai-services/openai/quickstart?tabs=command-line%2Cpython-new&pivots=programming-language-python) if want to see more.
146+
> [!TIP]
147+
> Use the Azure OpenAI API to send the prompt and receive the response. Click [here](https://learn.microsoft.com/en-us/azure/ai-services/openai/quickstart?tabs=command-line%2Cpython-new&pivots=programming-language-python) if want to see more.
148148
149149
```python
150150
import os
@@ -187,6 +187,7 @@ store_context(user_id, new_context)
187187
```
188188

189189
### Other considerations:
190+
190191
- To enhance context management, consider truncating older parts of the conversation, summarizing previous discussions, and using tokens effectively to manage prompt size.
191192
- For security and privacy, ensure the stored context is secure and adheres to privacy laws by encrypting sensitive data, implementing access controls, and ensuring compliance with data protection regulations like GDPR and CCPA.
192193

@@ -209,4 +210,4 @@ store_context(user_id, new_context)
209210
<div align="center">
210211
<h3 style="color: #4CAF50;">Total Visitors</h3>
211212
<img src="https://profile-counter.glitch.me/brown9804/count.svg" alt="Visitor Count" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
212-
</div>
213+
</div>

0 commit comments

Comments
 (0)