File size: 1,647 Bytes
bf61bad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "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
}