|
{ |
|
"cells": [ |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"from langchain import OpenAI\n", |
|
"from langchain.chat_models import ChatOpenAI\n", |
|
"from langchain.prompts import PromptTemplate\n", |
|
"from langchain.chains import LLMChain\n", |
|
"from langchain.document_loaders import TextLoader\n", |
|
"\n", |
|
"\n", |
|
"from pathlib import Path\n", |
|
"import os\n", |
|
"\n", |
|
"os.environ[\"OPENAI_API_KEY\"] = \"\"\n", |
|
"\n", |
|
"path = Path().home() / \"Documents\" / \"csv1.csv\"\n", |
|
"loader = TextLoader(path)\n", |
|
"document = loader.load()\n", |
|
"\n", |
|
"\n", |
|
"path2 = Path().home() / \"Documents\" / \"csv2.csv\"\n", |
|
"loader2 = TextLoader(path2)\n", |
|
"document2 = loader2.load()\n", |
|
"\n", |
|
"prompt_template = \"\"\"Following are two lists of Event Titles, Dates and Descriptions in the format <Title>;<Date>:\n", |
|
"<Description>\n", |
|
"{csv1}\n", |
|
"\n", |
|
"{csv2}\n", |
|
"\n", |
|
"TASKS: \n", |
|
"1. Show matching string values of the two lists\n", |
|
"2. Based on these matches, provide a natural sounding conversation starter \n", |
|
"\n", |
|
"\"\"\"\n", |
|
"prompt = PromptTemplate.from_template(prompt_template)\n", |
|
"\n", |
|
"llm = OpenAI (temperature=0)\n", |
|
"chain = LLMChain(llm=llm, prompt=prompt)\n", |
|
"response = chain({\"csv1\": document[0].page_content, \"csv2\": document2[0].page_content})\n", |
|
"\n", |
|
"\n", |
|
"print(response['text'])" |
|
] |
|
} |
|
], |
|
"metadata": { |
|
"language_info": { |
|
"name": "python" |
|
}, |
|
"orig_nbformat": 4 |
|
}, |
|
"nbformat": 4, |
|
"nbformat_minor": 2 |
|
} |
|
|