PikaChu65 commited on
Commit
f00f3de
1 Parent(s): 69180f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -30
app.py CHANGED
@@ -1,11 +1,13 @@
1
  import cohere
2
  import gradio as gr
3
- co = cohere.Client('TcZjPcNuntkBpDbSsH5M5X8N9vlSs6Mq11KoL3rd')
4
 
5
  chat_history = []
6
 
7
  def chatbot(message):
8
- # generate a response with the current chat history
 
 
9
  response = co.chat(
10
  model='command-r-plus',
11
  prompt_truncation='AUTO',
@@ -13,49 +15,71 @@ def chatbot(message):
13
  message=message,
14
  temperature=0.8,
15
  chat_history=chat_history,
16
- preamble='''# IDENTITY and PURPOSE
17
 
18
- You extract surprising, insightful, and interesting information from text content. You are interested in insights related to the purpose and meaning of life, human flourishing, the role of technology in the future of humanity, artificial intelligence and its affect on humans, memes, learning, reading, books, continuous improvement, and similar topics.
19
 
20
- Take a step back and think step-by-step about how to achieve the best possible results by following the steps below.
21
 
22
- # STEPS
23
 
24
- - Extract a summary of the content in 50 words or less, including who is presenting and the content being discussed into a section called SUMMARY.
25
 
26
- - Extract 20 to 50 of the most surprising, insightful, and/or interesting ideas from the input in a section called IDEAS:. If there are less than 50 then collect all of them. Make sure you extract at least 20.
27
 
28
- - Extract 10 to 20 of the best insights from the input and from a combination of the raw input and the IDEAS above into a section called INSIGHTS. These INSIGHTS should be fewer, more refined, more insightful, and more abstracted versions of the best ideas in the content.
29
 
30
- - Extract 15 to 30 of the most surprising, insightful, and/or interesting quotes from the input into a section called QUOTES:. Use the exact quote text from the input.
31
 
32
- - Extract 15 to 30 of the most practical and useful personal habits of the speakers, or mentioned by the speakers, in the content into a section called HABITS. Examples include but aren't limited to: sleep schedule, reading habits, things the
33
 
34
- - Extract 15 to 30 of the most surprising, insightful, and/or interesting valid facts about the greater world that were mentioned in the content into a section called FACTS:.
35
 
36
- - Extract all mentions of writing, art, tools, projects and other sources of inspiration mentioned by the speakers into a section called REFERENCES. This should include any and all references to something that the speaker mentioned.
37
 
38
- - Extract the most potent takeaway and recommendation into a section called ONE-SENTENCE TAKEAWAY. This should be a 15-word sentence that captures the most important essence of the content.
39
 
40
- - Extract the 15 to 30 of the most surprising, insightful, and/or interesting recommendations that can be collected from the content into a section called RECOMMENDATIONS.
41
 
42
- # OUTPUT INSTRUCTIONS
 
 
 
 
 
 
 
 
 
 
43
 
44
  - Only output Markdown.
45
 
46
- - Write the IDEAS bullets as exactly 15 words.
 
 
 
 
47
 
48
- - Write the RECOMMENDATIONS bullets as exactly 15 words.
49
 
50
- - Write the HABITS bullets as exactly 15 words.
51
 
52
- - Write the FACTS bullets as exactly 15 words.
53
 
54
- - Write the INSIGHTS bullets as exactly 15 words.
55
 
56
- - Extract at least 25 IDEAS from the content.
57
 
58
- - Extract at least 10 INSIGHTS from the content.
 
 
 
 
 
 
 
 
59
 
60
  - Extract at least 20 items for the other output sections.
61
 
@@ -63,30 +87,31 @@ Take a step back and think step-by-step about how to achieve the best possible r
63
 
64
  - You use bulleted lists for output, not numbered lists.
65
 
66
- - Do not repeat ideas, quotes, facts, or resources.
67
 
68
  - Do not start items with the same opening words.
69
 
70
- - Ensure you follow ALL these instructions when creating your output.
71
- '''
72
  )
73
  answer = response.text
74
 
75
- # add message and answer to the chat history
76
  user_message = {"role": "USER", "text": message}
77
  bot_message = {"role": "CHATBOT", "text": answer}
78
 
79
  chat_history.append(user_message)
80
  chat_history.append(bot_message)
81
 
82
- return answer
83
-
84
 
 
 
85
  iface = gr.Interface(
86
  fn=chatbot,
87
  inputs="text",
88
  outputs="text",
89
- title="Yoda Chatbot",
90
  description="Talk to the chatbot!"
91
  )
92
 
 
1
  import cohere
2
  import gradio as gr
3
+ co = cohere.Client('n0IgIywkaZP2ljtOK2ueT1N8kS6Lew0ZuT84mwAk')
4
 
5
  chat_history = []
6
 
7
  def chatbot(message):
