Skip to content

Commit

Permalink
Fix chat history object
Browse files Browse the repository at this point in the history
  • Loading branch information
BenConstable9 committed Sep 5, 2024
1 parent 87e4d87 commit ee595ed
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 105 deletions.
14 changes: 3 additions & 11 deletions text2sql/prompt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ template: |
The response to the user must meet the requirements in RESPONSE OUTPUT REQUIREMENTS.
IMPORTANT INFORMATION contains useful information that you can use to aid your knowledge.
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.
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.
[IMPORTANT INFORMATION]
Expand Down Expand Up @@ -38,7 +38,7 @@ template: |
3. Information Sources:
Use only information from the provided functions and specified important information.
Do not use any external sources or the conversation history for constructing the response.
Do not use any external sources or the chat history for constructing the response.
In case of conflicting information, prioritize data from the SQL Database as the primary source of truth.
4. Calculations:
Expand Down Expand Up @@ -82,23 +82,15 @@ template: |
[END SOURCES PROPERTY REQUIREMENTS]
[END RESPONSE OUTPUT REQUIREMENTS]
[CONVERSATION HISTORY]
{{$chat_history}}
[END CONVERSATION HISTORY]
</message>
{{$chat_history}}
<message role="user">{{$user_input}}</message>
description: Chatbot
name: ChatBot
input_variables:
- name: user_input
description: The user input
is_required: true
- name: chat_history
description: The history of the conversation for the last 3 messages
is_required: true
- name: important_information
description: Useful information for the chatbot
is_required: true
Expand Down
47 changes: 35 additions & 12 deletions text2sql/rag_with_ai_search_and_text_2_sql.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"gather": {
"logged": 1718623217703
Expand Down Expand Up @@ -58,7 +58,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -75,7 +75,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {
"gather": {
"logged": 1718623218006
Expand All @@ -97,7 +97,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {
"gather": {
"logged": 1718623218267
Expand Down Expand Up @@ -125,7 +125,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {
"gather": {
"logged": 1718623218614
Expand All @@ -140,7 +140,18 @@
}
}
},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"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)})"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Register the SQL Plugin with the Database name to use.\n",
"sql_plugin = SQLPlugin(database=os.environ[\"SQL_DB_NAME\"])\n",
Expand All @@ -149,9 +160,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"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)})"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ai_search_plugin = AISearchPlugin()\n",
"kernel.add_plugin(ai_search_plugin, \"AISearch\")"
Expand All @@ -172,7 +194,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -184,7 +206,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -204,7 +226,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -213,7 +235,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -251,6 +273,7 @@
" function_name=\"Chat\",\n",
" plugin_name=\"ChatBot\",\n",
" arguments=arguments,\n",
" chat_history=chat_history,\n",
" )\n",
"\n",
" logging.info(\"Answer: %s\", answer)\n",
Expand Down
Loading

0 comments on commit ee595ed

Please sign in to comment.