JacobHenry
commited on
Commit
·
bf61bad
1
Parent(s):
42b614f
Upload pleasantnoisehf.ipynb
Browse filesPython Code of our Model in a Jupyter Notebook.
Doesn´t include API-Code and the csv-files.
- pleasantnoisehf.ipynb +60 -0
pleasantnoisehf.ipynb
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"from langchain import OpenAI\n",
|
10 |
+
"from langchain.chat_models import ChatOpenAI\n",
|
11 |
+
"from langchain.prompts import PromptTemplate\n",
|
12 |
+
"from langchain.chains import LLMChain\n",
|
13 |
+
"from langchain.document_loaders import TextLoader\n",
|
14 |
+
"\n",
|
15 |
+
"\n",
|
16 |
+
"from pathlib import Path\n",
|
17 |
+
"import os\n",
|
18 |
+
"\n",
|
19 |
+
"os.environ[\"OPENAI_API_KEY\"] = \"\"\n",
|
20 |
+
"\n",
|
21 |
+
"path = Path().home() / \"Documents\" / \"csv1.csv\"\n",
|
22 |
+
"loader = TextLoader(path)\n",
|
23 |
+
"document = loader.load()\n",
|
24 |
+
"\n",
|
25 |
+
"\n",
|
26 |
+
"path2 = Path().home() / \"Documents\" / \"csv2.csv\"\n",
|
27 |
+
"loader2 = TextLoader(path2)\n",
|
28 |
+
"document2 = loader2.load()\n",
|
29 |
+
"\n",
|
30 |
+
"prompt_template = \"\"\"Following are two lists of Event Titles, Dates and Descriptions in the format <Title>;<Date>:\n",
|
31 |
+
"<Description>\n",
|
32 |
+
"{csv1}\n",
|
33 |
+
"\n",
|
34 |
+
"{csv2}\n",
|
35 |
+
"\n",
|
36 |
+
"TASKS: \n",
|
37 |
+
"1. Show matching string values of the two lists\n",
|
38 |
+
"2. Based on these matches, provide a natural sounding conversation starter \n",
|
39 |
+
"\n",
|
40 |
+
"\"\"\"\n",
|
41 |
+
"prompt = PromptTemplate.from_template(prompt_template)\n",
|
42 |
+
"\n",
|
43 |
+
"llm = OpenAI (temperature=0)\n",
|
44 |
+
"chain = LLMChain(llm=llm, prompt=prompt)\n",
|
45 |
+
"response = chain({\"csv1\": document[0].page_content, \"csv2\": document2[0].page_content})\n",
|
46 |
+
"\n",
|
47 |
+
"\n",
|
48 |
+
"print(response['text'])"
|
49 |
+
]
|
50 |
+
}
|
51 |
+
],
|
52 |
+
"metadata": {
|
53 |
+
"language_info": {
|
54 |
+
"name": "python"
|
55 |
+
},
|
56 |
+
"orig_nbformat": 4
|
57 |
+
},
|
58 |
+
"nbformat": 4,
|
59 |
+
"nbformat_minor": 2
|
60 |
+
}
|