|
48 | 48 | " }]},\n", |
49 | 49 | " ```\n", |
50 | 50 | "\n", |
51 | | - "- On Azure AI Search, create a role assignment for the Azure OpenAI managed identity. Required roles: Search Index Data Reader, Search Service Contributor.\n", |
| 51 | + "- On Azure AI Search, create a role assignment for the Azure OpenAI managed identity. Required roles: **Search Index Data Reader**, **Search Service Contributor**.\n", |
52 | 52 | "\n", |
53 | | - "- On Azure OpenAI, create a role assigmnet for the user running the code: Required role: Cognitive Services OpenAI User." |
| 53 | + "- On Azure OpenAI, create a role assigment for the user running the code: Required role: **Cognitive Services OpenAI User**." |
54 | 54 | ] |
55 | 55 | }, |
56 | 56 | { |
|
84 | 84 | "outputs": [], |
85 | 85 | "source": [ |
86 | 86 | "# Set query parameters for grounding the conversation on your search index\n", |
87 | | - "k=50\n", |
88 | 87 | "search_type=\"text\"\n", |
89 | 88 | "use_semantic_reranker=True\n", |
90 | 89 | "sources_to_include=5" |
|
100 | 99 | "from azure.core.credentials_async import AsyncTokenCredential\n", |
101 | 100 | "from azure.identity.aio import get_bearer_token_provider\n", |
102 | 101 | "from azure.search.documents.aio import SearchClient\n", |
103 | | - "from azure.search.documents.models import VectorizableTextQuery, HybridSearch\n", |
104 | 102 | "from openai import AsyncAzureOpenAI\n", |
105 | 103 | "from enum import Enum\n", |
106 | 104 | "from typing import List, Optional\n", |
107 | 105 | "\n", |
108 | | - "\n", |
109 | 106 | "def create_openai_client(credential: AsyncTokenCredential) -> AsyncAzureOpenAI:\n", |
110 | 107 | " token_provider = get_bearer_token_provider(credential, \"https://cognitiveservices.azure.com/.default\")\n", |
111 | 108 | " return AsyncAzureOpenAI(\n", |
|
128 | 125 | " HYBRID = \"hybrid\"\n", |
129 | 126 | "\n", |
130 | 127 | "# This function retrieves the sselected fields from the search index\n", |
131 | | - "async def get_sources(search_client: SearchClient, query: str, search_type: SearchType, use_semantic_reranker: bool = True, sources_to_include: int = 5, k: int = 50) -> List[str]:\n", |
| 128 | + "async def get_sources(search_client: SearchClient, query: str, search_type: SearchType, use_semantic_reranker: bool = True, sources_to_include: int = 5) -> List[str]:\n", |
132 | 129 | " search_type == SearchType.TEXT,\n", |
133 | 130 | " response = await search_client.search(\n", |
134 | 131 | " search_text=query,\n", |
|
159 | 156 | " \"content\": message\n", |
160 | 157 | " })\n", |
161 | 158 | "\n", |
162 | | - " async def append_grounded_message(self, search_client: SearchClient, query: str, search_type: SearchType, use_semantic_reranker: bool = True, sources_to_include: int = 5, k: int = 50):\n", |
163 | | - " sources = await get_sources(search_client, query, search_type, use_semantic_reranker, sources_to_include, k)\n", |
| 159 | + " async def append_grounded_message(self, search_client: SearchClient, query: str, search_type: SearchType, use_semantic_reranker: bool = True, sources_to_include: int = 5):\n", |
| 160 | + " sources = await get_sources(search_client, query, search_type, use_semantic_reranker, sources_to_include)\n", |
164 | 161 | " sources_formatted = \"\\n\".join([f'{document[\"HotelName\"]}:{document[\"Description\"]}:{document[\"Tags\"]}' for document in sources])\n", |
165 | 162 | " self.append_message(role=\"user\", message=GROUNDED_PROMPT.format(query=query, sources=sources_formatted))\n", |
166 | 163 | " self.search_results.append(\n", |
|
0 commit comments