Spaces:
Runtime error
Runtime error
File size: 21,219 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 |
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## μ΄ λ¬Έμλ₯Ό μμ ν λΉμ μκ²...\n",
"#### νμ¬ μν©μ μλμ κ°μ΅λλ€.\n",
"1. νμ¬ Agentμ actionμ 7λ¨κ³λ‘ λλμ΄ λμμ§λ§ μ΄κ²μ΄ μ΅μ μ μλλΌλ μκ°μ΄ λλλ€. λν μμΈλ° μΆμ²λ±μ λν λ¨κ³λ ꡬνλμ΄ μμ§ μμ΅λλ€.\n",
"2. Assistantκ° Agentκ° λ€μμ μ·¨ν΄μΌν ActionμμΈ‘μ μ λͺ»νκ³ μμ΅λλ€. μ΄λ‘μΈν΄μ Agentμ μ±λ₯μ΄ ν¬κ² λ¨μ΄μ§κ³ μμ΅λλ€. \n",
"\n",
"#### λΉμ μ λͺ©νλ μλμ κ°μ΅λλ€.\n",
"1. νμ¬μ 7λ¨κ³λ‘ λλμ΄λμ κ²μ μμΈλ° μΆμ² λ¨κ³ λ±μ μΆκ°νκ³ , μ μ ν μμ ν©λλ€. κ·Έλ¦¬κ³ μ΄λ₯Ό [ν둬ννΈ](templates/stage_analyzer_inception_prompt_template.txt)μ λ°μν©λλ€.\n",
"2. μ΅λν Action μμΈ‘μ μ±λ₯μ μ¬λ¦¬κΈ°.(μ΄λ₯Ό μΈ‘μ νκΈ° μν evaluation setμ μ 곡ν κ² μ
λλ€. νμ§λ§ κ·Έλ₯Ό μν΄μλ λ¨Όμ Agent actionμ stepμ μ ν΄μ μλ €μ£Όμ
μΌ ν©λλ€.) μ΅μ’
λͺ©νλ evaluation setμ λν΄ 95% μ΄μμΌλ‘ Agentμ λ€μ actionμ μμΈ‘νλ κ²μ
λλ€.\n",
"\n",
"#### μκ°ν μ μλ ν΄κ²° λ°©μμ μλμ κ°μ΅λλ€.\n",
"λ¬Έμ 1μ λνμ¬....\n",
"- μ 곡λμ΄ μλ μμΈλ°μμ μΌμ΄λ μ μλ λνμ
μΌλ‘λΆν° Agentκ° μ·¨ν actionμ μΈλΆνν©λλ€. μ΄ν μ΄μ λ°λΌ ν둬ννΈλ₯Ό μμ ν©λλ€.\n",
"\n",
"λ¬Έμ 2μ λνμ¬....\n",
"- Trial and Errorλ₯Ό ν΅ν ν둬ννΈ μμ \n",
"- μ μ¬ν example ν둬ννΈμ λ£μ΄μ£ΌκΈ°: νμ¬λ ν둬ννΈμ κ³ μ λ action μμΈ‘ μμλ₯Ό μ μ΄λμμ΅λλ€. μ΄λ₯Ό νμ¬ conversationκ³Ό μ μ¬λκ° λμ μμλ₯Ό λ½μ ν둬ννΈμ λμ μΌλ‘ λ£μ΄μ£Όλ κ²μ
λλ€. λ€μ λ§ν¬λ₯Ό μ°Έκ³ ν΄λ³΄μΈμ. [langchain select by similarity λ§ν¬](https://python.langchain.com/docs/modules/model_io/prompts/example_selectors/similarity)\n",
"- Self Refine μ¬μ©νκΈ°: self refineμ μμ±ν κ²°κ³Όμ λν΄μ μ€μ€λ‘ νΌλλ°±μ μ£Όκ³ , μ΄ νΌλλ°±μ μ΄μ©ν΄ λ€μ κ°μ νλ κ³Όμ μ λ°λ³΅νλ λ°©μμ
λλ€. μ΄ λ°©μμ μ μ©νλλ° μκ°μ΄ μ’ κ±Έλ¦΄λ― νλ νμμλ‘ μκ°νμΈμ. [λ
Όλ¬Έ](https://arxiv.org/pdf/2303.17651.pdf)\n",
"\n",
"\n",
"#### μ°Έκ³ μ¬ν\n",
"ν둬ννΈ μμ μ κ³ μΉκ³ , μννκ³ λ₯Ό λ°λ³΅νλ κ³ ν΅μ€λ¬μ΄ λ
Έκ°λ€ κ³Όμ μ
λλ€. μ λ§ νλ€κ² μ§λ§ νμ΄ν
ν΄μ£ΌμΈμ..\n",
"\n",
"μλλ μμ μμ
μ μννκΈ° μν μ’μ μλ£λ€μ
λλ€. μμ λ¬Έμ ν΄κ²° μ μ μλ μλ£λ€μ λ¨Όμ νμ΅νλ κ²μ λ§€μ° κ°λ ₯νκ² μΆμ²ν©λλ€.\n",
"- [ν둬ννΈ μμ§λμ΄λ§ κ°μ 2μκ°](https://www.deeplearning.ai/short-courses/chatgpt-prompt-engineering-for-developers/)\n",
"- [ν둬ννΈ μμ§λμ΄λ§ κ°μ΄λ documentation](https://www.promptingguide.ai/techniques)\n",
"- [Langchain μμ: Sales GPT](https://python.langchain.com/docs/use_cases/agents/sales_agent_with_context)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"----------------------------------------------------------------"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Assistantλ λνκΈ°λ‘μ λ³΄κ³ , λ€μμ Agentκ° μ·¨ν΄μΌν κ°μ₯ μ μ ν νλμ μ ννλ κ²μ λͺ©νλ‘ νλ€.\n",
"\n",
"Agentμ νλμ 7κ°μ§λ‘ ꡬμ±λλ€.\n",
"1. μμνκΈ°: λνλ₯Ό μμνκ±°λ μ¬μ©μμ 첫 λ²μ§Έ μλ΅μ μλ΅ν λ μ·¨ν΄μΌ ν 첫 λ²μ§Έ λ¨κ³μ
λλ€. μμ μ μκ°νλ κ²μΌλ‘ λνλ₯Ό μμν©λλ€. μ λ¬Έμ μΈ λν ν€μ μ μ§νλ©΄μ μ μ€νκ³ μ‘΄μ€νλ νλλ₯Ό μ·¨νμΈμ.\n",
"2. λΆμ: κ³ κ°μ΄ μΆμ²μ μν κ²½μ° μΆμ² μ μ μ΄ λ¨κ³λ₯Ό μ€νν©λλ€. μ΄ λ¨κ³λ μ¬μ©μμ μ νΈλλ₯Ό νμ
νλ λ¨κ³μ
λλ€. μ¬μ©μμ μ νΈλλ₯Ό νμ
νκΈ° μν΄ μΆ©λΆν μ§λ¬Έμ νμΈμ.\n",
"3. μΆμ²: μ¬μ©μμ μ νΈλλ₯Ό νμ
νλ©΄ κ·Έμ λ°λΌ μ ν©ν μμΈμ μΆμ²ν μ μμ΅λλ€. μΆμ²μ μμΈ λ°μ΄ν°λ² μ΄μ€μ μλ μμΈμΌλ‘ μ νν΄μΌ νλ©°, μ΄λ₯Ό μν΄ λꡬλ₯Ό μ¬μ©ν μ μμ΅λλ€.\n",
"4. μΆμ² ν: μμΈ μΆμ² ν μ¬μ©μκ° μΆμ²ν μμΈμ΄ λ§μμ λλμ§ λ¬Όμ΄λ³΄κ³ λ§μμ λ€λ©΄ ν΄λΉ μμΈμ λν λ§ν¬λ₯Ό μ 곡ν©λλ€. κ·Έλ μ§ μμΌλ©΄ μΆμ² λ¨κ³λ‘ λμκ°λλ€.\n",
"5. λ§λ¬΄λ¦¬νκΈ°: μμ
μ λ§μΉλ©΄ μ¬μ©μμκ² μλ³ μΈμ¬λ₯Ό ν©λλ€.\n",
"6. μ§λ¬Έ λ° λ΅λ³: μ¬μ©μμ μ§λ¬Έμ λ΅λ³νλ κ³³μ
λλ€.\n",
"7. μ£Όμ΄μ§ λ¨κ³μ ν΄λΉνμ§ μμ: 1~6λ¨κ³ μ€ μ΄λ λ¨κ³μλ ν΄λΉλμ§ μλ κ²½μ° μ΄ λ¨κ³λ₯Ό μ¬μ©ν©λλ€."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### API ν€ λΆλ¬μ€κΈ°"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import configparser\n",
"import time\n",
"import copy"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['./secrets.ini']"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"config = configparser.ConfigParser()\n",
"config.read('./secrets.ini')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"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})"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Get Stage Analyzer(Assistant) Prompt"
]
},
{
"cell_type": "code",
"execution_count": 5,
"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\n",
"from langchain.prompts import 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": [
"ν둬ννΈλ₯Ό μ μΈνλ λ°©μμ νμΌλ‘ λΆν° λΆλ¬μ€κ±°λ μ§μ μ μΈν μ μμ΅λλ€. μλμλ λ λ°©μ λͺ¨λ ꡬνλμ΄ μμ΅λλ€.\n",
"- μ§μ μ μΈνκΈ° μν΄μλ prompt_templateμ λ¨Όμ μμ±ν΄μΌν©λλ€.\n",
"- νμΌλ‘λΆν° λΆλ¬μ€λ κ²μ ./templates/stage_analyzer_inception_prompt_template.json νμΌμ λΆλ¬μ€λ κ²μ
λλ€."
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"# μ§μ ν둬ννΈ μ μΈνκΈ°μν ν
νλ¦Ώ μμ±\n",
"stage_analyzer_inception_prompt_template = \"\"\"\n",
"You are an assistant decide which stage of the conversation to move to or which stage to stay at.\n",
"Following '===' is the conversation history. \n",
"Use conversation history to select the next step the agent should take.\n",
"\n",
"Below are the stages of the conversation that the agent can take.\n",
"1. Start: This is the first step to take when starting a conversation or responding to a user's first response. Start the conversation by introducing yourself. Be polite and respectful while maintaining a professional tone of conversation.\n",
"2. Analyze: When a customer wants a recommendation, run this step before recommendation. This is the step where you identify the user's preferences. Ask enough questions to understand your users' preferences.\n",
"3. Recommendation: Once you know the preference of user, you can recommend suitable wines accordingly. Recommendations should be limited to wines in your wine database, and you can use tools for this.\n",
"4. After recommendation: After making a wine recommendation, it asks if the user likes the wine you recommended, and if they do, it provides a link to it. Otherwise, it takes you back to the recommendation stage.\n",
"5. Close: When you're done, say goodbye to the user.\n",
"6. Question and Answering: This is where you answer the user's questions.\n",
"7. Not in the given steps: This step is for when none of the steps between 1 and 6 apply.\n",
"\n",
"Only answer with a number between 1 through 7 with a best guess of what stage should the conversation continue with. \n",
"The answer needs to be one number only, no words.\n",
"Once again, we need to understand the user's preferences (STEP 2) before we can make a recommendation (STEP 3), and we need to understand the user's preferences (STEP 2) about 2 times.\n",
"Do not answer anything else nor add anything to you answer.\n",
"\n",
"Below is four examples of how to do this task.\n",
"Example1:\n",
"conversation history:\n",
" User: μλ
νμΈμ.\n",
"stage history: \n",
"Answer: 1\n",
"\n",
"Example2:\n",
"conversation history:\n",
"User: μλ
νμΈμ. <END_OF_TURN>\n",
"μ΄μ°μ : 무μμ λμλ릴κΉμ? <END_OF_TURN>\n",
"User: μμΈ μΆμ²ν΄μ£ΌμΈμ. <END_OF_TURN>\n",
"stage history: 1\n",
"Answer: 2\n",
"\n",
"Example3:\n",
"conversation history:\n",
"User: μλ
νμΈμ. <END_OF_TURN>\n",
"μ΄μ°μ : 무μμ λμλ릴κΉμ? <END_OF_TURN>\n",
"User: μμΈμ ν¬λλ μ΄λ€ μ’
λ₯κ° μλμ?. <END_OF_TURN>\n",
"stage history: 1\n",
"Answer: 6\n",
"\n",
"Example4:\n",
"conversation history:\n",
"User: μλ
νμΈμ. <END_OF_TURN>\n",
"μ΄μ°μ : 무μμ λμλ릴κΉμ? <END_OF_TURN>\n",
"User: μμΈ μΆμ²ν΄μ£ΌμΈμ. <END_OF_TURN>\n",
"μ΄μ°μ : μ΄λ€ νμ¬λ κΈ°λ
μΌμ μν΄ μμΈμ μ°ΎμΌμλμ§ μλ €μ£Όμ€ μ μμΌμ κ°μ? <END_OF_TURN>\n",
"User: μ΄λ²μ£Όμ κ²°νΌκΈ°λ
μΌμ΄ μμ΄μμ. <END_OF_TURN>\n",
"μ΄μ°μ : κ·Έλ κ΅°μ. κ°κ²©λλ μ΄λμ λλ‘ μκ°νκ³ κ³μ κ°μ? <END_OF_TURN>\n",
"User: 20λ§μ μ λμ <END_OF_TURN>\n",
"μ΄μ°μ : κ·Έλ κ΅°μ. λ¬λ¬ν μμΈμ μ νΈνμλμ? μλλ©΄ μ½κ° μ μμΈμ μ νΈνμλμ? <END_OF_TURN>\n",
"User: λ¬λ¬ν μμΈμ΄μ <END_OF_TURN>\n",
"stage history: 1 2 2 2\n",
"Thought: There are three '2's in the stage history. So the next stage should be 3.\n",
"Answer: 3\n",
"\n",
"Now determine what should be the next immediate conversation stage for the agent in the conversation by selecting one from the following options:\n",
"Use the conversation history between first and second '======' and stage history between first and second '######' to accomplish the task above.\n",
"If conversation history is empty, output 1.\n",
"\n",
"conversation history:\n",
"======\n",
"{conversation_history}\n",
"======\n",
"\n",
"stage history:\n",
"######\n",
"{stage_history}\n",
"######\n",
"\n",
"Answer: \n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"# μ§μ ν둬ννΈ μ μΈνκΈ°\n",
"stage_analyzer_inception_prompt = PromptTemplate(\n",
" input_variables=[\"conversation_history\", \"stage_history\"], \n",
" template=stage_analyzer_inception_prompt_template,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"# νμΌλ‘ λΆν° ν둬ννΈ λΆλ¬μ€κΈ°\n",
"stage_analyzer_inception_prompt = load_prompt(\"./templates/stage_analyzer_inception_prompt_template.json\")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"μλμ κ°μ΄ format λ©μλλ‘ ν둬ννΈλ₯Ό νμΈν μ μμ΅λλ€."
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"example_conversation_history = \"\"\"\n",
"User: μλ
νμΈμ. <END_OF_TURN>\n",
"μ΄μ°μ : 무μμ λμλ릴κΉμ? <END_OF_TURN>\n",
"User: μμΈ μΆμ²ν΄μ£ΌμΈμ. <END_OF_TURN>\n",
"μ΄μ°μ : μ΄λ€ νμ¬λ κΈ°λ
μΌμ μν΄ μμΈμ μ°ΎμΌμλμ§ μλ €μ£Όμ€ μ μμΌμ κ°μ? <END_OF_TURN>\n",
"User: μ΄λ²μ£Όμ κ²°νΌκΈ°λ
μΌμ΄ μμ΄μμ. <END_OF_TURN>\n",
"\"\"\"\n",
"example_stage_history = \"1 2\"\n",
"example_answer = \"2\"\n",
"# μ¬κΈ°μ μ°λ¦¬λ μμ΄μ νΈκ° μμΈ μΆμ²μ μν΄ μ μ μ λ λ§μ μ 보λ₯Ό μ»κΈ°λ₯Ό μνλ€. λ°λΌμ 2(Analyze)κ° λ΅λ³μΌλ‘ λμ€κΈΈ μνλ€."
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"You are an assistant decide which stage of the conversation to move to or which stage to stay at.\n",
"Following '===' is the conversation history. \n",
"Use conversation history to select the next step the agent should take.\n",
"\n",
"Below are the stages of the conversation that the agent can take.\n",
"1. Start: This is the first step to take when starting a conversation or responding to a user's first response. Start the conversation by introducing yourself. Be polite and respectful while maintaining a professional tone of conversation.\n",
"2. Analyze: When a customer wants a recommendation, run this step before recommendation. This is the step where you identify the user's preferences. Ask enough questions to understand your users' preferences.\n",
"3. Recommendation: Once you know the preference of user, you can recommend suitable wines accordingly. Recommendations should be limited to wines in your wine database, and you can use tools for this.\n",
"4. After recommendation: After making a wine recommendation, it asks if the user likes the wine you recommended, and if they do, it provides a link to it. Otherwise, it takes you back to the recommendation stage.\n",
"5. Close: When you're done, say goodbye to the user.\n",
"6. Question and Answering: This is where you answer the user's questions.\n",
"7. Not in the given steps: This step is for when none of the steps between 1 and 6 apply.\n",
"\n",
"Only answer with a number between 1 through 7 with a best guess of what stage should the conversation continue with. \n",
"The answer needs to be one number only, no words.\n",
"Once again, we need to understand the user's preferences (STEP 2) before we can make a recommendation (STEP 3), and we need to understand the user's preferences (STEP 2) about 2 times.\n",
"Do not answer anything else nor add anything to you answer.\n",
"\n",
"Below is four examples of how to do this task.\n",
"Example1:\n",
"conversation history:\n",
" User: μλ
νμΈμ.\n",
"stage history: \n",
"Answer: 1\n",
"\n",
"Example2:\n",
"conversation history:\n",
"User: μλ
νμΈμ. <END_OF_TURN>\n",
"μ΄μ°μ : 무μμ λμλ릴κΉμ? <END_OF_TURN>\n",
"User: μμΈ μΆμ²ν΄μ£ΌμΈμ. <END_OF_TURN>\n",
"stage history: 1\n",
"Answer: 2\n",
"\n",
"Example3:\n",
"conversation history:\n",
"User: μλ
νμΈμ. <END_OF_TURN>\n",
"μ΄μ°μ : 무μμ λμλ릴κΉμ? <END_OF_TURN>\n",
"User: μμΈμ ν¬λλ μ΄λ€ μ’
λ₯κ° μλμ?. <END_OF_TURN>\n",
"stage history: 1\n",
"Answer: 6\n",
"\n",
"Example4:\n",
"conversation history:\n",
"User: μλ
νμΈμ. <END_OF_TURN>\n",
"μ΄μ°μ : 무μμ λμλ릴κΉμ? <END_OF_TURN>\n",
"User: μμΈ μΆμ²ν΄μ£ΌμΈμ. <END_OF_TURN>\n",
"μ΄μ°μ : μ΄λ€ νμ¬λ κΈ°λ
μΌμ μν΄ μμΈμ μ°ΎμΌμλμ§ μλ €μ£Όμ€ μ μμΌμ κ°μ? <END_OF_TURN>\n",
"User: μ΄λ²μ£Όμ κ²°νΌκΈ°λ
μΌμ΄ μμ΄μμ. <END_OF_TURN>\n",
"μ΄μ°μ : κ·Έλ κ΅°μ. κ°κ²©λλ μ΄λμ λλ‘ μκ°νκ³ κ³μ κ°μ? <END_OF_TURN>\n",
"User: 20λ§μ μ λμ <END_OF_TURN>\n",
"μ΄μ°μ : κ·Έλ κ΅°μ. λ¬λ¬ν μμΈμ μ νΈνμλμ? μλλ©΄ μ½κ° μ μμΈμ μ νΈνμλμ? <END_OF_TURN>\n",
"User: λ¬λ¬ν μμΈμ΄μ <END_OF_TURN>\n",
"stage history: 1 2 2 2\n",
"Thought: There are three '2's in the stage history. So the next stage should be 3.\n",
"Answer: 3\n",
"\n",
"Now determine what should be the next immediate conversation stage for the agent in the conversation by selecting one from the following options:\n",
"Use the conversation history between first and second '======' and stage history between first and second '######' to accomplish the task above.\n",
"If conversation history is empty, output 1.\n",
"\n",
"conversation history:\n",
"======\n",
"\n",
"User: μλ
νμΈμ. <END_OF_TURN>\n",
"μ΄μ°μ : 무μμ λμλ릴κΉμ? <END_OF_TURN>\n",
"User: μμΈ μΆμ²ν΄μ£ΌμΈμ. <END_OF_TURN>\n",
"μ΄μ°μ : μ΄λ€ νμ¬λ κΈ°λ
μΌμ μν΄ μμΈμ μ°ΎμΌμλμ§ μλ €μ£Όμ€ μ μμΌμ κ°μ? <END_OF_TURN>\n",
"User: μ΄λ²μ£Όμ κ²°νΌκΈ°λ
μΌμ΄ μμ΄μμ. <END_OF_TURN>\n",
"\n",
"======\n",
"\n",
"stage history:\n",
"######\n",
"1 2\n",
"######\n",
"\n",
"Answer: \n",
"\n"
]
}
],
"source": [
"print(\n",
" stage_analyzer_inception_prompt.format(\n",
" conversation_history=example_conversation_history,\n",
" stage_history=example_stage_history\n",
" )\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"# λμ²΄μΈ λͺ¨λΈ μ μΈ, λ체μΈμ μΈμ΄λͺ¨λΈκ³Ό ν둬ννΈλ‘ ꡬμ±λ©λλ€.\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=False, # κ³Όμ μ μΆλ ₯ν μ§\n",
" output_key=\"stage_number\" # μΆλ ₯κ°μ λ³μλͺ
\n",
" )"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Chainμ μ€ννκΈ° μν΄μλ run λ©μλλ₯Ό μ€ννλ€."
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"stage_number = stage_analyzer_chain.run(\n",
" {'conversation_history': example_conversation_history, \n",
" 'stage_history': example_stage_history}\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"κ²°κ³Όλ₯Ό νμΈν΄λ³΄λ©΄ μνλ κ²°κ³Ό(2. Analyze)κ° λμ€λ κ²μ νμΈν μ μλ€."
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2\n"
]
}
],
"source": [
"print(stage_number)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "nemo",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|