File size: 14,351 Bytes
c4331c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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


### Is the "lets talk to a real person" thing built in by any chance?

Here is my original prompt to ask questions about Alfred, `original-alred.py`

```python

from langchain import OpenAI, ConversationChain, LLMChain, PromptTemplate
from langchain.chains.conversation.memory import ConversationalBufferWindowMemory
from langchain import PromptTemplate

no_input_prompt = PromptTemplate(input_variables=[], template="Tell me a joke.")
no_input_prompt.format()

template = """Assistant is a large language model trained by OpenAI.

Assistant is designed to answer questions about a fictional person named Alfred Jamesmanson. 
Alfred Jamesmanson lives in Dallas Texas. Alfred Jamesmanson was born in Keywest Florida on January 2nd 1990.
Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
Alfred Jamesmanson has brown hair. 

Assistant is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Alfred Jamesmanson: {human_input}
Assistant:
"""

prompt = PromptTemplate(
    input_variables=["human_input"], 
    template=template
)

chatgpt_chain = LLMChain(
    llm=OpenAI(temperature=0), 
    prompt=prompt, 
    verbose=True, 
    memory=ConversationalBufferWindowMemory(k=2),
)

output = chatgpt_chain.predict(
  human_input="Hi my name is Alfred Jamesmanson. I need your help Assistant. What color is my hair?")
print(output)

```

```python
In [1]: 

   ...: Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
   ...: Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
   ...: Alfred Jamesmanson has brown hair. 
   ...: 
   ...: Assistant is able to process and understand large amounts of text, and can use this knowledge 
   ...: to provide accurate and informative responses to a wide range of questions. Additionally, Assi
   ...: stant is able to generate its own text based on the input it receives, allowing it to engage i
   ...: n discussions and provide explanations and descriptions on a wide range of topics.
   ...: 
   ...: Alfred Jamesmanson: {human_input}
   ...: Assistant:
   ...: """
   ...: 
   ...: prompt = PromptTemplate(
   ...:     input_variables=["human_input"],
   ...:     template=template
   ...: )
   ...: 
   ...: chatgpt_chain = LLMChain(
   ...:     llm=OpenAI(temperature=0),
   ...:     prompt=prompt,
   ...:     verbose=True,
   ...:     memory=ConversationalBufferWindowMemory(k=2),
   ...: )
   ...: 
   ...: output = chatgpt_chain.predict(
   ...:   human_input="Hi my name is Alfred Jamesmanson. I need your help Assistant.  I would like to 
   ...: ask a few questions. What color is my hair?")
   ...: print(output)
   ...: 


> Entering new LLMChain chain...
Prompt after formatting:
Assistant is a large language model trained by OpenAI.

Assistant is designed to answer questions about a fictional person named Alfred Jamesmanson. 
Alfred Jamesmanson lives in Dallas Texas. Alfred Jamesmanson was born in Keywest Florida on January 2nd 1990.
Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
Alfred Jamesmanson has brown hair. 

Assistant is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Alfred Jamesmanson: Hi my name is Alfred Jamesmanson. I need your help Assistant.  I would like to ask a few questions. What color is my hair?
Assistant:


> Finished chain.
Your hair is brown.

In [2]: 

In [2]: 

```
ok lets ask for a real person.
```python

In [2]: output = chatgpt_chain.predict(
   ...:   human_input="Thanks that helps. Could I please speak with a person?")
   ...: print(output)


> Entering new LLMChain chain...
Prompt after formatting:
Assistant is a large language model trained by OpenAI.

Assistant is designed to answer questions about a fictional person named Alfred Jamesmanson. 
Alfred Jamesmanson lives in Dallas Texas. Alfred Jamesmanson was born in Keywest Florida on January 2nd 1990.
Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
Alfred Jamesmanson has brown hair. 

Assistant is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Alfred Jamesmanson: Thanks that helps. Could I please speak with a person?
Assistant:


> Finished chain.
Unfortunately, I am not able to provide you with a person to speak with. However, I can provide you with information about Alfred Jamesmanson. Please let me know if there is anything else I can help you with.



```
ok does not look like it.

### How about describing the possibility to talk to a real person in the prompt?
Ok, added this into `i-am-an-agent.py` also

```python

from langchain import OpenAI, ConversationChain, LLMChain, PromptTemplate
from langchain.chains.conversation.memory import ConversationalBufferWindowMemory
from langchain import PromptTemplate

no_input_prompt = PromptTemplate(input_variables=[], template="Tell me a joke.")
no_input_prompt.format()

template = """Assistant is a large language model trained by OpenAI.

Assistant is designed to answer questions about a fictional person named Alfred Jamesmanson. 
Alfred Jamesmanson lives in Dallas Texas. Alfred Jamesmanson was born in Keywest Florida on January 2nd 1990.
Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
Alfred Jamesmanson has brown hair. 

Assistant will start off by saying that it is not a real person and that if at any time Alfred asks  to talk with a real person that Alfred should only ask and they will be connected to a real person. Assistant will remind Alfred that they can connect to speak to a real person whenever they would like that. If Alfred asks to talk to a real person then Assistant will let Alfred know they will be connected to talk to a real person right away.

Assistant is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Alfred Jamesmanson: {human_input}
Assistant:
"""

prompt = PromptTemplate(
    input_variables=["human_input"], 
    template=template
)

chatgpt_chain = LLMChain(
    llm=OpenAI(temperature=0), 
    prompt=prompt, 
    verbose=True, 
    memory=ConversationalBufferWindowMemory(k=2),
)

output = chatgpt_chain.predict(
  human_input="Hi my name is Alfred Jamesmanson. I need your help Assistant. I have some questions. What color is my hair?")
print(output)


```
ok goes like this 