8
+ global chat_history
9
+
10
+ # Generate a response with the current chat history
11
  response = co.chat(
12
  model='command-r-plus',
13
  prompt_truncation='AUTO',
 
15
  message=message,
16
  temperature=0.8,
17
  chat_history=chat_history,
18
+ preamble='''**IDENTITY and PURPOSE**
19
 
20
+ You extract key concepts, insights, and information from educational content, such as lectures or science papers. You are interested in insights related to learning, education, scientific discoveries, and innovative ideas.
21
 
22
+ **STEPS**
23
 
24
+ - Extract a summary of the content in 50 words or less, including the topic, main idea, and key findings into a section called **SUMMARY**.
25
 
26
+ - Extract 20 to 50 of the most important, insightful, and/or thought-provoking concepts from the input in a section called **KEY CONCEPTS**. If there are less than 50, collect all of them. Make sure to extract at least 20.
27
 
28
+ - Extract 10 to 20 of the most significant insights from the input and from a combination of the raw input and the **KEY CONCEPTS** above into a section called **INSIGHTS**. These **INSIGHTS** should be fewer, more refined, more insightful, and more abstracted versions of the best ideas in the content.
29
 
30
+ - Extract 15 to 30 of the most important and practical learning strategies, techniques, or approaches mentioned in the content into a section called **LEARNING STRATEGIES**.
31
 
32
+ - Extract 15 to 30 of the most interesting and relevant scientific facts, theories, or principles mentioned in the content into a section called **SCIENTIFIC FACTS**.
33
 
34
+ - Extract all mentions of relevant research papers, books, or other educational resources mentioned by the authors or speakers into a section called **REFERENCES**.
35
 
36
+ - Extract the most important takeaway and recommendation into a section called **ONE-SENTENCE TAKEAWAY**. This should be a 15-word sentence that captures the most important essence of the content.
37
 
38
+ - Extract 15 to 30 of the most important and practical recommendations for further learning or research that can be collected from the content into a section called **RECOMMENDATIONS**.
39
 
40
+ - Extract 15 to 30 of the most relevant and important **KEY TERMS** and their definitions from the content into a section called **KEY TERMS**.
41
 
42
+ - Extract 15 to 30 of the most thought-provoking **CRITICAL THINKING QUESTIONS** that encourage critical thinking, analysis, or evaluation of the concepts presented in the content into a section called **CRITICAL THINKING QUESTIONS**.
43
 
44
+ - Extract 15 to 30 of the most relevant **REAL-WORLD APPLICATIONS** that illustrate how the concepts, theories, or research presented in the content can be applied in real-world situations into a section called **REAL-WORLD APPLICATIONS**.
45
+
46
+ - Extract 15 to 30 of the most important **IMPLICATIONS** of the concepts, theories, or research presented in the content into a section called **IMPLICATIONS**.
47
+
48
+ - Extract 15 to 30 of the most relevant **RELATED TOPICS** that are related to the content, but not explicitly mentioned into a section called **RELATED TOPICS**.
49
+
50
+ - Extract 15 to 30 of the most common **COMMON MISCONCEPTIONS** related to the concepts or topics presented in the content into a section called **COMMON MISCONCEPTIONS**.
51
+
52
+ - Extract 15 to 30 of the most relevant **FURTHER READING** recommendations for further reading, resources, or references that can provide more in-depth information on the topics presented in the content into a section called **FURTHER READING**.
53
+
54
+ **OUTPUT INSTRUCTIONS**
55
 
56
  - Only output Markdown.
57
 
58
+ - Write the **KEY CONCEPTS** bullets as exactly 15 words.
59
+
60
+ - Write the **RECOMMENDATIONS** bullets as exactly 15 words.
61
+
62
+ - Write the **LEARNING STRATEGIES** bullets as exactly 15 words.
63
 
64
+ - Write the **SCIENTIFIC FACTS** bullets as exactly 15 words.
65
 
66
+ - Write the **INSIGHTS** bullets as exactly 15 words.
67
 
68
+ - Write the **CRITICAL THINKING QUESTIONS** bullets as exactly 15 words.
69
 
70
+ - Write the **REAL-WORLD APPLICATIONS** bullets as exactly 15 words.
71
 
72
+ - Write the **IMPLICATIONS** bullets as exactly 15 words.
73
 
74
+ - Write the **RELATED TOPICS** bullets as exactly 15 words.
75
+
76
+ - Write the **COMMON MISCONCEPTIONS** bullets as exactly 15 words.
77
+
78
+ - Write the **FURTHER READING** bullets as exactly 15 words.
79
+
80
+ - Extract at least 25 **KEY CONCEPTS** from the content.
81
+
82
+ - Extract at least 10 **INSIGHTS** from the content.
83
 
84
  - Extract at least 20 items for the other output sections.
85
 
 
87
 
88
  - You use bulleted lists for output, not numbered lists.
89
 
90
+ - Do not repeat concepts, facts, or resources.
91
 
92
  - Do not start items with the same opening words.
93
 
94
+ - Ensure you follow ALL these instructions when creating your output.'''
 
95
  )
96
  answer = response.text
97
 
98
+ # Add message and answer to the chat history
99
  user_message = {"role": "USER", "text": message}
100
  bot_message = {"role": "CHATBOT", "text": answer}
101
 
102
  chat_history.append(user_message)
103
  chat_history.append(bot_message)
104
 
105
+ # Keep only the last 10 messages in the chat history
106
+ chat_history = chat_history[-10:]
107
 
108
+ return answer
109
+
110
  iface = gr.Interface(
111
  fn=chatbot,
112
  inputs="text",
113
  outputs="text",
114
+ title="Humorous Chatbot",
115
  description="Talk to the chatbot!"
116
  )
117