|
59 | 59 | },
|
60 | 60 | {
|
61 | 61 | "cell_type": "code",
|
62 |
| - "execution_count": 1, |
| 62 | + "execution_count": 2, |
63 | 63 | "metadata": {},
|
64 | 64 | "outputs": [
|
65 | 65 | {
|
66 | 66 | "data": {
|
67 | 67 | "text/plain": [
|
68 |
| - "True" |
| 68 | + "False" |
69 | 69 | ]
|
70 | 70 | },
|
71 |
| - "execution_count": 1, |
| 71 | + "execution_count": 2, |
72 | 72 | "metadata": {},
|
73 | 73 | "output_type": "execute_result"
|
74 | 74 | }
|
|
105 | 105 | "\n",
|
106 | 106 | "# Vector search index parameters\n",
|
107 | 107 | "index_name = \"VectorSearchIndex\"\n",
|
108 |
| - "vector_dimensions = (\n", |
109 |
| - " 1536 # text-embedding-ada-002 uses a 1536-dimensional embedding vector\n", |
110 |
| - ")\n", |
| 108 | + "vector_dimensions = 1536 # text-embedding-ada-002 uses a 1536-dimensional embedding vector\n", |
111 | 109 | "num_lists = 1\n",
|
112 | 110 | "similarity = \"COS\" # cosine distance"
|
113 | 111 | ]
|
|
141 | 139 | "from semantic_kernel.memory.memory_store_base import MemoryStoreBase\n",
|
142 | 140 | "\n",
|
143 | 141 | "\n",
|
144 |
| - "async def upsert_data_to_memory_store(\n", |
145 |
| - " memory: SemanticTextMemory, store: MemoryStoreBase, data_file_path: str\n", |
146 |
| - ") -> None:\n", |
| 142 | + "async def upsert_data_to_memory_store(memory: SemanticTextMemory, store: MemoryStoreBase, data_file_path: str) -> None:\n", |
147 | 143 | " \"\"\"\n",
|
148 | 144 | " This asynchronous function takes two memory stores and a data file path as arguments.\n",
|
149 | 145 | " It is designed to upsert (update or insert) data into the memory stores from the data file.\n",
|
150 | 146 | "\n",
|
151 | 147 | " Args:\n",
|
152 |
| - " kernel_memory_store (callable): A callable object that represents the kernel memory store where data will be upserted.\n", |
153 |
| - " memory_store (callable): A callable object that represents the memory store where data will be upserted.\n", |
| 148 | + " memory (callable): A callable object that represents the semantic kernel memory.\n", |
| 149 | + " store (callable): A callable object that represents the memory store where data will be upserted.\n", |
154 | 150 | " data_file_path (str): The path to the data file that contains the data to be upserted.\n",
|
155 | 151 | "\n",
|
156 | 152 | " Returns:\n",
|
|
164 | 160 | " # check if the item already exists in the memory store\n",
|
165 | 161 | " # if the id doesn't exist, it throws an exception\n",
|
166 | 162 | " try:\n",
|
167 |
| - " already_created = bool(\n", |
168 |
| - " await store.get(\n", |
169 |
| - " collection_name, item[\"id\"], with_embedding=True\n", |
170 |
| - " )\n", |
171 |
| - " )\n", |
| 163 | + " already_created = bool(await store.get(collection_name, item[\"id\"], with_embedding=True))\n", |
172 | 164 | " except Exception:\n",
|
173 | 165 | " already_created = False\n",
|
174 | 166 | " # if the record doesn't exist, we generate embeddings and save it to the database\n",
|
|
297 | 289 | ],
|
298 | 290 | "source": [
|
299 | 291 | "# adding azure openai text embedding service\n",
|
300 |
| - "embedding_model_deployment_name = os.environ.get(\n", |
301 |
| - " \"AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME\"\n", |
302 |
| - ")\n", |
| 292 | + "embedding_model_deployment_name = os.environ.get(\"AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME\")\n", |
303 | 293 | "\n",
|
304 | 294 | "kernel.add_service(\n",
|
305 | 295 | " AzureTextEmbedding(\n",
|
|
515 | 505 | "from semantic_kernel.connectors.ai.open_ai import OpenAITextPromptExecutionSettings\n",
|
516 | 506 | "\n",
|
517 | 507 | "execution_settings = OpenAITextPromptExecutionSettings(\n",
|
518 |
| - " service_id=\"chat_completion\",\n", |
519 |
| - " ai_model_id=chat_model_deployment_name,\n", |
520 |
| - " max_tokens=500,\n", |
521 |
| - " temperature=0.0,\n", |
522 |
| - " top_p=0.5\n", |
| 508 | + " service_id=\"chat_completion\", ai_model_id=chat_model_deployment_name, max_tokens=500, temperature=0.0, top_p=0.5\n", |
523 | 509 | ")"
|
524 | 510 | ]
|
525 | 511 | },
|
|
540 | 526 | " InputVariable(name=\"db_record\", description=\"The database record\", is_required=True),\n",
|
541 | 527 | " InputVariable(name=\"query_term\", description=\"The user input\", is_required=True),\n",
|
542 | 528 | " ],\n",
|
543 |
| - " execution_settings=execution_settings\n", |
| 529 | + " execution_settings=execution_settings,\n", |
544 | 530 | ")"
|
545 | 531 | ]
|
546 | 532 | },
|
|
551 | 537 | "outputs": [],
|
552 | 538 | "source": [
|
553 | 539 | "chat_function = kernel.create_function_from_prompt(\n",
|
554 |
| - " function_name= \"ChatGPTFunc\",\n", |
555 |
| - " plugin_name=\"chatGPTPlugin\",\n", |
556 |
| - " prompt_template_config=chat_prompt_template_config\n", |
| 540 | + " function_name=\"ChatGPTFunc\", plugin_name=\"chatGPTPlugin\", prompt_template_config=chat_prompt_template_config\n", |
557 | 541 | ")"
|
558 | 542 | ]
|
559 | 543 | },
|
|
563 | 547 | "metadata": {},
|
564 | 548 | "outputs": [],
|
565 | 549 | "source": [
|
566 |
| - "completions_result = await kernel.invoke(chat_function, sk.KernelArguments(query_term=query_term, db_record=result[0].additional_metadata))" |
| 550 | + "completions_result = await kernel.invoke(\n", |
| 551 | + " chat_function, sk.KernelArguments(query_term=query_term, db_record=result[0].additional_metadata)\n", |
| 552 | + ")" |
567 | 553 | ]
|
568 | 554 | },
|
569 | 555 | {
|
|
629 | 615 | "while query_term != \"exit\":\n",
|
630 | 616 | " query_term = input(\"Enter a query: \")\n",
|
631 | 617 | " result = await memory.search(collection_name, query_term)\n",
|
632 |
| - " completions_result = kernel.invoke_stream(chat_function, sk.KernelArguments(query_term=query_term, db_record=result[0].additional_metadata))\n", |
| 618 | + " completions_result = kernel.invoke_stream(\n", |
| 619 | + " chat_function, sk.KernelArguments(query_term=query_term, db_record=result[0].additional_metadata)\n", |
| 620 | + " )\n", |
633 | 621 | " print(f\"Question:\\n{query_term}\\nResponse:\")\n",
|
634 | 622 | " async for completion in completions_result:\n",
|
635 | 623 | " print(str(completion[0]), end=\"\")\n",
|
|
654 | 642 | "name": "python",
|
655 | 643 | "nbconvert_exporter": "python",
|
656 | 644 | "pygments_lexer": "ipython3",
|
657 |
| - "version": "3.11.8" |
| 645 | + "version": "3.12.2" |
658 | 646 | }
|
659 | 647 | },
|
660 | 648 | "nbformat": 4,
|
|
0 commit comments