jerpint commited on
Commit
e16fc27
·
unverified ·
1 Parent(s): c5f5dc3

Add hf transformers bot (#24)

Browse files
Files changed (1) hide show
  1. app.py +42 -2
app.py CHANGED
@@ -7,6 +7,7 @@ from buster.chatbot import Chatbot, ChatbotConfig
7
  MILA_CLUSTER_CHANNEL = "C04LR4H9KQA"
8
  ORION_CHANNEL = "C04LYHGUYB0"
9
  PYTORCH_CHANNEL = "C04MEK6N882"
 
10
 
11
  buster_cfg = ChatbotConfig(
12
  documents_file="buster/data/document_embeddings.csv",
@@ -70,7 +71,7 @@ orion_cfg = ChatbotConfig(
70
 
71
  What is the meaning of life for orion?
72
 
73
- This doesn't seem to be related to cluster usage.
74
 
75
  Now answer the following question:
76
  """,
@@ -103,13 +104,46 @@ pytorch_cfg = ChatbotConfig(
103
 
104
  What is the meaning of life for pytorch?
105
 
106
- This doesn't seem to be related to cluster usage.
107
 
108
  Now answer the following question:
109
  """,
110
  )
111
  pytorch_chatbot = Chatbot(pytorch_cfg)
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  app = App(token=os.environ.get("SLACK_BOT_TOKEN"), signing_secret=os.environ.get("SLACK_SIGNING_SECRET"))
114
 
115
 
@@ -130,6 +164,12 @@ def respond_to_question(event, say):
130
  elif channel == PYTORCH_CHANNEL:
131
  print("*******using PYTORCH********")
132
  answer = pytorch_chatbot.process_input(text)
 
 
 
 
 
 
133
 
134
  # responds to the message in the thread
135
  thread_ts = event["event_ts"]
 
7
  MILA_CLUSTER_CHANNEL = "C04LR4H9KQA"
8
  ORION_CHANNEL = "C04LYHGUYB0"
9
  PYTORCH_CHANNEL = "C04MEK6N882"
10
+ HF_TRANSFORMERS_CHANNEL = "C04NJNCJWHE"
11
 
12
  buster_cfg = ChatbotConfig(
13
  documents_file="buster/data/document_embeddings.csv",
 
71
 
72
  What is the meaning of life for orion?
73
 
74
+ This doesn't seem to be related to the orion library.
75
 
76
  Now answer the following question:
77
  """,
 
104
 
105
  What is the meaning of life for pytorch?
106
 
107
+ This doesn't seem to be related to the pytorch library.
108
 
109
  Now answer the following question:
110
  """,
111
  )
112
  pytorch_chatbot = Chatbot(pytorch_cfg)
113
 
114
+ hf_transformers_cfg = ChatbotConfig(
115
+ documents_file="buster/data/document_embeddings_hf_transformers.tar.gz",
116
+ unknown_prompt="This doesn't seem to be related to the huggingface library. I am not sure how to answer.",
117
+ embedding_model="text-embedding-ada-002",
118
+ top_k=3,
119
+ thresh=0.7,
120
+ max_chars=3000,
121
+ completion_kwargs={
122
+ "engine": "text-davinci-003",
123
+ "max_tokens": 500,
124
+ },
125
+ separator="\n",
126
+ link_format="slack",
127
+ text_after_response="I'm a bot 🤖 and not always perfect.",
128
+ text_before_prompt="""You are a slack chatbot assistant answering technical questions about huggingface transformers, a library to train transformers in python.
129
+ Make sure to format your answers in Markdown format, including code block and snippets.
130
+ Do not include any links to urls or hyperlinks in your answers.
131
+
132
+ If you do not know the answer to a question, or if it is completely irrelevant to the library usage, simply reply with:
133
+
134
+ 'This doesn't seem to be related to the huggingface library.'
135
+
136
+ For example:
137
+
138
+ What is the meaning of life for huggingface?
139
+
140
+ This doesn't seem to be related to the huggingface library.
141
+
142
+ Now answer the following question:
143
+ """,
144
+ )
145
+ hf_transformers_chatbot = Chatbot(hf_transformers_cfg)
146
+
147
  app = App(token=os.environ.get("SLACK_BOT_TOKEN"), signing_secret=os.environ.get("SLACK_SIGNING_SECRET"))
148
 
149
 
 
164
  elif channel == PYTORCH_CHANNEL:
165
  print("*******using PYTORCH********")
166
  answer = pytorch_chatbot.process_input(text)
167
+ elif channel == HF_TRANSFORMERS_CHANNEL:
168
+ print("*******using HF TRANSFORMERS********")
169
+ answer = hf_transformers_chatbot.process_input(text)
170
+ else:
171
+ print(f"invalid channel: {channel}")
172
+ answer = "I was not yet implemented to support this channel."
173
 
174
  # responds to the message in the thread
175
  thread_ts = event["event_ts"]