Skip to content

Add movies dataset #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 19 additions & 31 deletions rag-azure-openai-cosmosdb-notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
"False"
]
},
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -105,9 +105,7 @@
"\n",
"# Vector search index parameters\n",
"index_name = \"VectorSearchIndex\"\n",
"vector_dimensions = (\n",
" 1536 # text-embedding-ada-002 uses a 1536-dimensional embedding vector\n",
")\n",
"vector_dimensions = 1536 # text-embedding-ada-002 uses a 1536-dimensional embedding vector\n",
"num_lists = 1\n",
"similarity = \"COS\" # cosine distance"
]
Expand Down Expand Up @@ -141,16 +139,14 @@
"from semantic_kernel.memory.memory_store_base import MemoryStoreBase\n",
"\n",
"\n",
"async def upsert_data_to_memory_store(\n",
" memory: SemanticTextMemory, store: MemoryStoreBase, data_file_path: str\n",
") -> None:\n",
"async def upsert_data_to_memory_store(memory: SemanticTextMemory, store: MemoryStoreBase, data_file_path: str) -> None:\n",
" \"\"\"\n",
" This asynchronous function takes two memory stores and a data file path as arguments.\n",
" It is designed to upsert (update or insert) data into the memory stores from the data file.\n",
"\n",
" Args:\n",
" kernel_memory_store (callable): A callable object that represents the kernel memory store where data will be upserted.\n",
" memory_store (callable): A callable object that represents the memory store where data will be upserted.\n",
" memory (callable): A callable object that represents the semantic kernel memory.\n",
" store (callable): A callable object that represents the memory store where data will be upserted.\n",
" data_file_path (str): The path to the data file that contains the data to be upserted.\n",
"\n",
" Returns:\n",
Expand All @@ -164,11 +160,7 @@
" # check if the item already exists in the memory store\n",
" # if the id doesn't exist, it throws an exception\n",
" try:\n",
" already_created = bool(\n",
" await store.get(\n",
" collection_name, item[\"id\"], with_embedding=True\n",
" )\n",
" )\n",
" already_created = bool(await store.get(collection_name, item[\"id\"], with_embedding=True))\n",
" except Exception:\n",
" already_created = False\n",
" # if the record doesn't exist, we generate embeddings and save it to the database\n",
Expand Down Expand Up @@ -297,9 +289,7 @@
],
"source": [
"# adding azure openai text embedding service\n",
"embedding_model_deployment_name = os.environ.get(\n",
" \"AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME\"\n",
")\n",
"embedding_model_deployment_name = os.environ.get(\"AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME\")\n",
"\n",
"kernel.add_service(\n",
" AzureTextEmbedding(\n",
Expand Down Expand Up @@ -515,11 +505,7 @@
"from semantic_kernel.connectors.ai.open_ai import OpenAITextPromptExecutionSettings\n",
"\n",
"execution_settings = OpenAITextPromptExecutionSettings(\n",
" service_id=\"chat_completion\",\n",
" ai_model_id=chat_model_deployment_name,\n",
" max_tokens=500,\n",
" temperature=0.0,\n",
" top_p=0.5\n",
" service_id=\"chat_completion\", ai_model_id=chat_model_deployment_name, max_tokens=500, temperature=0.0, top_p=0.5\n",
")"
]
},
Expand All @@ -540,7 +526,7 @@
" InputVariable(name=\"db_record\", description=\"The database record\", is_required=True),\n",
" InputVariable(name=\"query_term\", description=\"The user input\", is_required=True),\n",
" ],\n",
" execution_settings=execution_settings\n",
" execution_settings=execution_settings,\n",
")"
]
},
Expand All @@ -551,9 +537,7 @@
"outputs": [],
"source": [
"chat_function = kernel.create_function_from_prompt(\n",
" function_name= \"ChatGPTFunc\",\n",
" plugin_name=\"chatGPTPlugin\",\n",
" prompt_template_config=chat_prompt_template_config\n",
" function_name=\"ChatGPTFunc\", plugin_name=\"chatGPTPlugin\", prompt_template_config=chat_prompt_template_config\n",
")"
]
},
Expand All @@ -563,7 +547,9 @@
"metadata": {},
"outputs": [],
"source": [
"completions_result = await kernel.invoke(chat_function, sk.KernelArguments(query_term=query_term, db_record=result[0].additional_metadata))"
"completions_result = await kernel.invoke(\n",
" chat_function, sk.KernelArguments(query_term=query_term, db_record=result[0].additional_metadata)\n",
")"
]
},
{
Expand Down Expand Up @@ -629,7 +615,9 @@
"while query_term != \"exit\":\n",
" query_term = input(\"Enter a query: \")\n",
" result = await memory.search(collection_name, query_term)\n",
" completions_result = kernel.invoke_stream(chat_function, sk.KernelArguments(query_term=query_term, db_record=result[0].additional_metadata))\n",
" completions_result = kernel.invoke_stream(\n",
" chat_function, sk.KernelArguments(query_term=query_term, db_record=result[0].additional_metadata)\n",
" )\n",
" print(f\"Question:\\n{query_term}\\nResponse:\")\n",
" async for completion in completions_result:\n",
" print(str(completion[0]), end=\"\")\n",
Expand All @@ -654,7 +642,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.12.2"
}
},
"nbformat": 4,
Expand Down
Loading