{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "3853d1cd", "metadata": {}, "source": [ "### API 키 불러오기" ] }, { "cell_type": "code", "execution_count": 1, "id": "968fee23", "metadata": {}, "outputs": [], "source": [ "import os\n", "import configparser" ] }, { "cell_type": "code", "execution_count": 2, "id": "a836b0e7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['./secrets.ini']" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "config = configparser.ConfigParser()\n", "config.read('./secrets.ini')" ] }, { "cell_type": "code", "execution_count": 3, "id": "fef7bec8", "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": 4, "id": "c41f820a", "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", "id": "e995c9e3", "metadata": {}, "source": [ "### Get Stage Analyzer Prompt" ] }, { "cell_type": "code", "execution_count": 5, "id": "25c82b0d", "metadata": {}, "outputs": [], "source": [ "stage_analyzer_inception_prompt = load_prompt(\"./templates/stage_analyzer_inception_prompt_template.json\")\n", "llm = ChatOpenAI(model='gpt-3.5-turbo', temperature=0.0)\n", "stage_analyzer_chain = LLMChain(\n", " llm=llm,\n", " prompt=stage_analyzer_inception_prompt, \n", " verbose=True, \n", " output_key=\"stage_number\")" ] }, { "attachments": {}, "cell_type": "markdown", "id": "63824ec7", "metadata": {}, "source": [ "### Load wine database json" ] }, { "cell_type": "code", "execution_count": 6, "id": "d1228108", "metadata": {}, "outputs": [], "source": [ "df = pd.read_json('./data/unified_wine_data.json', encoding='utf-8', lines=True)" ] }, { "cell_type": "code", "execution_count": 7, "id": "4c2ca36f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | url\n", " | site_name\n", " | price\n", " | name\n", " | en_name\n", " | img_url\n", " | body\n", " | acidity\n", " | tannin\n", " | sweetness\n", " | alcohol\n", " | wine_type\n", " | country\n", " | grape\n", " | rating\n", " | pickup_location\n", " | vivino_link\n", " | 
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0\n", " | https://www.winenara.com/shop/product/product_...\n", " | winenara\n", " | 49000\n", " | 모노폴 클라시코\n", " | Monopole Classico\n", " | https://www.winenara.com/uploads/product/550/1...\n", " | 3\n", " | \n", " | \n", " | -1\n", " | -1\n", " | 화이트\n", " | 스페인\n", " | \n", " | 3.8\n", " | \n", " | https://www.vivino.com/monopole-la-rioja-blanc...\n", " | 
| 1\n", " | https://www.winenara.com/shop/product/product_...\n", " | winenara\n", " | 32000\n", " | 슐럼베르거 로제 스페셜 브뤼\n", " | Schlumberger Rose Special Brut\n", " | https://www.winenara.com/uploads/product/550/d...\n", " | 3\n", " | \n", " | \n", " | -1\n", " | -1\n", " | 스파클링\n", " | 독일\n", " | \n", " | 3.8\n", " | \n", " | https://www.vivino.com/schlumberger-spring-edi...\n", " | 
| 2\n", " | https://www.winenara.com/shop/product/product_...\n", " | winenara\n", " | 50000\n", " | SET)페데럴리스트 샤르도네 원통 패키지\n", " | SET)THE FEDERALIST CHARDONNAY\n", " | https://www.winenara.com/uploads/product/550/d...\n", " | 3\n", " | \n", " | \n", " | -1\n", " | -1\n", " | 화이트\n", " | 미국\n", " | \n", " | 3.7\n", " | \n", " | https://www.vivino.com/federalist-chardonnay-m...\n", " | 
| 3\n", " | https://www.winenara.com/shop/product/product_...\n", " | winenara\n", " | 55000\n", " | 베니카 트레 비니스\n", " | VENICA TRE VIGNIS\n", " | https://www.winenara.com/uploads/product/550/c...\n", " | 4\n", " | \n", " | \n", " | -1\n", " | -1\n", " | 화이트\n", " | 이탈리아\n", " | \n", " | 3.9\n", " | \n", " | https://www.vivino.com/US-CA/en/venica-venica-...\n", " | 
| 4\n", " | https://www.winenara.com/shop/product/product_...\n", " | winenara\n", " | 24900\n", " | SET)빌라엠비앙코 + 글라스2개 윈터패키지\n", " | SET)VILLA M Bianco + GLASS WINTER PACKAGE\n", " | https://www.winenara.com/uploads/product/550/a...\n", " | -1\n", " | \n", " | \n", " | 4\n", " | -1\n", " | 디저트\n", " | 이탈리아\n", " | \n", " | 3.9\n", " | \n", " | https://www.vivino.com/villa-m-bianco/w/1774733\n", " | 
\n", " LinkedIn Audrey.ai\n", "
\n", "