Spaces:
Runtime error
Runtime error
MSchell0129
commited on
Commit
·
871d89e
1
Parent(s):
7005d5d
- Dockerfile +1 -4
- general_chatbot.py +17 -9
Dockerfile
CHANGED
@@ -2,10 +2,7 @@ FROM python:3.9
|
|
2 |
WORKDIR /code
|
3 |
COPY ./requirements.txt /code/requirements.txt
|
4 |
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
5 |
-
|
6 |
-
USER user
|
7 |
-
ENV HOME=/home/user\
|
8 |
-
PATH=/home/user/.local/bin:$PATH
|
9 |
|
10 |
COPY . .
|
11 |
|
|
|
2 |
WORKDIR /code
|
3 |
COPY ./requirements.txt /code/requirements.txt
|
4 |
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
5 |
+
|
|
|
|
|
|
|
6 |
|
7 |
COPY . .
|
8 |
|
general_chatbot.py
CHANGED
@@ -4,27 +4,35 @@
|
|
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 |
-
|
15 |
-
|
|
|
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 |
-
{
|
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 |
-
|
|
|
4 |
# Interacting with APIs
|
5 |
# Code Understanding
|
6 |
|
|
|
7 |
from langchain.llms import OpenAI
|
8 |
from langchain import LLMChain
|
9 |
from langchain.prompts.prompt import PromptTemplate
|
10 |
+
from api_key import openai_api_key
|
11 |
from langchain.chains.conversation.memory import ConversationBufferMemory
|
12 |
import os
|
13 |
|
14 |
+
|
15 |
+
openai_api_key = openai_api_key
|
16 |
+
template = f"""
|
17 |
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
|
18 |
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.
|
19 |
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.
|
20 |
You should not be judemental.
|
21 |
+
Context: {{chat_history}}
|
22 |
+
Human: {{human_input}}
|
23 |
+
Chatbot:"""
|
24 |
+
|
25 |
+
prompt = PromptTemplate(
|
26 |
+
input_variables=["chat_history", "human_input"],
|
27 |
+
template = template
|
28 |
+
,
|
29 |
+
)
|
30 |
|
|
|
31 |
|
32 |
memory = ConversationBufferMemory(memory_key='chat_history')
|
33 |
|
34 |
+
llm_chain = LLMChain(llm=OpenAI(openai_api_key=openai_api_key), prompt=prompt, verbose=True, memory=memory)
|
35 |
+
|
36 |
+
response = llm_chain.predict(human_input='Hello, how are you?')
|
37 |
|
38 |
+
print(response)
|