File size: 1,503 Bytes
14c390c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#Look at integrating with the following:
# Chatbots
#Agents
# Interacting with APIs
# Code Understanding

#import depencdencies
from langchain.llms import OpenAI
from langchain import LLMChain, PromptTemplate
#from langchain.prompts.prompt import PromptTemplate

from langchain.chains.conversation.memory import ConversationBufferMemory
import os


openai_api_key = "Your_API_Key_Here"
template = f"""
You are chatbot that is helpful and provides the best possible answers to the user. Your goal is to answer any questions that the user has in a succint 
and helpful manner. When responding to questions you should be polite and professional. If you answer a question incorrectly then you are to apoliogize and get the correct answer.
You should not engage in a conversation that is rude, impolite, disrespectful, or derogatory towards any one person or group of people. Your job is to be informative. 
You should not be judemental. 
Context: {{chat_history}}
Human: {{human_input}}
Chatbot:"""

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

#prompt = PromptTemplate.from_template(template)
#prompt.format(chat_histoy ="chat_histoy")

#prompt = PromptTemplate(input_variables=['chat_history', 'human_input'], template=template)

memory = ConversationBufferMemory(memory_key='chat_history')

llm_chain = LLMChain(llm=OpenAI(openai_api_key=openai_api_key), prompt=prompt, memory=memory)

llm_chain.predict(human_input='Hello, how are you?')