s4um1l commited on
Commit
c8c540a
·
1 Parent(s): 4930060

Enhance AI assistant capabilities with specialized templates

Browse files

- Updated system prompt to describe 5 key capabilities
- Added specialized templates for different tasks:
- Technical concept explanations
- Text summarization
- Creative writing
- Problem-solving
- Tone transformation
- Implemented task detection logic to select appropriate templates
- Updated GitHub repository link in chainlit.md

Files changed (2) hide show
  1. app.py +106 -7
  2. chainlit.md +1 -1
app.py CHANGED
@@ -11,20 +11,88 @@ from dotenv import load_dotenv
11
  load_dotenv()
12
 
13
  # ChatOpenAI Templates
14
- system_template = """You are a helpful assistant who always speaks in a pleasant tone!
 
 
 
 
 
 
 
15
  """
16
 
 
17
  user_template = """{input}
18
  Think through your response step by step.
19
  """
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  @cl.on_chat_start # marks a function that will be executed at the start of a user session
23
  async def start_chat():
24
  settings = {
25
- "model": "gpt-3.5-turbo",
26
  "temperature": 0,
27
- "max_tokens": 500,
28
  "top_p": 1,
29
  "frequency_penalty": 0,
30
  "presence_penalty": 0,
@@ -35,12 +103,43 @@ async def start_chat():
35
 
36
  @cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
37
  async def main(message: cl.Message):
38
- settings = cl.user_session.get("settings")
39
 
40
  client = AsyncOpenAI()
41
 
42
  print(message.content)
43
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  prompt = Prompt(
45
  provider=ChatOpenAI.id,
46
  messages=[
@@ -51,8 +150,8 @@ async def main(message: cl.Message):
51
  ),
52
  PromptMessage(
53
  role="user",
54
- template=user_template,
55
- formatted=user_template.format(input=message.content),
56
  ),
57
  ],
58
  inputs={"input": message.content},
 
11
  load_dotenv()
12
 
13
  # ChatOpenAI Templates
14
+ system_template = """You are a versatile, knowledgeable assistant with strong capabilities in:
15
+ 1. Explaining technical concepts in simple terms
16
+ 2. Summarizing and extracting key information
17
+ 3. Creative writing and storytelling
18
+ 4. Problem-solving and logical reasoning
19
+ 5. Adapting your tone and style to different contexts
20
+
21
+ Always maintain a helpful, pleasant tone while providing comprehensive responses.
22
  """
23
 
24
+ # User template
25
  user_template = """{input}
26
  Think through your response step by step.
27
  """
28
 
29
+ # 1. Technical concept explanation template
30
+ explanation_template = """For explaining technical concepts to beginners:
31
+ - Start with a simple, jargon-free definition
32
+ - Use a relatable real-world analogy or metaphor
33
+ - Break down complex ideas into simpler components
34
+ - Provide concrete examples that illustrate the concept
35
+ - Explain practical benefits or applications
36
+ - End with a memorable summary comparison
37
+
38
+ Apply this approach to explain this concept: {input}"""
39
+
40
+ # 2. Summarization template
41
+ summary_template = """For summarization tasks:
42
+ - Read the full text carefully first
43
+ - Identify only the most important points (usually 3-7 key points)
44
+ - Use concise, clear language
45
+ - Organize points logically (chronological, importance, or topic-based)
46
+ - Use bullet points for clarity and scannability
47
+ - Ensure no critical information is lost
48
+ - Avoid adding your own interpretations or opinions
49
+
50
+ Summarize this text: {input}"""
51
+
52
+ # 3. Creative writing template
53
+ creative_template = """For creative writing tasks:
54
+ - Create a complete story with beginning, middle, and end
55
+ - Develop a clear central character with a goal or challenge
56
+ - Establish a vivid setting with sensory details
57
+ - Include an interesting complication or twist
58
+ - Resolve the story in a satisfying way
59
+ - Use descriptive language efficiently
60
+ - Stick precisely to the required word count
61
+ - Incorporate the specific theme or elements requested
62
+
63
+ Write a creative story with these requirements: {input}"""
64
+
65
+ # 4. Problem-solving template
66
+ problem_solving_template = """For math or logical problems:
67
+ - Read the problem carefully to identify what's being asked
68
+ - List all given information and constraints
69
+ - Break down the problem into smaller steps
70
+ - Show your work for each step with clear explanations dont use latex
71
+ - Check your solution against the original constraints
72
+ - Present the final answer clearly
73
+ - Verify the answer with a different approach if possible
74
+
75
+ Solve this problem step by step: {input}"""
76
+
77
+ # 5. Tone transformation template
78
+ tone_template = """For changing the tone of text:
79
+ - Identify the target tone (formal, casual, enthusiastic, etc.)
80
+ - Note key characteristics of that tone (vocabulary level, sentence structure, expressions)
81
+ - Preserve all important information from the original
82
+ - Replace informal phrases with more formal alternatives (or vice versa)
83
+ - Adjust sentence structure to match the desired tone
84
+ - Revise for consistency in tone throughout
85
+ - Ensure the message remains clear despite tone changes
86
+
87
+ Transform this text to the specified tone: {input}"""
88
+
89
 
90
  @cl.on_chat_start # marks a function that will be executed at the start of a user session
91
  async def start_chat():
92
  settings = {
93
+ "model": "gpt-4o-mini",
94
  "temperature": 0,
95
+ "max_tokens": 1000,
96
  "top_p": 1,
97
  "frequency_penalty": 0,
98
  "presence_penalty": 0,
 
103
 
104
  @cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
105
  async def main(message: cl.Message):
106
+ settings = cl.user_session.get("settings").copy()
107
 
108
  client = AsyncOpenAI()
109
 
110
  print(message.content)
111
+ # Detect task type and select appropriate template
112
+ if any(term in message.content.lower() for term in ["explain", "concept", "explain this", "explain the concept"]):
113
+ template_to_use = explanation_template
114
+ # For explanations, lower temperature for clarity
115
+ settings["temperature"] = 0.1
116
+
117
+ elif any(term in message.content.lower() for term in ["summary", "summarize", "key points"]):
118
+ template_to_use = summary_template
119
+ # For summaries, low temperature for factual accuracy
120
+ settings["temperature"] = 0.1
121
+
122
+ elif any(term in message.content.lower() for term in ["story", "creative", "imaginative"]):
123
+ template_to_use = creative_template
124
+ # For creative writing, higher temperature
125
+ settings["temperature"] = 0.7
126
+ settings["max_tokens"] = 300 # Ensure enough space for creativity
127
+
128
+ elif any(term in message.content.lower() for term in ["problem", "solve", "math", "how many"]):
129
+ template_to_use = problem_solving_template
130
+ # For math problems, zero temperature for accuracy
131
+ settings["temperature"] = 0
132
+
133
+ elif any(term in message.content.lower() for term in ["tone", "formal", "professional", "rewrite"]):
134
+ template_to_use = tone_template
135
+ # Moderate temperature for tone transformation
136
+ settings["temperature"] = 0.3
137
+
138
+ else:
139
+ # Default template if no specific type is detected
140
+ template_to_use = user_template
141
+
142
+ # Create prompt with the selected template
143
  prompt = Prompt(
144
  provider=ChatOpenAI.id,
145
  messages=[
 
150
  ),
151
  PromptMessage(
152
  role="user",
153
+ template=template_to_use,
154
+ formatted=template_to_use.format(input=message.content),
155
  ),
156
  ],
157
  inputs={"input": message.content},
chainlit.md CHANGED
@@ -1,3 +1,3 @@
1
  # Beyond ChatGPT
2
 
3
- This Chainlit app was created following instructions from [this repository!](https://github.com/AI-Maker-Space/Beyond-ChatGPT)
 
1
  # Beyond ChatGPT
2
 
3
+ This Chainlit app was created following instructions from [this repository!](https://github.com/s4um1l/Beyond-ChatGPT)