Skip to content

Commit 02bc2d9

Browse files
Fix chat history object (#5)
1 parent 87e4d87 commit 02bc2d9

File tree

3 files changed

+99
-105
lines changed

3 files changed

+99
-105
lines changed

text2sql/prompt.yaml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ template: |
1010
1111
The response to the user must meet the requirements in RESPONSE OUTPUT REQUIREMENTS.
1212
IMPORTANT INFORMATION contains useful information that you can use to aid your knowledge.
13-
CONVERSATION HISTORY contains the previous question and answer pairs in the conversation in JSON format. Do not use this information to answer the question, but to provide context on what was asked previously.
13+
CHAT HISTORY contains the previous question and answer pairs in the conversation in JSON format. Do not use this information to answer the question, but to provide context on what was asked previously.
1414
1515
[IMPORTANT INFORMATION]
1616
@@ -38,7 +38,7 @@ template: |
3838
3939
3. Information Sources:
4040
Use only information from the provided functions and specified important information.
41-
Do not use any external sources or the conversation history for constructing the response.
41+
Do not use any external sources or the chat history for constructing the response.
4242
In case of conflicting information, prioritize data from the SQL Database as the primary source of truth.
4343
4444
4. Calculations:
@@ -82,23 +82,15 @@ template: |
8282
[END SOURCES PROPERTY REQUIREMENTS]
8383
8484
[END RESPONSE OUTPUT REQUIREMENTS]
85-
86-
[CONVERSATION HISTORY]
87-
88-
{{$chat_history}}
89-
90-
[END CONVERSATION HISTORY]
9185
</message>
86+
{{$chat_history}}
9287
<message role="user">{{$user_input}}</message>
9388
description: Chatbot
9489
name: ChatBot
9590
input_variables:
9691
- name: user_input
9792
description: The user input
9893
is_required: true
99-
- name: chat_history
100-
description: The history of the conversation for the last 3 messages
101-
is_required: true
10294
- name: important_information
10395
description: Useful information for the chatbot
10496
is_required: true

text2sql/rag_with_ai_search_and_text_2_sql.ipynb

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
{
1515
"cell_type": "code",
16-
"execution_count": null,
16+
"execution_count": 1,
1717
"metadata": {
1818
"gather": {
1919
"logged": 1718623217703
@@ -58,7 +58,7 @@
5858
},
5959
{
6060
"cell_type": "code",
61-
"execution_count": null,
61+
"execution_count": 2,
6262
"metadata": {},
6363
"outputs": [],
6464
"source": [
@@ -75,7 +75,7 @@
7575
},
7676
{
7777
"cell_type": "code",
78-
"execution_count": null,
78+
"execution_count": 3,
7979
"metadata": {
8080
"gather": {
8181
"logged": 1718623218006
@@ -97,7 +97,7 @@
9797
},
9898
{
9999
"cell_type": "code",
100-
"execution_count": null,
100+
"execution_count": 4,
101101
"metadata": {
102102
"gather": {
103103
"logged": 1718623218267
@@ -125,7 +125,7 @@
125125
},
126126
{
127127
"cell_type": "code",
128-
"execution_count": null,
128+
"execution_count": 5,
129129
"metadata": {
130130
"gather": {
131131
"logged": 1718623218614
@@ -140,7 +140,18 @@
140140
}
141141
}
142142
},
143-
"outputs": [],
143+
"outputs": [
144+
{
145+
"data": {
146+
"text/plain": [
147+
"KernelPlugin(name='SQL', description=None, functions={'GetEntitySchema': KernelFunctionFromMethod(metadata=KernelFunctionMetadata(name='GetEntitySchema', plugin_name='SQL', description='Get the detailed schema of an entity in the Database. Use the entity and the column returned to formulate a SQL query. The view name or table name must be one of the ENTITY NAMES defined in the [ENTITIES LIST]. Only use the column names obtained from GetEntitySchema() when constructing a SQL query, do not make up column names.', parameters=[KernelParameterMetadata(name='entity_name', description='The view or table name to get the schema for. It must be one of the ENTITY NAMES defined in the [ENTITIES LIST] function.', default_value=None, type_='str', is_required=True, type_object=<class 'str'>, schema_data={'type': 'string', 'description': 'The view or table name to get the schema for. It must be one of the ENTITY NAMES defined in the [ENTITIES LIST] function.'}, function_schema_include=True)], is_prompt=False, is_asynchronous=True, return_parameter=KernelParameterMetadata(name='return', description='', default_value=None, type_='str', is_required=True, type_object=<class 'str'>, schema_data={'type': 'string'}, function_schema_include=True), additional_properties={}), invocation_duration_histogram=<opentelemetry.metrics._internal.instrument._ProxyHistogram object at 0x7f94ab79e7b0>, streaming_duration_histogram=<opentelemetry.metrics._internal.instrument._ProxyHistogram object at 0x7f94a97e38f0>, method=<bound method SQLPlugin.get_entity_schema of <plugins.sql_plugin.sql_plugin.SQLPlugin object at 0x7f9483c23440>>, stream_method=None), 'RunSQLQuery': KernelFunctionFromMethod(metadata=KernelFunctionMetadata(name='RunSQLQuery', plugin_name='SQL', description='Runs an SQL query against the SQL Database to extract information.', parameters=[KernelParameterMetadata(name='sql_query', description='The SQL query to run against the DB', default_value=None, type_='str', is_required=True, type_object=<class 'str'>, schema_data={'type': 'string', 'description': 'The SQL query to run against the DB'}, function_schema_include=True)], is_prompt=False, is_asynchronous=True, return_parameter=KernelParameterMetadata(name='return', description='', default_value=None, type_='str', is_required=True, type_object=<class 'str'>, schema_data={'type': 'string'}, function_schema_include=True), additional_properties={}), invocation_duration_histogram=<opentelemetry.metrics._internal.instrument._ProxyHistogram object at 0x7f94ab79e7b0>, streaming_duration_histogram=<opentelemetry.metrics._internal.instrument._ProxyHistogram object at 0x7f94a97e38f0>, method=<bound method SQLPlugin.run_sql_query of <plugins.sql_plugin.sql_plugin.SQLPlugin object at 0x7f9483c23440>>, stream_method=None)})"
148+
]
149+
},
150+
"execution_count": 5,
151+
"metadata": {},
152+
"output_type": "execute_result"
153+
}
154+
],
144155
"source": [
145156
"# Register the SQL Plugin with the Database name to use.\n",
146157
"sql_plugin = SQLPlugin(database=os.environ[\"SQL_DB_NAME\"])\n",
@@ -149,9 +160,20 @@
149160
},
150161
{
151162
"cell_type": "code",
152-
"execution_count": null,
163+
"execution_count": 6,
153164
"metadata": {},
154-
"outputs": [],
165+
"outputs": [
166+
{
167+
"data": {
168+
"text/plain": [
169+
"KernelPlugin(name='AISearch', description=None, functions={'QueryDocumentStorage': KernelFunctionFromMethod(metadata=KernelFunctionMetadata(name='QueryDocumentStorage', plugin_name='AISearch', description='Runs an hybrid semantic search against some text to return relevant documents that are indexed within AI Search.', parameters=[KernelParameterMetadata(name='text', description='The text to run a semantic search against.', default_value=None, type_='str', is_required=True, type_object=<class 'str'>, schema_data={'type': 'string', 'description': 'The text to run a semantic search against.'}, function_schema_include=True)], is_prompt=False, is_asynchronous=True, return_parameter=KernelParameterMetadata(name='return', description='', default_value=None, type_='str', is_required=True, type_object=<class 'str'>, schema_data={'type': 'string'}, function_schema_include=True), additional_properties={}), invocation_duration_histogram=<opentelemetry.metrics._internal.instrument._ProxyHistogram object at 0x7f94ab79e7b0>, streaming_duration_histogram=<opentelemetry.metrics._internal.instrument._ProxyHistogram object at 0x7f94a97e38f0>, method=<bound method AISearchPlugin.query_document_storage of <plugins.ai_search_plugin.ai_search_plugin.AISearchPlugin object at 0x7f9483c23f20>>, stream_method=None)})"
170+
]
171+
},
172+
"execution_count": 6,
173+
"metadata": {},
174+
"output_type": "execute_result"
175+
}
176+
],
155177
"source": [
156178
"ai_search_plugin = AISearchPlugin()\n",
157179
"kernel.add_plugin(ai_search_plugin, \"AISearch\")"
@@ -172,7 +194,7 @@
172194
},
173195
{
174196
"cell_type": "code",
175-
"execution_count": null,
197+
"execution_count": 7,
176198
"metadata": {},
177199
"outputs": [],
178200
"source": [
@@ -184,7 +206,7 @@
184206
},
185207
{
186208
"cell_type": "code",
187-
"execution_count": null,
209+
"execution_count": 8,
188210
"metadata": {},
189211
"outputs": [],
190212
"source": [
@@ -204,7 +226,7 @@
204226
},
205227
{
206228
"cell_type": "code",
207-
"execution_count": null,
229+
"execution_count": 9,
208230
"metadata": {},
209231
"outputs": [],
210232
"source": [
@@ -213,7 +235,7 @@
213235
},
214236
{
215237
"cell_type": "code",
216-
"execution_count": null,
238+
"execution_count": 10,
217239
"metadata": {},
218240
"outputs": [],
219241
"source": [
@@ -251,6 +273,7 @@
251273
" function_name=\"Chat\",\n",
252274
" plugin_name=\"ChatBot\",\n",
253275
" arguments=arguments,\n",
276+
" chat_history=chat_history,\n",
254277
" )\n",
255278
"\n",
256279
" logging.info(\"Answer: %s\", answer)\n",

0 commit comments

Comments
 (0)