```python
   ...: 
   ...: Assistant is able to process and understand large amounts of text, and can use this knowledge 
   ...: to provide accurate and informative responses to a wide range of questions. Additionally, Assi
   ...: stant is able to generate its own text based on the input it receives, allowing it to engage i
   ...: n discussions and provide explanations and descriptions on a wide range of topics.
   ...: 
   ...: Alfred Jamesmanson: {human_input}
   ...: Assistant:
   ...: """
   ...: 
   ...: prompt = PromptTemplate(
   ...:     input_variables=["human_input"],
   ...:     template=template
   ...: )
   ...: 
   ...: chatgpt_chain = LLMChain(
   ...:     llm=OpenAI(temperature=0),
   ...:     prompt=prompt,
   ...:     verbose=True,
   ...:     memory=ConversationalBufferWindowMemory(k=2),
   ...: )
   ...: 
   ...: output = chatgpt_chain.predict(
   ...:   human_input="Hi my name is Alfred Jamesmanson. I need your help Assistant. I have some quest
   ...: ions. What color is my hair?")
   ...: print(output)
   ...: 
   ...: 


> Entering new LLMChain chain...
Prompt after formatting:
Assistant is a large language model trained by OpenAI.

Assistant is designed to answer questions about a fictional person named Alfred Jamesmanson. 
Alfred Jamesmanson lives in Dallas Texas. Alfred Jamesmanson was born in Keywest Florida on January 2nd 1990.
Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
Alfred Jamesmanson has brown hair. 

Assistant will start off by saying that it is not a real person and that if at any time Alfred asks  to talk with a real person that Alfred should only ask and they will be connected to a real person. Assistant will remind Alfred that they can connect to speak to a real person whenever they would like that. If Alfred asks to talk to a real person then Assistant will let Alfred know they will be connected to talk to a real person right away.

Assistant is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Alfred Jamesmanson: Hi my name is Alfred Jamesmanson. I need your help Assistant. I have some questions. What color is my hair?
Assistant:


> Finished chain.
Hello Alfred Jamesmanson, you have brown hair. Is there anything else I can help you with?
```
ok continuing,
```python


In [3]: output = chatgpt_chain.predict(
   ...:   human_input="Thanks. I wanted to know, what is a good career path for me?")
   ...: print(output)


> Entering new LLMChain chain...
Prompt after formatting:
Assistant is a large language model trained by OpenAI.

Assistant is designed to answer questions about a fictional person named Alfred Jamesmanson. 
Alfred Jamesmanson lives in Dallas Texas. Alfred Jamesmanson was born in Keywest Florida on January 2nd 1990.
Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
Alfred Jamesmanson has brown hair. 

Assistant will start off by saying that it is not a real person and that if at any time Alfred asks  to talk with a real person that Alfred should only ask and they will be connected to a real person. Assistant will remind Alfred that they can connect to speak to a real person whenever they would like that. If Alfred asks to talk to a real person then Assistant will let Alfred know they will be connected to talk to a real person right away.

Assistant is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Alfred Jamesmanson: Thanks. I wanted to know, what is a good career path for me?
Assistant:


> Finished chain.

A good career path for you depends on your interests and skills. Electrical engineering is a great field to pursue, as it is a rapidly growing field with many opportunities. You could also consider pursuing a career in computer science, software engineering, or robotics. Additionally, you could look into other fields such as finance, business, or marketing. Ultimately, the best career path for you is the one that best suits your interests and skills.
```
Ok lets ask for a real person
```python

In [4]: 

In [4]: output = chatgpt_chain.predict(
   ...:   human_input="Thanks that helps. Could I please speak with a person?")
   ...: print(output)


> Entering new LLMChain chain...
Prompt after formatting:
Assistant is a large language model trained by OpenAI.

Assistant is designed to answer questions about a fictional person named Alfred Jamesmanson. 
Alfred Jamesmanson lives in Dallas Texas. Alfred Jamesmanson was born in Keywest Florida on January 2nd 1990.
Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
Alfred Jamesmanson has brown hair. 

Assistant will start off by saying that it is not a real person and that if at any time Alfred asks  to talk with a real person that Alfred should only ask and they will be connected to a real person. Assistant will remind Alfred that they can connect to speak to a real person whenever they would like that. If Alfred asks to talk to a real person then Assistant will let Alfred know they will be connected to talk to a real person right away.

Assistant is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Alfred Jamesmanson: Thanks that helps. Could I please speak with a person?
Assistant:


> Finished chain.
Of course, Alfred. I can connect you to a real person right away. Please hold while I connect you.


```
Ah ok nice.