Spaces:
Runtime error
Runtime error
File size: 22,437 Bytes
4a51346 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## ์ด ๋ฌธ์๋ฅผ ์์ ํ ๋น์ ์๊ฒ...\n",
"#### ํ์ฌ ์ํฉ์ ์๋์ ๊ฐ์ต๋๋ค.\n",
"1. ์๋ 4๊ฐ์ง์ ๋๊ตฌ๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.\n",
"- ํํฐ query๋ก ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ ๋ณด ์ถ์ถ(์ถ์ฒ์ ์ํจ): chroma๋ฅผ ํ์ฉํด ์์ง๋ wine database์ ํํฐ๋ฅผ ์ ์ฉํ์ฌ ํน์ ์์ธ๋ง ๋ฝ์์ฌ ์ ์์ต๋๋ค. \n",
" - input: {body:3, price:100000~120000}\n",
" - output: [Document(page_content='ํฌ์ง์ค ๋ฐ์ด ์ ค์', metadata={'price': '30000', ...}),]\n",
"- ์์ฐ์ด query๋ก ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ ๋ณด ์ถ์ถ(์ถ์ฒ์ ์ํจ): DocArrayInMemorySearch์ ํ์ฉํด wine database์ ์์ฐ์ด๋ก ํน์ ๋ฐ์ดํฐ๋ฅผ ๋ฝ์ ์ฌ ์ ์์ต๋๋ค.\n",
" - input: \"ํ๋์ค์์ ๋ง๋ค์ด์ง ์์ธ์?\"\n",
"- ํน์ URL query๋ก ์น ํ์ด์ง์์ ์ ๋ณด ์ถ์ถ(์์ธ ๊ตฌ๋งค๋งํฌ์์ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ฌ ๋ ์ฌ์ฉ): SeleniumURLLoader๋ฅผ ์ด์ฉํด ํน์ url๋ก ๋ถํฐ ์นํ์ด์ง ์ ๋ณด๋ฅผ ์ป์ ์ ์์ต๋๋ค.\n",
"- ์์ฐ์ด ๊ตฌ๊ธ ๊ฒ์์ผ๋ก ์น ํ์ด์ง์์ ์ ๋ณด ์ถ์ถ(Q&A์ฒ๋ผ ๊ทธ ์ธ ๊ฒ์์ด ํ์ํ ๊ฒฝ์ฐ ์ฌ์ฉ): SerpAPI๋ฅผ ์ด์ฉํด ๊ตฌ๊ธ์์ ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค.\n",
"\n",
"#### ๋น์ ์ ๋ชฉํ๋ ์๋์ ๊ฐ์ต๋๋ค.\n",
"1. ๋ค์ํ ๋๊ตฌ๋ฅผ ์ฌ์ฉํ๊ฑฐ๋ ์๊ณ ๋ฆฌ์ฆ์ ํ๊ตฌํ์ฌ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ฐ๊ฒฐํ ์ ์๋ ์ข์ ๋ฐฉ์์ ์ฐพ์ต๋๋ค. (์๋ฅผ ๋ค๋ฉด ์์ธ๋ฐ์ ์์ธ์ ๋ณด๋ฅผ ๊ฒ์ํ๊ธฐ ์ํ ์นด์นด์ค ์์น ์ ๋ณด API๋ฑ์ ์ถ๊ฐํ ์ ์์ ๋ฏ ํฉ๋๋ค.)\n",
"2. ๋๊ตฌ๋ฅผ ์ฌ์ฉํ ๋๋ ์ ์ ํ format์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ฑ๋ฅ์ ์ํฅ์ ์ค๋๋ค. ๊ฐ ๋๊ตฌ๋ค์ ๋ํ ์ ์ ํ input format์ ์ฐพ์ต๋๋ค.\n",
"\n",
"\n",
"#### ์ฐธ๊ณ ์ฌํญ\n",
"ํ์ฌ ๋ง์ด ๋๋ฌด ๋ชจํธํ๊ฒ ์จ์๊ณ , ๋๊ตฌ์ ์ฌ์ฉ์ฒ๊ฐ ํ์คํ์ง ์์ต๋๋ค. ์ด๋ฅผ ๊ตฌ์ฒดํํ๋ ๊ณผ์ ์ด ํ์ํ๊ธฐ๋ ํฉ๋๋ค."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"-------------------------------------------------------------------------------"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### API ํค ๋ถ๋ฌ์ค๊ธฐ"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import configparser"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['./secrets.ini']"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"config = configparser.ConfigParser()\n",
"config.read('./secrets.ini')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"openai_api_key = config['OPENAI']['OPENAI_API_KEY']\n",
"serper_api_key = config['SERPER']['SERPER_API_KEY']\n",
"serp_api_key = config['SERPAPI']['SERPAPI_API_KEY']\n",
"os.environ.update({'OPENAI_API_KEY': openai_api_key})\n",
"os.environ.update({'SERPER_API_KEY': serper_api_key})\n",
"os.environ.update({'SERPAPI_API_KEY': serp_api_key})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from typing import List, Union\n",
"import re\n",
"import json\n",
"\n",
"import pandas as pd\n",
"from langchain import SerpAPIWrapper, LLMChain\n",
"from langchain.agents import Tool, AgentType, AgentExecutor, LLMSingleActionAgent, AgentOutputParser\n",
"from langchain.chat_models import ChatOpenAI\n",
"from langchain.chains import LLMChain, SimpleSequentialChain\n",
"from langchain.chains.query_constructor.base import AttributeInfo\n",
"from langchain.document_loaders import DataFrameLoader, SeleniumURLLoader\n",
"from langchain.embeddings import OpenAIEmbeddings\n",
"from langchain.indexes import VectorstoreIndexCreator\n",
"from langchain.prompts import PromptTemplate, StringPromptTemplate, load_prompt, BaseChatPromptTemplate\n",
"from langchain.llms import OpenAI\n",
"from langchain.retrievers.self_query.base import SelfQueryRetriever\n",
"from langchain.schema import AgentAction, AgentFinish, HumanMessage\n",
"from langchain.vectorstores import DocArrayInMemorySearch, Chroma"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Load wine database json"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_json('./data/unified_wine_data.json', encoding='utf-8', lines=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>url</th>\n",
" <th>site_name</th>\n",
" <th>price</th>\n",
" <th>name</th>\n",
" <th>en_name</th>\n",
" <th>img_url</th>\n",
" <th>body</th>\n",
" <th>acidity</th>\n",
" <th>tannin</th>\n",
" <th>sweetness</th>\n",
" <th>alcohol</th>\n",
" <th>wine_type</th>\n",
" <th>country</th>\n",
" <th>grape</th>\n",
" <th>rating</th>\n",
" <th>pickup_location</th>\n",
" <th>vivino_link</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>https://www.winenara.com/shop/product/product_...</td>\n",
" <td>winenara</td>\n",
" <td>49000</td>\n",
" <td>๋ชจ๋
ธํด ํด๋ผ์์ฝ</td>\n",
" <td>Monopole Classico</td>\n",
" <td>https://www.winenara.com/uploads/product/550/1...</td>\n",
" <td>3</td>\n",
" <td></td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>-1</td>\n",
" <td>ํ์ดํธ</td>\n",
" <td>์คํ์ธ</td>\n",
" <td></td>\n",
" <td>3.8</td>\n",
" <td></td>\n",
" <td>https://www.vivino.com/monopole-la-rioja-blanc...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>https://www.winenara.com/shop/product/product_...</td>\n",
" <td>winenara</td>\n",
" <td>32000</td>\n",
" <td>์๋ผ๋ฒ ๋ฅด๊ฑฐ ๋ก์ ์คํ์
๋ธ๋คผ</td>\n",
" <td>Schlumberger Rose Special Brut</td>\n",
" <td>https://www.winenara.com/uploads/product/550/d...</td>\n",
" <td>3</td>\n",
" <td></td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>-1</td>\n",
" <td>์คํํด๋ง</td>\n",
" <td>๋
์ผ</td>\n",
" <td></td>\n",
" <td>3.8</td>\n",
" <td></td>\n",
" <td>https://www.vivino.com/schlumberger-spring-edi...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>https://www.winenara.com/shop/product/product_...</td>\n",
" <td>winenara</td>\n",
" <td>50000</td>\n",
" <td>SET)ํ๋ฐ๋ด๋ฆฌ์คํธ ์ค๋ฅด๋๋ค ์ํต ํจํค์ง</td>\n",
" <td>SET)THE FEDERALIST CHARDONNAY</td>\n",
" <td>https://www.winenara.com/uploads/product/550/d...</td>\n",
" <td>3</td>\n",
" <td></td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>-1</td>\n",
" <td>ํ์ดํธ</td>\n",
" <td>๋ฏธ๊ตญ</td>\n",
" <td></td>\n",
" <td>3.7</td>\n",
" <td></td>\n",
" <td>https://www.vivino.com/federalist-chardonnay-m...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>https://www.winenara.com/shop/product/product_...</td>\n",
" <td>winenara</td>\n",
" <td>55000</td>\n",
" <td>๋ฒ ๋์นด ํธ๋ ๋น๋์ค</td>\n",
" <td>VENICA TRE VIGNIS</td>\n",
" <td>https://www.winenara.com/uploads/product/550/c...</td>\n",
" <td>4</td>\n",
" <td></td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>-1</td>\n",
" <td>ํ์ดํธ</td>\n",
" <td>์ดํ๋ฆฌ์</td>\n",
" <td></td>\n",
" <td>3.9</td>\n",
" <td></td>\n",
" <td>https://www.vivino.com/US-CA/en/venica-venica-...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>https://www.winenara.com/shop/product/product_...</td>\n",
" <td>winenara</td>\n",
" <td>24900</td>\n",
" <td>SET)๋น๋ผ์ ๋น์์ฝ + ๊ธ๋ผ์ค2๊ฐ ์ํฐํจํค์ง</td>\n",
" <td>SET)VILLA M Bianco + GLASS WINTER PACKAGE</td>\n",
" <td>https://www.winenara.com/uploads/product/550/a...</td>\n",
" <td>-1</td>\n",
" <td></td>\n",
" <td></td>\n",
" <td>4</td>\n",
" <td>-1</td>\n",
" <td>๋์ ํธ</td>\n",
" <td>์ดํ๋ฆฌ์</td>\n",
" <td></td>\n",
" <td>3.9</td>\n",
" <td></td>\n",
" <td>https://www.vivino.com/villa-m-bianco/w/1774733</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" url site_name price \\\n",
"0 https://www.winenara.com/shop/product/product_... winenara 49000 \n",
"1 https://www.winenara.com/shop/product/product_... winenara 32000 \n",
"2 https://www.winenara.com/shop/product/product_... winenara 50000 \n",
"3 https://www.winenara.com/shop/product/product_... winenara 55000 \n",
"4 https://www.winenara.com/shop/product/product_... winenara 24900 \n",
"\n",
" name en_name \\\n",
"0 ๋ชจ๋
ธํด ํด๋ผ์์ฝ Monopole Classico \n",
"1 ์๋ผ๋ฒ ๋ฅด๊ฑฐ ๋ก์ ์คํ์
๋ธ๋คผ Schlumberger Rose Special Brut \n",
"2 SET)ํ๋ฐ๋ด๋ฆฌ์คํธ ์ค๋ฅด๋๋ค ์ํต ํจํค์ง SET)THE FEDERALIST CHARDONNAY \n",
"3 ๋ฒ ๋์นด ํธ๋ ๋น๋์ค VENICA TRE VIGNIS \n",
"4 SET)๋น๋ผ์ ๋น์์ฝ + ๊ธ๋ผ์ค2๊ฐ ์ํฐํจํค์ง SET)VILLA M Bianco + GLASS WINTER PACKAGE \n",
"\n",
" img_url body acidity tannin \\\n",
"0 https://www.winenara.com/uploads/product/550/1... 3 \n",
"1 https://www.winenara.com/uploads/product/550/d... 3 \n",
"2 https://www.winenara.com/uploads/product/550/d... 3 \n",
"3 https://www.winenara.com/uploads/product/550/c... 4 \n",
"4 https://www.winenara.com/uploads/product/550/a... -1 \n",
"\n",
" sweetness alcohol wine_type country grape rating pickup_location \\\n",
"0 -1 -1 ํ์ดํธ ์คํ์ธ 3.8 \n",
"1 -1 -1 ์คํํด๋ง ๋
์ผ 3.8 \n",
"2 -1 -1 ํ์ดํธ ๋ฏธ๊ตญ 3.7 \n",
"3 -1 -1 ํ์ดํธ ์ดํ๋ฆฌ์ 3.9 \n",
"4 4 -1 ๋์ ํธ ์ดํ๋ฆฌ์ 3.9 \n",
"\n",
" vivino_link \n",
"0 https://www.vivino.com/monopole-la-rioja-blanc... \n",
"1 https://www.vivino.com/schlumberger-spring-edi... \n",
"2 https://www.vivino.com/federalist-chardonnay-m... \n",
"3 https://www.vivino.com/US-CA/en/venica-venica-... \n",
"4 https://www.vivino.com/villa-m-bianco/w/1774733 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"df.head()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Prepare Langchain Tool"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Tool1: Wine database 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"loader =DataFrameLoader(data_frame=df, page_content_column='name')\n",
"docs = loader.load()\n",
"embeddings = OpenAIEmbeddings()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"์๋๋ wine database1์ metadata_field Attribute์ด๋ค. ์๋๋ฅผ ๊ธฐ์ค์ผ๋ก ์์น๋ฅผ ์งํํ๊ฒ ๋๋ค."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"metadata_field_info = [\n",
" AttributeInfo(\n",
" name=\"body\",\n",
" description=\"1-5 rating for the body of wine\",\n",
" type=\"int\",\n",
" ),\n",
" AttributeInfo(\n",
" name=\"sweetness\",\n",
" description=\"1-5 rating for the sweetness of wine\",\n",
" type=\"int\",\n",
" ),\n",
" AttributeInfo(\n",
" name=\"alcohol\",\n",
" description=\"1-5 rating for the alcohol of wine\",\n",
" type=\"int\",\n",
" ),\n",
" AttributeInfo(\n",
" name=\"price\",\n",
" description=\"The price of the wine\",\n",
" type=\"int\",\n",
" ),\n",
" AttributeInfo(\n",
" name=\"rating\", \n",
" description=\"1-5 rating for the wine\", \n",
" type=\"float\"\n",
" ),\n",
" AttributeInfo(\n",
" name=\"wine_type\", \n",
" description=\"The type of wine. It can be '๋ ๋', '๋ก์ ', '์คํํด๋ง', 'ํ์ดํธ', '๋์ ํธ', '์ฃผ์ ๊ฐํ'\", \n",
" type=\"string\"\n",
" ),\n",
" AttributeInfo(\n",
" name=\"country\", \n",
" description=\"The country of wine. It can be '๊ธฐํ ์ ๋๋ฅ', '๊ธฐํ๊ตฌ๋๋ฅ', '๋ด์ง๋๋', '๋
์ผ', '๋ฏธ๊ตญ', '์คํ์ธ', '์๋ฅดํจํฐ๋', '์ดํ๋ฆฌ์', '์น ๋ ', 'ํฌ๋ฃจํฌ์นผ', 'ํ๋์ค', 'ํธ์ฃผ'\", \n",
" type=\"float\"\n",
" ),\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vectorstore = Chroma.from_documents(docs, embeddings)\n",
"document_content_description = \"Database of a wine\"\n",
"llm = OpenAI(temperature=0)\n",
"retriever = SelfQueryRetriever.from_llm(\n",
" llm, vectorstore, document_content_description, metadata_field_info, verbose=True\n",
") # Added missing closing parenthesis\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"query=' ' filter=Operation(operator=<Operator.AND: 'and'>, arguments=[Comparison(comparator=<Comparator.EQ: 'eq'>, attribute='wine_type', value='๋ ๋'), Operation(operator=<Operator.AND: 'and'>, arguments=[Comparison(comparator=<Comparator.GT: 'gt'>, attribute='body', value=0), Comparison(comparator=<Comparator.LT: 'lt'>, attribute='body', value=3)])]) limit=None\n"
]
},
{
"data": {
"text/plain": [
"[Document(page_content='๋ฐ ๋
ํผ๋
ธ๋์', metadata={'url': 'https://www.winenara.com/shop/product/product_view?product_cd=03P976', 'site_name': 'winenara', 'price': 29000, 'en_name': 'BAR DOG PINOT NOIR', 'img_url': 'https://www.winenara.com/uploads/product/550/1936_detail_084.png', 'body': 2, 'acidity': '', 'tannin': '', 'sweetness': -1, 'alcohol': -1, 'wine_type': '๋ ๋', 'country': '๋ฏธ๊ตญ', 'grape': '', 'rating': 3.6, 'pickup_location': '', 'vivino_link': 'https://www.vivino.com/US-CA/en/bar-dog-pinot-noir/w/7129723'}),\n",
" Document(page_content='๋ฃจ์ด๋ผ๋๋ฅด ํผ๋
ธ๋์', metadata={'url': 'https://www.winenara.com/shop/product/product_view?product_cd=03H965', 'site_name': 'winenara', 'price': 52000, 'en_name': 'LOUIS LATOUR PINOT NOIR', 'img_url': 'https://www.winenara.com/uploads/product/550/493_detail_025.png', 'body': 2, 'acidity': '', 'tannin': '', 'sweetness': -1, 'alcohol': -1, 'wine_type': '๋ ๋', 'country': 'ํ๋์ค', 'grape': '', 'rating': 3.6, 'pickup_location': '', 'vivino_link': 'https://www.vivino.com/GB/en/louis-latour-bourgogne-pinot-noir/w/7343'}),\n",
" Document(page_content='๋ฃจ์ด๋ผ๋๋ฅด ์๋จ๋ค', metadata={'url': 'https://www.winenara.com/shop/product/product_view?product_cd=03P299', 'site_name': 'winenara', 'price': 79000, 'en_name': 'LOUIS LATOUR SANTENAY', 'img_url': 'https://www.winenara.com/uploads/product/550/489_detail_096.png', 'body': 2, 'acidity': '', 'tannin': '', 'sweetness': -1, 'alcohol': -1, 'wine_type': '๋ ๋', 'country': 'ํ๋์ค', 'grape': '', 'rating': 3.8, 'pickup_location': '', 'vivino_link': 'https://www.vivino.com/louis-latour-santenay-rouge/w/7369'}),\n",
" Document(page_content='๋น์๋ ๋ ๋ก์', metadata={'url': 'https://www.winenara.com/shop/product/product_view?product_cd=033704', 'site_name': 'winenara', 'price': 12000, 'en_name': 'VIALETTO ROSSO', 'img_url': 'https://www.winenara.com/uploads/product/550/d1ef6058de3661b565084b815e359852.png', 'body': 2, 'acidity': '', 'tannin': '', 'sweetness': -1, 'alcohol': -1, 'wine_type': '๋ ๋', 'country': '์ดํ๋ฆฌ์', 'grape': '', 'rating': 3.1, 'pickup_location': '', 'vivino_link': 'https://www.vivino.com/US-CA/en/vialetto-rosso-dolce/w/2213764'})]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"retriever.get_relevant_documents('{\"wine_type\":\"๋ ๋\", \"body\": \"lt 3 gt 0\"}') # gt means greater than, lt means less than, eq means equal to"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Tool2: Search specific wine with url"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def search_with_url(query):\n",
" return SeleniumURLLoader(urls=[query]).load()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Tool3: Wine database 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"index = VectorstoreIndexCreator(\n",
" vectorstore_cls=DocArrayInMemorySearch\n",
").from_loaders([loader])"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Tool4: Search in Google"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"search = SerpAPIWrapper()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tools = [\n",
" Tool(\n",
" name=\"Wine database\",\n",
" func=retriever.get_relevant_documents,\n",
" description=\"\"\"\n",
"Database about the wines in wine store. You can get information such as the price of the wine, purchase URL, features, rating information, and more.\n",
"You can search wines with the following attributes:\n",
"- body: 1-5 rating int for the body of wine. You have to specify greater than or less than. For example, if you want to search for wines with a body rating of less than 3, enter 'body: gt 0 lt 3'\n",
"- price: The price range of the wine. Please enter the price range in the form of range. For example, if you want to search for wines that cost less than 20,000 won, enter 'price: gt 0 lt20000'\n",
"- rating: 1-5 rating float for the wine. You have to specify greater than or less than. For example, if you want to search for wines with a rating of less than 3, enter 'rating: gt 0 lt 3'\n",
"- wine_type: The type of wine. It can be '๋ ๋', '๋ก์ ', '์คํํด๋ง', 'ํ์ดํธ', '๋์ ํธ', '์ฃผ์ ๊ฐํ'\n",
"- name: The name of wine. ์
๋ ฅํ ๋๋ '์์ธ ์ด๋ฆ์ \"๋น๋ ์กฐ์\" ์
๋๋ค' ์ด๋ฐ ์์ผ๋ก ์
๋ ฅํด์ฃผ์ธ์.\n",
"\"\"\"\n",
" ),\n",
" Tool(\n",
" name = \"Search specific wine with url\",\n",
" func=search_with_url,\n",
" description=\"Search specific wine with url. Query must be url\"\n",
" ),\n",
" Tool(\n",
" name = \"Wine database 2\",\n",
" func=index.query,\n",
" description=\"Database about the wines in wine store. You can use this tool if you're having trouble getting information from the wine database tool above. Query must be in String\"\n",
" ),\n",
" Tool(\n",
" name = \"Search\",\n",
" func=search.run,\n",
" description=\"Useful for when you need to ask with search. Search in English only.\"\n",
" ),\n",
"]"
]
}
],
"metadata": {
"language_info": {
"name": "python"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|