Spaces:
Runtime error
Runtime error
MSchell0129
commited on
Commit
·
7005d5d
1
Parent(s):
562b6f8
created general chatbot
Browse files- general_chatbot.py +24 -1
general_chatbot.py
CHANGED
@@ -4,4 +4,27 @@
|
|
4 |
# Interacting with APIs
|
5 |
# Code Understanding
|
6 |
|
7 |
-
#import depencdencies
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
# Interacting with APIs
|
5 |
# Code Understanding
|
6 |
|
7 |
+
#import depencdencies
|
8 |
+
from langchain.llms import OpenAI
|
9 |
+
from langchain import LLMChain
|
10 |
+
from langchain.prompts.prompt import PromptTemplate
|
11 |
+
from langchain.chains.conversation.memory import ConversationBufferMemory
|
12 |
+
import os
|
13 |
+
|
14 |
+
openai_api_key = os.environ.get('OPENAI_API_KEY')
|
15 |
+
template = '''
|
16 |
+
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
|
17 |
+
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.
|
18 |
+
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.
|
19 |
+
You should not be judemental.
|
20 |
+
{chat_histoy}
|
21 |
+
Human: {human_input}
|
22 |
+
Chatbot:'''
|
23 |
+
|
24 |
+
prompt = PromptTemplate(input_variables=['chat_history', 'human_input'], template=template)
|
25 |
+
|
26 |
+
memory = ConversationBufferMemory(memory_key='chat_history')
|
27 |
+
|
28 |
+
llm_chain = LLMChain(llm=OpenAI(openai_api_key=openai_api_key), prompt=prompt, memory=memory)
|
29 |
+
|
30 |
+
llm_chain.predict(human_input='Hello, how are you?')
|