vkthakur88 commited on
Commit
567c17c
·
1 Parent(s): 44dfb88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -13
app.py CHANGED
@@ -4,25 +4,33 @@ import os
4
 
5
  client = hf_hub.InferenceClient(token = os.environ['HUGGINGFACEHUB_API_TOKEN'])
6
 
7
- def create_prompt(question, history):
8
- template = '''You are a good chatbot that talks with human.
 
9
 
10
- {history}
 
 
 
 
 
 
11
 
12
- Human : {question}
13
- Chatbot :'''
14
 
15
- conv_template = '''
16
- Human : {query}
17
- Chatbot : {response}
18
- '''
19
 
20
- prev_chat = ''
 
21
 
22
- for ques, ans in history:
23
- prev_chat += conv_template.format(query = ques, response = ans)
24
 
25
- prompt = template.format(history = prev_chat, question = question)
 
 
26
 
27
  return prompt
28
 
 
4
 
5
  client = hf_hub.InferenceClient(token = os.environ['HUGGINGFACEHUB_API_TOKEN'])
6
 
7
+ def create_chat_summary(history):
8
+ context = '''
9
+ Please summarize following conversation so that it become context to further conversation:
10
 
11
+ Chatbot: I am a chemistry professor. I help student to understand chemistry.
12
+ '''
13
+ for ques, ans in history:
14
+ context += f'''
15
+ Human : {ques}
16
+ Chatbot : {ans}
17
+ '''
18
 
19
+ return context
 
20
 
21
+ def create_prompt(question, history):
22
+ context_prompt = create_chat_summary(history)
23
+ context = client.text_generation(prompt = context_prompt, model = 'google/flan-t5-xxl')
 
24
 
25
+ prompt = f'''
26
+ You are a good chatbot that talks with human based on following context:
27
 
28
+ Context :
29
+ {context}
30
 
31
+ Human : {question}
32
+ Chatbot :
33
+ '''
34
 
35
  return prompt
36