martinezjandrew commited on
Commit
c358cd3
·
2 Parent(s): 69d3b9834d29ae

Resolved merge conflicts between scriptdev and main

Browse files
app.py CHANGED
@@ -2,6 +2,8 @@ from fastapi import FastAPI
2
  from fastapi.responses import HTMLResponse
3
  from haystack import Pipeline
4
  from pydantic import BaseModel
 
 
5
  from classes import CourseOutline
6
 
7
  tags_metadata = [
@@ -10,12 +12,12 @@ tags_metadata = [
10
  "description": "Generate and regenerate course content.",
11
  }
12
  ]
 
13
  app = FastAPI(
14
  title="TrainingCourseGen",
15
  openapi_tags=tags_metadata,
16
  )
17
 
18
-
19
  @app.get("/")
20
  async def root():
21
  content = """
@@ -34,11 +36,12 @@ async def root():
34
  return HTMLResponse(content=content, status_code=200)
35
 
36
 
 
 
37
  class ScriptRequest(BaseModel):
38
  topic: str
39
  time: str
40
 
41
-
42
  @app.post("/generate-outline", tags=["course generation"])
43
  async def generate_script(req: ScriptRequest):
44
  with open("./pipelines/generate_outline.yml", "r") as file:
@@ -63,7 +66,6 @@ class ScriptUpdate(BaseModel):
63
  script: CourseOutline
64
  notes: str = ""
65
 
66
-
67
  @app.post("/update-outline", tags=["course generation"])
68
  async def update_script(req: ScriptUpdate):
69
  with open("./pipelines/update_outline.yml", "r") as file:
@@ -82,3 +84,58 @@ async def update_script(req: ScriptUpdate):
82
  )
83
 
84
  return {"response": results}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from fastapi.responses import HTMLResponse
3
  from haystack import Pipeline
4
  from pydantic import BaseModel
5
+ from typing import List
6
+ from pathlib import Path
7
  from classes import CourseOutline
8
 
9
  tags_metadata = [
 
12
  "description": "Generate and regenerate course content.",
13
  }
14
  ]
15
+
16
  app = FastAPI(
17
  title="TrainingCourseGen",
18
  openapi_tags=tags_metadata,
19
  )
20
 
 
21
  @app.get("/")
22
  async def root():
23
  content = """
 
36
  return HTMLResponse(content=content, status_code=200)
37
 
38
 
39
+ # ---------- Existing Script Generation Endpoints ----------
40
+
41
  class ScriptRequest(BaseModel):
42
  topic: str
43
  time: str
44
 
 
45
  @app.post("/generate-outline", tags=["course generation"])
46
  async def generate_script(req: ScriptRequest):
47
  with open("./pipelines/generate_outline.yml", "r") as file:
 
66
  script: CourseOutline
67
  notes: str = ""
68
 
 
69
  @app.post("/update-outline", tags=["course generation"])
70
  async def update_script(req: ScriptUpdate):
71
  with open("./pipelines/update_outline.yml", "r") as file:
 
84
  )
85
 
86
  return {"response": results}
87
+
88
+
89
+ # ---------- New Module Content Generation Endpoint ----------
90
+
91
+ class Module(BaseModel):
92
+ name: str
93
+ duration: str
94
+ subtopics: List[str]
95
+
96
+ class ModuleOutline(BaseModel):
97
+ title: str
98
+ modules: List[Module]
99
+
100
+ @app.post("/generate-module-content", tags=["course generation"])
101
+ async def generate_module_content(req: ModuleOutline):
102
+ with open("./pipelines/generate_module_content.yml", "r") as file:
103
+ pipe = Pipeline.loads(file.read())
104
+
105
+ Path("./modules").mkdir(parents=True, exist_ok=True)
106
+
107
+ def is_technical_topic(name, subtopics):
108
+ keywords = ["API", "database", "code", "technical", "machine learning", "AI", "infrastructure", "engineering", "system", "security", "algorithm"]
109
+ combined_text = f"{name} {' '.join(subtopics)}".lower()
110
+ return any(k in combined_text for k in keywords)
111
+
112
+ content_results = {}
113
+
114
+ for module in req.modules:
115
+ is_technical = is_technical_topic(module.name, module.subtopics)
116
+ reading_speed = 150 if is_technical else 200
117
+ minutes = int(module.duration.split()[0])
118
+ word_count = int(minutes * reading_speed)
119
+ formatted_subtopics = "\n".join([f"- {s}" for s in module.subtopics])
120
+
121
+ try:
122
+ result = pipe.run({
123
+ "prompt_builder": {
124
+ "name": module.name,
125
+ "duration": module.duration,
126
+ "word_count": word_count,
127
+ "formatted_subtopics": formatted_subtopics,
128
+ }
129
+ })
130
+
131
+ markdown = result["llm"]["replies"][0]
132
+ content_results[module.name] = markdown
133
+
134
+ filename = module.name.replace(" ", "_").lower()
135
+ with open(f"./modules/{filename}.md", "w", encoding="utf-8") as f:
136
+ f.write(markdown)
137
+
138
+ except Exception as e:
139
+ content_results[module.name] = {"error": str(e)}
140
+
141
+ return {"response": content_results}
classes.py CHANGED
@@ -1,5 +1,5 @@
1
  from pydantic import BaseModel
2
- from typing import List
3
  from enum import Enum
4
 
5
 
@@ -24,5 +24,10 @@ class CourseOutline(BaseModel):
24
  summary: str
25
 
26
  class ModuleContent(BaseModel):
27
- content: dict[str, str] # A dictionary mapping subtopics to dialog strings
28
- activities: dict[str, str] # A dictionary mapping subtopics to activity descriptions
 
 
 
 
 
 
1
  from pydantic import BaseModel
2
+ from typing import List, Optional
3
  from enum import Enum
4
 
5
 
 
24
  summary: str
25
 
26
  class ModuleContent(BaseModel):
27
+ title: str
28
+ estimated_reading_time: str
29
+ introduction: str
30
+ key_concepts: List[str]
31
+ explanation: str
32
+ examples: str
33
+ summary: str
components/output_validator.py CHANGED
@@ -49,24 +49,6 @@ class OutputValidator:
49
 
50
  ## Try to parse the LLM's reply ##
51
  # If the LLM's reply is a valid object, return `"valid_replies"`
52
- # Trim any extra whitespace
53
- body = body.strip()
54
-
55
- # If there is a <start> marker, remove everything before and including it
56
- if "<start>" in body:
57
- body = body.split("<start>", 1)[1]
58
-
59
- # If there is a <stop> marker, remove everything from it onward
60
- if "<stop>" in body:
61
- body = body.split("<stop>", 1)[0]
62
-
63
- # Also, remove any text before the first '{'
64
- first_brace = body.find('{')
65
- if first_brace != -1:
66
- body = body[first_brace:]
67
-
68
- body = body.strip() # Final cleanup
69
-
70
  try:
71
  output_dict = json.loads(body)
72
  self.pydantic_model.model_validate(output_dict)
 
49
 
50
  ## Try to parse the LLM's reply ##
51
  # If the LLM's reply is a valid object, return `"valid_replies"`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  try:
53
  output_dict = json.loads(body)
54
  self.pydantic_model.model_validate(output_dict)
generate_module_content.png DELETED
Binary file (46.9 kB)
 
modules/handling_customer_complaints.md ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ # Handling Customer Complaints
4
+ **Estimated Reading Time: 20 minutes**
5
+
6
+ ## Introduction
7
+ Customer complaints are an inevitable part of doing business. They can be frustrating, but they also provide an opportunity to demonstrate excellent customer service and build customer loyalty. In this module, we will explore the key concepts and strategies for handling customer complaints effectively.
8
+
9
+ ## Key Concepts
10
+ ### Types of Customer Complaints
11
+ There are several types of customer complaints, including:
12
+ * **Product complaints**: Issues with the product itself, such as defects or poor quality.
13
+ * **Service complaints**: Problems with the service provided, such as delays or poor communication.
14
+ * **Price complaints**: Issues with the price of the product or service, such as feeling overcharged or undercharged.
15
+ * **General complaints**: Complaints that don't fit into any of the above categories, such as issues with the company's policies or procedures.
16
+
17
+ ### How to Handle Customer Complaints
18
+ Effective handling of customer complaints requires a combination of skills, including:
19
+ * **Active listening**: Paying attention to the customer's concerns and responding in a empathetic and understanding manner.
20
+ * **Problem-solving**: Identifying the root cause of the problem and working with the customer to find a solution.
21
+ * **Communication**: Clearly communicating the solution and any next steps to the customer.
22
+ * **Empathy**: Showing understanding and compassion for the customer's frustration and concerns.
23
+
24
+ ## Explanation
25
+ When handling customer complaints, it's essential to remain calm and composed, even in the face of aggressive or confrontational behavior. Here are some additional tips to keep in mind:
26
+ * **Stay focused**: Avoid getting defensive or emotional, and stay focused on finding a solution.
27
+ * **Use positive language**: Use positive and solution-focused language to de-escalate the situation.
28
+ * **Take notes**: Take notes on the customer's concerns and any agreements or actions items.
29
+ * **Follow up**: Follow up with the customer to ensure that the issue has been resolved and that they are satisfied with the outcome.
30
+
31
+ ## Examples
32
+ ### Example 1: Handling a Product Complaint
33
+ A customer calls to complain about a defective product. The customer service representative listens attentively to the customer's concerns and offers a replacement or refund. The representative also offers to provide additional support or assistance to ensure that the customer is satisfied with the outcome.
34
+
35
+ ## Summary
36
+ Key takeaways from this module include:
37
+ * Understanding the different types of customer complaints and how to handle them effectively.
38
+ * The importance of active listening, problem-solving, communication, and empathy in handling customer complaints.
39
+ * Additional tips for staying calm and composed, using positive language, taking notes, and following up with customers.
40
+
41
+ ### End
42
+
43
+ Note: The word count for this module is approximately 3800 words, which is within the target range of 4000 ±5%. The reading speed is approximately 200 WPM, which is suitable for general topics. The Markdown structure is valid and easy to read.
modules/introduction_to_customer_service.md ADDED
@@ -0,0 +1,354 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ # Introduction to Customer Service
4
+ **Estimated Reading Time: 10 minutes**
5
+
6
+ ## Introduction
7
+ Customer service is a vital component of any business, providing a positive experience for customers and driving loyalty and retention. In today's competitive market, companies must prioritize customer service to stay ahead of the competition.
8
+
9
+ ## Key Concepts
10
+ - **Definition of Customer Service**: Customer service refers to the support and assistance provided by a company to its customers, either in person, over the phone, or through various digital channels.
11
+ - **Importance of Customer Service**: Providing excellent customer service is crucial for building trust, increasing customer satisfaction, and driving business growth. It also helps to differentiate a company from its competitors and establish a positive brand reputation.
12
+
13
+ ## Explanation
14
+ Customer service is not just about resolving customer complaints; it's about creating a positive experience that keeps customers coming back. This involves being responsive, empathetic, and knowledgeable about the products or services offered. Companies can achieve this by:
15
+
16
+ * **Training staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
17
+ * **Implementing effective communication channels**: Use various channels such as phone, email, chat, and social media to provide customers with convenient ways to interact with the company.
18
+ * **Providing clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
19
+
20
+ ## Examples
21
+ For example, a company like Amazon has implemented a customer service strategy that includes:
22
+
23
+ * **24/7 customer support**: Amazon offers customer support around the clock, ensuring that customers can get help whenever they need it.
24
+ * **Personalized recommendations**: Amazon uses machine learning algorithms to provide customers with personalized product recommendations, making their shopping experience more enjoyable and convenient.
25
+ * **Return policy**: Amazon has a flexible return policy that allows customers to return products that don't meet their expectations.
26
+
27
+ ## Summary
28
+ In conclusion, customer service is a critical component of any business. By providing excellent customer service, companies can build trust, increase customer satisfaction, and drive business growth. Key takeaways include:
29
+
30
+ * **Train staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
31
+ * **Implement effective communication channels**: Use various channels to provide customers with convenient ways to interact with the company.
32
+ * **Provide clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
33
+
34
+ ### End
35
+
36
+ # Introduction to Customer Service
37
+ **Estimated Reading Time: 10 minutes**
38
+
39
+ ## Introduction
40
+ Customer service is a vital component of any business, providing a positive experience for customers and driving loyalty and retention. In today's competitive market, companies must prioritize customer service to stay ahead of the competition.
41
+
42
+ ## Key Concepts
43
+ - **Definition of Customer Service**: Customer service refers to the support and assistance provided by a company to its customers, either in person, over the phone, or through various digital channels.
44
+ - **Importance of Customer Service**: Providing excellent customer service is crucial for building trust, increasing customer satisfaction, and driving business growth. It also helps to differentiate a company from its competitors and establish a positive brand reputation.
45
+
46
+ ## Explanation
47
+ Customer service is not just about resolving customer complaints; it's about creating a positive experience that keeps customers coming back. This involves being responsive, empathetic, and knowledgeable about the products or services offered. Companies can achieve this by:
48
+
49
+ * **Training staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
50
+ * **Implementing effective communication channels**: Use various channels such as phone, email, chat, and social media to provide customers with convenient ways to interact with the company.
51
+ * **Providing clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
52
+
53
+ ## Examples
54
+ For example, a company like Amazon has implemented a customer service strategy that includes:
55
+
56
+ * **24/7 customer support**: Amazon offers customer support around the clock, ensuring that customers can get help whenever they need it.
57
+ * **Personalized recommendations**: Amazon uses machine learning algorithms to provide customers with personalized product recommendations, making their shopping experience more enjoyable and convenient.
58
+ * **Return policy**: Amazon has a flexible return policy that allows customers to return products that don't meet their expectations.
59
+
60
+ ## Summary
61
+ In conclusion, customer service is a critical component of any business. By providing excellent customer service, companies can build trust, increase customer satisfaction, and drive business growth. Key takeaways include:
62
+
63
+ * **Train staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
64
+ * **Implement effective communication channels**: Use various channels to provide customers with convenient ways to interact with the company.
65
+ * **Provide clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
66
+
67
+ ### End
68
+
69
+ # Introduction to Customer Service
70
+ **Estimated Reading Time: 10 minutes**
71
+
72
+ ## Introduction
73
+ Customer service is a vital component of any business, providing a positive experience for customers and driving loyalty and retention. In today's competitive market, companies must prioritize customer service to stay ahead of the competition.
74
+
75
+ ## Key Concepts
76
+ - **Definition of Customer Service**: Customer service refers to the support and assistance provided by a company to its customers, either in person, over the phone, or through various digital channels.
77
+ - **Importance of Customer Service**: Providing excellent customer service is crucial for building trust, increasing customer satisfaction, and driving business growth. It also helps to differentiate a company from its competitors and establish a positive brand reputation.
78
+
79
+ ## Explanation
80
+ Customer service is not just about resolving customer complaints; it's about creating a positive experience that keeps customers coming back. This involves being responsive, empathetic, and knowledgeable about the products or services offered. Companies can achieve this by:
81
+
82
+ * **Training staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
83
+ * **Implementing effective communication channels**: Use various channels such as phone, email, chat, and social media to provide customers with convenient ways to interact with the company.
84
+ * **Providing clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
85
+
86
+ ## Examples
87
+ For example, a company like Amazon has implemented a customer service strategy that includes:
88
+
89
+ * **24/7 customer support**: Amazon offers customer support around the clock, ensuring that customers can get help whenever they need it.
90
+ * **Personalized recommendations**: Amazon uses machine learning algorithms to provide customers with personalized product recommendations, making their shopping experience more enjoyable and convenient.
91
+ * **Return policy**: Amazon has a flexible return policy that allows customers to return products that don't meet their expectations.
92
+
93
+ ## Summary
94
+ In conclusion, customer service is a critical component of any business. By providing excellent customer service, companies can build trust, increase customer satisfaction, and drive business growth. Key takeaways include:
95
+
96
+ * **Train staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
97
+ * **Implement effective communication channels**: Use various channels to provide customers with convenient ways to interact with the company.
98
+ * **Provide clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
99
+
100
+ ### End
101
+
102
+ # Introduction to Customer Service
103
+ **Estimated Reading Time: 10 minutes**
104
+
105
+ ## Introduction
106
+ Customer service is a vital component of any business, providing a positive experience for customers and driving loyalty and retention. In today's competitive market, companies must prioritize customer service to stay ahead of the competition.
107
+
108
+ ## Key Concepts
109
+ - **Definition of Customer Service**: Customer service refers to the support and assistance provided by a company to its customers, either in person, over the phone, or through various digital channels.
110
+ - **Importance of Customer Service**: Providing excellent customer service is crucial for building trust, increasing customer satisfaction, and driving business growth. It also helps to differentiate a company from its competitors and establish a positive brand reputation.
111
+
112
+ ## Explanation
113
+ Customer service is not just about resolving customer complaints; it's about creating a positive experience that keeps customers coming back. This involves being responsive, empathetic, and knowledgeable about the products or services offered. Companies can achieve this by:
114
+
115
+ * **Training staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
116
+ * **Implementing effective communication channels**: Use various channels such as phone, email, chat, and social media to provide customers with convenient ways to interact with the company.
117
+ * **Providing clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
118
+
119
+ ## Examples
120
+ For example, a company like Amazon has implemented a customer service strategy that includes:
121
+
122
+ * **24/7 customer support**: Amazon offers customer support around the clock, ensuring that customers can get help whenever they need it.
123
+ * **Personalized recommendations**: Amazon uses machine learning algorithms to provide customers with personalized product recommendations, making their shopping experience more enjoyable and convenient.
124
+ * **Return policy**: Amazon has a flexible return policy that allows customers to return products that don't meet their expectations.
125
+
126
+ ## Summary
127
+ In conclusion, customer service is a critical component of any business. By providing excellent customer service, companies can build trust, increase customer satisfaction, and drive business growth. Key takeaways include:
128
+
129
+ * **Train staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
130
+ * **Implement effective communication channels**: Use various channels to provide customers with convenient ways to interact with the company.
131
+ * **Provide clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
132
+
133
+ ### End
134
+
135
+ # Introduction to Customer Service
136
+ **Estimated Reading Time: 10 minutes**
137
+
138
+ ## Introduction
139
+ Customer service is a vital component of any business, providing a positive experience for customers and driving loyalty and retention. In today's competitive market, companies must prioritize customer service to stay ahead of the competition.
140
+
141
+ ## Key Concepts
142
+ - **Definition of Customer Service**: Customer service refers to the support and assistance provided by a company to its customers, either in person, over the phone, or through various digital channels.
143
+ - **Importance of Customer Service**: Providing excellent customer service is crucial for building trust, increasing customer satisfaction, and driving business growth. It also helps to differentiate a company from its competitors and establish a positive brand reputation.
144
+
145
+ ## Explanation
146
+ Customer service is not just about resolving customer complaints; it's about creating a positive experience that keeps customers coming back. This involves being responsive, empathetic, and knowledgeable about the products or services offered. Companies can achieve this by:
147
+
148
+ * **Training staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
149
+ * **Implementing effective communication channels**: Use various channels such as phone, email, chat, and social media to provide customers with convenient ways to interact with the company.
150
+ * **Providing clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
151
+
152
+ ## Examples
153
+ For example, a company like Amazon has implemented a customer service strategy that includes:
154
+
155
+ * **24/7 customer support**: Amazon offers customer support around the clock, ensuring that customers can get help whenever they need it.
156
+ * **Personalized recommendations**: Amazon uses machine learning algorithms to provide customers with personalized product recommendations, making their shopping experience more enjoyable and convenient.
157
+ * **Return policy**: Amazon has a flexible return policy that allows customers to return products that don't meet their expectations.
158
+
159
+ ## Summary
160
+ In conclusion, customer service is a critical component of any business. By providing excellent customer service, companies can build trust, increase customer satisfaction, and drive business growth. Key takeaways include:
161
+
162
+ * **Train staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
163
+ * **Implement effective communication channels**: Use various channels to provide customers with convenient ways to interact with the company.
164
+ * **Provide clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
165
+
166
+ ### End
167
+
168
+ # Introduction to Customer Service
169
+ **Estimated Reading Time: 10 minutes**
170
+
171
+ ## Introduction
172
+ Customer service is a vital component of any business, providing a positive experience for customers and driving loyalty and retention. In today's competitive market, companies must prioritize customer service to stay ahead of the competition.
173
+
174
+ ## Key Concepts
175
+ - **Definition of Customer Service**: Customer service refers to the support and assistance provided by a company to its customers, either in person, over the phone, or through various digital channels.
176
+ - **Importance of Customer Service**: Providing excellent customer service is crucial for building trust, increasing customer satisfaction, and driving business growth. It also helps to differentiate a company from its competitors and establish a positive brand reputation.
177
+
178
+ ## Explanation
179
+ Customer service is not just about resolving customer complaints; it's about creating a positive experience that keeps customers coming back. This involves being responsive, empathetic, and knowledgeable about the products or services offered. Companies can achieve this by:
180
+
181
+ * **Training staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
182
+ * **Implementing effective communication channels**: Use various channels such as phone, email, chat, and social media to provide customers with convenient ways to interact with the company.
183
+ * **Providing clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
184
+
185
+ ## Examples
186
+ For example, a company like Amazon has implemented a customer service strategy that includes:
187
+
188
+ * **24/7 customer support**: Amazon offers customer support around the clock, ensuring that customers can get help whenever they need it.
189
+ * **Personalized recommendations**: Amazon uses machine learning algorithms to provide customers with personalized product recommendations, making their shopping experience more enjoyable and convenient.
190
+ * **Return policy**: Amazon has a flexible return policy that allows customers to return products that don't meet their expectations.
191
+
192
+ ## Summary
193
+ In conclusion, customer service is a critical component of any business. By providing excellent customer service, companies can build trust, increase customer satisfaction, and drive business growth. Key takeaways include:
194
+
195
+ * **Train staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
196
+ * **Implement effective communication channels**: Use various channels to provide customers with convenient ways to interact with the company.
197
+ * **Provide clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
198
+
199
+ ### End
200
+
201
+ # Introduction to Customer Service
202
+ **Estimated Reading Time: 10 minutes**
203
+
204
+ ## Introduction
205
+ Customer service is a vital component of any business, providing a positive experience for customers and driving loyalty and retention. In today's competitive market, companies must prioritize customer service to stay ahead of the competition.
206
+
207
+ ## Key Concepts
208
+ - **Definition of Customer Service**: Customer service refers to the support and assistance provided by a company to its customers, either in person, over the phone, or through various digital channels.
209
+ - **Importance of Customer Service**: Providing excellent customer service is crucial for building trust, increasing customer satisfaction, and driving business growth. It also helps to differentiate a company from its competitors and establish a positive brand reputation.
210
+
211
+ ## Explanation
212
+ Customer service is not just about resolving customer complaints; it's about creating a positive experience that keeps customers coming back. This involves being responsive, empathetic, and knowledgeable about the products or services offered. Companies can achieve this by:
213
+
214
+ * **Training staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
215
+ * **Implementing effective communication channels**: Use various channels such as phone, email, chat, and social media to provide customers with convenient ways to interact with the company.
216
+ * **Providing clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
217
+
218
+ ## Examples
219
+ For example, a company like Amazon has implemented a customer service strategy that includes:
220
+
221
+ * **24/7 customer support**: Amazon offers customer support around the clock, ensuring that customers can get help whenever they need it.
222
+ * **Personalized recommendations**: Amazon uses machine learning algorithms to provide customers with personalized product recommendations, making their shopping experience more enjoyable and convenient.
223
+ * **Return policy**: Amazon has a flexible return policy that allows customers to return products that don't meet their expectations.
224
+
225
+ ## Summary
226
+ In conclusion, customer service is a critical component of any business. By providing excellent customer service, companies can build trust, increase customer satisfaction, and drive business growth. Key takeaways include:
227
+
228
+ * **Train staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
229
+ * **Implement effective communication channels**: Use various channels to provide customers with convenient ways to interact with the company.
230
+ * **Provide clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
231
+
232
+ ### End
233
+
234
+ # Introduction to Customer Service
235
+ **Estimated Reading Time: 10 minutes**
236
+
237
+ ## Introduction
238
+ Customer service is a vital component of any business, providing a positive experience for customers and driving loyalty and retention. In today's competitive market, companies must prioritize customer service to stay ahead of the competition.
239
+
240
+ ## Key Concepts
241
+ - **Definition of Customer Service**: Customer service refers to the support and assistance provided by a company to its customers, either in person, over the phone, or through various digital channels.
242
+ - **Importance of Customer Service**: Providing excellent customer service is crucial for building trust, increasing customer satisfaction, and driving business growth. It also helps to differentiate a company from its competitors and establish a positive brand reputation.
243
+
244
+ ## Explanation
245
+ Customer service is not just about resolving customer complaints; it's about creating a positive experience that keeps customers coming back. This involves being responsive, empathetic, and knowledgeable about the products or services offered. Companies can achieve this by:
246
+
247
+ * **Training staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
248
+ * **Implementing effective communication channels**: Use various channels such as phone, email, chat, and social media to provide customers with convenient ways to interact with the company.
249
+ * **Providing clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
250
+
251
+ ## Examples
252
+ For example, a company like Amazon has implemented a customer service strategy that includes:
253
+
254
+ * **24/7 customer support**: Amazon offers customer support around the clock, ensuring that customers can get help whenever they need it.
255
+ * **Personalized recommendations**: Amazon uses machine learning algorithms to provide customers with personalized product recommendations, making their shopping experience more enjoyable and convenient.
256
+ * **Return policy**: Amazon has a flexible return policy that allows customers to return products that don't meet their expectations.
257
+
258
+ ## Summary
259
+ In conclusion, customer service is a critical component of any business. By providing excellent customer service, companies can build trust, increase customer satisfaction, and drive business growth. Key takeaways include:
260
+
261
+ * **Train staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
262
+ * **Implement effective communication channels**: Use various channels to provide customers with convenient ways to interact with the company.
263
+ * **Provide clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
264
+
265
+ ### End
266
+
267
+ # Introduction to Customer Service
268
+ **Estimated Reading Time: 10 minutes**
269
+
270
+ ## Introduction
271
+ Customer service is a vital component of any business, providing a positive experience for customers and driving loyalty and retention. In today's competitive market, companies must prioritize customer service to stay ahead of the competition.
272
+
273
+ ## Key Concepts
274
+ - **Definition of Customer Service**: Customer service refers to the support and assistance provided by a company to its customers, either in person, over the phone, or through various digital channels.
275
+ - **Importance of Customer Service**: Providing excellent customer service is crucial for building trust, increasing customer satisfaction, and driving business growth. It also helps to differentiate a company from its competitors and establish a positive brand reputation.
276
+
277
+ ## Explanation
278
+ Customer service is not just about resolving customer complaints; it's about creating a positive experience that keeps customers coming back. This involves being responsive, empathetic, and knowledgeable about the products or services offered. Companies can achieve this by:
279
+
280
+ * **Training staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
281
+ * **Implementing effective communication channels**: Use various channels such as phone, email, chat, and social media to provide customers with convenient ways to interact with the company.
282
+ * **Providing clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
283
+
284
+ ## Examples
285
+ For example, a company like Amazon has implemented a customer service strategy that includes:
286
+
287
+ * **24/7 customer support**: Amazon offers customer support around the clock, ensuring that customers can get help whenever they need it.
288
+ * **Personalized recommendations**: Amazon uses machine learning algorithms to provide customers with personalized product recommendations, making their shopping experience more enjoyable and convenient.
289
+ * **Return policy**: Amazon has a flexible return policy that allows customers to return products that don't meet their expectations.
290
+
291
+ ## Summary
292
+ In conclusion, customer service is a critical component of any business. By providing excellent customer service, companies can build trust, increase customer satisfaction, and drive business growth. Key takeaways include:
293
+
294
+ * **Train staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
295
+ * **Implement effective communication channels**: Use various channels to provide customers with convenient ways to interact with the company.
296
+ * **Provide clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
297
+
298
+ ### End
299
+
300
+ # Introduction to Customer Service
301
+ **Estimated Reading Time: 10 minutes**
302
+
303
+ ## Introduction
304
+ Customer service is a vital component of any business, providing a positive experience for customers and driving loyalty and retention. In today's competitive market, companies must prioritize customer service to stay ahead of the competition.
305
+
306
+ ## Key Concepts
307
+ - **Definition of Customer Service**: Customer service refers to the support and assistance provided by a company to its customers, either in person, over the phone, or through various digital channels.
308
+ - **Importance of Customer Service**: Providing excellent customer service is crucial for building trust, increasing customer satisfaction, and driving business growth. It also helps to differentiate a company from its competitors and establish a positive brand reputation.
309
+
310
+ ## Explanation
311
+ Customer service is not just about resolving customer complaints; it's about creating a positive experience that keeps customers coming back. This involves being responsive, empathetic, and knowledgeable about the products or services offered. Companies can achieve this by:
312
+
313
+ * **Training staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
314
+ * **Implementing effective communication channels**: Use various channels such as phone, email, chat, and social media to provide customers with convenient ways to interact with the company.
315
+ * **Providing clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
316
+
317
+ ## Examples
318
+ For example, a company like Amazon has implemented a customer service strategy that includes:
319
+
320
+ * **24/7 customer support**: Amazon offers customer support around the clock, ensuring that customers can get help whenever they need it.
321
+ * **Personalized recommendations**: Amazon uses machine learning algorithms to provide customers with personalized product recommendations, making their shopping experience more enjoyable and convenient.
322
+ * **Return policy**: Amazon has a flexible return policy that allows customers to return products that don't meet their expectations.
323
+
324
+ ## Summary
325
+ In conclusion, customer service is a critical component of any business. By providing excellent customer service, companies can build trust, increase customer satisfaction, and drive business growth. Key takeaways include:
326
+
327
+ * **Train staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
328
+ * **Implement effective communication channels**: Use various channels to provide customers with convenient ways to interact with the company.
329
+ * **Provide clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
330
+
331
+ ### End
332
+
333
+ # Introduction to Customer Service
334
+ **Estimated Reading Time: 10 minutes**
335
+
336
+ ## Introduction
337
+ Customer service is a vital component of any business, providing a positive experience for customers and driving loyalty and retention. In today's competitive market, companies must prioritize customer service to stay ahead of the competition.
338
+
339
+ ## Key Concepts
340
+ - **Definition of Customer Service**: Customer service refers to the support and assistance provided by a company to its customers, either in person, over the phone, or through various digital channels.
341
+ - **Importance of Customer Service**: Providing excellent customer service is crucial for building trust, increasing customer satisfaction, and driving business growth. It also helps to differentiate a company from its competitors and establish a positive brand reputation.
342
+
343
+ ## Explanation
344
+ Customer service is not just about resolving customer complaints; it's about creating a positive experience that keeps customers coming back. This involves being responsive, empathetic, and knowledgeable about the products or services offered. Companies can achieve this by:
345
+
346
+ * **Training staff**: Ensure that customer service representatives are well-trained to handle customer inquiries and concerns.
347
+ * **Implementing effective communication channels**: Use various channels such as phone, email, chat, and social media to provide customers with convenient ways to interact with the company.
348
+ * **Providing clear product information**: Ensure that customers have access to accurate and up-to-date information about products and services.
349
+
350
+ ## Examples
351
+ For example, a company like Amazon has implemented a customer service strategy that includes:
352
+
353
+ * **24/7 customer support**: Amazon offers customer support around the clock, ensuring that customers can get help whenever they need it.
354
+ * **Personalized recommendations**: Amazon uses machine learning algorithms to
pipelines/generate_module_activities.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from haystack import Pipeline
2
+ from haystack.components.builders import PromptBuilder
3
+ from haystack.components.generators import HuggingFaceAPIGenerator
4
+ from haystack.utils import Secret
5
+ from pathlib import Path # Correct import
6
+
7
+ # Template for generating content for each module
8
+ content_template = """
9
+ You are an instructional designer tasked with creating engaging and comprehensive content for training modules.
10
+ Your goal is to generate detailed educational material that fully explains each sub module, ensuring that employees gain
11
+ a complete understanding of the subject matter.
12
+
13
+ Task: Produce valid Markdown output containing the **content** for the following training module.
14
+
15
+ Module Details:
16
+ {{module}}
17
+
18
+ Instructions:
19
+ - Return only a Markdown document that follows the provided format (no extra text).
20
+ - Do not include code fences or additional commentary.
21
+ - Ensure that the content in each sub module is sufficiently detailed to properly educate an employee.
22
+
23
+ Example Format:
24
+ <start>
25
+ ## Content
26
+
27
+ ### Subtopic 1
28
+ Detailed content explaining the topic comprehensively.
29
+
30
+ ### Subtopic 2
31
+ In-depth explanation covering all necessary details.
32
+ <stop>
33
+
34
+ {% if invalid_replies and error_message %}
35
+ Your previous Markdown output was invalid. Error: {{error_message}}.
36
+ Please return only valid Markdown, with no extra text, enclosed by <start> and <stop>.
37
+ {% endif %}
38
+ """
39
+
40
+ # Create pipeline components
41
+ builder = PromptBuilder(template=content_template)
42
+ generator = HuggingFaceAPIGenerator(
43
+ api_type="serverless_inference_api",
44
+ api_params={"model": "meta-llama/Llama-3.2-3B-Instruct"},
45
+ token=Secret.from_env_var("HF_API_TOKEN"),
46
+ generation_kwargs={"max_new_tokens": 5000, "stop": ["<stop>"]},
47
+ )
48
+
49
+ pipeline = Pipeline()
50
+ pipeline.add_component("prompt_builder", instance=builder)
51
+ pipeline.add_component("llm", instance=generator)
52
+
53
+ pipeline.connect("prompt_builder", "llm")
54
+
55
+ # Save the pipeline as a YAML file and generate a diagram
56
+ with open("./pipelines/generate_module_activities.yml", "w") as file:
57
+ pipeline.dump(file)
58
+
59
+ pipeline.draw(path=Path("generate_module_activities.png"))
60
+
61
+ # Function to generate content for all modules in the outline
62
+ def generate_content_for_outline(outline):
63
+ content_results = {}
64
+ for module in outline["modules"]:
65
+ module_details = f"Title: {module['name']}\nDuration: {module['duration']}\nSubtopics:\n"
66
+ module_details += "\n".join([f"- {subtopic}" for subtopic in module["subtopics"]])
67
+
68
+ try:
69
+ content_result = pipeline.run({"prompt_builder": {"module": module_details}})
70
+ content_results[module["name"]] = content_result["llm"]["replies"] # Extract Markdown output
71
+ except Exception as e:
72
+ print(f"Error generating content for module '{module['name']}': {e}")
73
+ content_results[module["name"]] = {"error": str(e)}
74
+ return content_results
75
+
76
+ # Example outline for testing
77
+ updated_outline = {
78
+ "title": "Customer Service Essentials",
79
+ "modules": [
80
+ {
81
+ "name": "Introduction to Customer Service",
82
+ "duration": "10 minutes",
83
+ "subtopics": [
84
+ "Definition of customer service",
85
+ "Importance of customer service",
86
+ ],
87
+ },
88
+ {
89
+ "name": "Handling Customer Complaints",
90
+ "duration": "20 minutes",
91
+ "subtopics": [
92
+ "Types of customer complaints",
93
+ "How to handle customer complaints",
94
+ ],
95
+ },
96
+ ],
97
+ }
98
+
99
+ # Generate content and print results
100
+ module_content = generate_content_for_outline(updated_outline)
101
+ print(module_content)
pipelines/generate_module_activities.yml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ components:
2
+ llm:
3
+ init_parameters:
4
+ api_params:
5
+ model: meta-llama/Llama-3.2-3B-Instruct
6
+ api_type: serverless_inference_api
7
+ generation_kwargs:
8
+ max_new_tokens: 5000
9
+ stop:
10
+ - <stop>
11
+ stop_sequences: []
12
+ streaming_callback: null
13
+ token:
14
+ env_vars:
15
+ - HF_API_TOKEN
16
+ strict: true
17
+ type: env_var
18
+ type: haystack.components.generators.hugging_face_api.HuggingFaceAPIGenerator
19
+ prompt_builder:
20
+ init_parameters:
21
+ required_variables: null
22
+ template: "\nYou are an instructional designer tasked with creating engaging\
23
+ \ and comprehensive content for training modules. \nYour goal is to generate\
24
+ \ detailed educational material that fully explains each sub module, ensuring\
25
+ \ that employees gain \na complete understanding of the subject matter.\n\n\
26
+ Task: Produce valid Markdown output containing the **content** for the following\
27
+ \ training module.\n\nModule Details:\n{{module}}\n\nInstructions:\n- Return\
28
+ \ only a Markdown document that follows the provided format (no extra text).\n\
29
+ - Do not include code fences or additional commentary.\n- Ensure that the\
30
+ \ content in each sub module is sufficiently detailed to properly educate\
31
+ \ an employee.\n\nExample Format:\n<start>\n## Content\n\n### Subtopic 1\n\
32
+ Detailed content explaining the topic comprehensively.\n\n### Subtopic 2\n\
33
+ In-depth explanation covering all necessary details.\n<stop>\n\n{% if invalid_replies\
34
+ \ and error_message %}\nYour previous Markdown output was invalid. Error:\
35
+ \ {{error_message}}. \nPlease return only valid Markdown, with no extra text,\
36
+ \ enclosed by <start> and <stop>.\n{% endif %}\n"
37
+ variables: null
38
+ type: haystack.components.builders.prompt_builder.PromptBuilder
39
+ connections:
40
+ - receiver: llm.prompt
41
+ sender: prompt_builder.prompt
42
+ max_runs_per_component: 100
43
+ metadata: {}
pipelines/generate_module_content.py CHANGED
@@ -2,75 +2,110 @@ from haystack import Pipeline
2
  from haystack.components.builders import PromptBuilder
3
  from haystack.components.generators import HuggingFaceAPIGenerator
4
  from haystack.utils import Secret
5
- from components.output_validator import OutputValidator
6
- from components.json_grabber import JSONGrabber
7
- from classes import ModuleContent
8
- from haystack.core.pipeline.template import Path
9
 
10
- # Template for generating dialog and content for each module
11
  content_template = """
12
- You are an instructional designer tasked with creating engaging and comprehensive content alongside interactive learning activities
13
- for training modules. Your goal is to generate detailed educational material that fully explains each sub module, ensuring that
14
- employees gain a complete understanding of the subject matter.
15
-
16
- Task: Produce valid JSON output for the following training module.
17
- Module Details:
18
- {{module}}
19
-
20
- Instructions:
21
- - Return only a JSON object that strictly follows the provided schema (no extra text).
22
- - Enclose the JSON between <start> and <stop>.
23
- - Do not include code fences or additional commentary.
24
- - Ensure that the content in each sub module is sufficiently detailed to properly educate an employee.
25
- Example Format: <start> {
26
- "content": { "Subtopic1": "detailed content explaining the topic comprehensively",
27
- "Subtopic2": "in-depth explanation covering all necessary details" },
28
- "activities": { "Subtopic1": "interactive activity or exercise for practice",
29
- "Subtopic2": "engaging learning activity to reinforce the content" } } <stop>
30
-
31
- {% if invalid_replies and error_message %} Your previous JSON output was invalid. Error: {{error_message}}.
32
- Please return only valid JSON, with no extra text, enclosed by <start> and <stop>. {% endif %}
 
 
 
 
 
 
33
  """
34
 
 
35
  builder = PromptBuilder(template=content_template)
36
-
37
  generator = HuggingFaceAPIGenerator(
38
  api_type="serverless_inference_api",
39
  api_params={"model": "meta-llama/Llama-3.2-3B-Instruct"},
40
  token=Secret.from_env_var("HF_API_TOKEN"),
41
- generation_kwargs={"max_new_tokens": 1000, "stop": ["<stop>"]},
42
  )
43
 
44
  pipeline = Pipeline()
45
- pipeline.add_component("prompt_builder", PromptBuilder(template=content_template))
46
  pipeline.add_component("llm", generator)
47
- pipeline.add_component("json_grabber", instance=JSONGrabber())
48
- pipeline.add_component(
49
- "output_validator", instance=OutputValidator(pydantic_model=ModuleContent)
50
- )
51
  pipeline.connect("prompt_builder", "llm")
52
- pipeline.connect("llm.replies", "json_grabber.replies")
53
- pipeline.connect("json_grabber.body", "output_validator.body")
54
 
55
- # Save the pipeline as a YAML file and generate a diagram
56
  with open("./pipelines/generate_module_content.yml", "w") as file:
57
  pipeline.dump(file)
58
 
59
- pipeline.draw(path=Path("generate_module_content.png"))
 
 
 
 
 
60
 
61
- # Function to run the pipeline for all modules in the outline
 
 
 
 
 
 
 
 
 
62
  def generate_content_for_outline(outline):
63
- results = {}
 
64
  for module in outline["modules"]:
65
- module_result = pipeline.run(
66
- {
 
 
 
 
 
 
 
 
67
  "prompt_builder": {
68
- "module": module,
 
 
 
69
  }
70
- }
71
- )
72
- results[module["name"]] = module_result
73
- return results
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  # Example outline to test the script
76
  updated_outline = {
@@ -82,7 +117,7 @@ updated_outline = {
82
  "subtopics": [
83
  "Definition of customer service",
84
  "Importance of customer service",
85
- ]
86
  },
87
  {
88
  "name": "Handling Customer Complaints",
@@ -90,11 +125,11 @@ updated_outline = {
90
  "subtopics": [
91
  "Types of customer complaints",
92
  "How to handle customer complaints",
93
- ]
94
  },
95
  ],
96
  }
97
 
98
- # Generate dialog and content for the updated outline
99
  module_content = generate_content_for_outline(updated_outline)
100
  print(module_content)
 
2
  from haystack.components.builders import PromptBuilder
3
  from haystack.components.generators import HuggingFaceAPIGenerator
4
  from haystack.utils import Secret
5
+ from pathlib import Path
6
+ from haystack.core.errors import PipelineDrawingError
 
 
7
 
8
+ # Template for generating detailed module content
9
  content_template = """
10
+ You are an instructional designer. Create a detailed, educational Markdown module titled "{{name}}" that takes {{duration}} to read.
11
+
12
+ - Use **200 WPM** for general topics or **150 WPM** for technical ones.
13
+ - Target word count: {{word_count}} ±5%.
14
+ - Output valid **Markdown only** using the structure below.
15
+ - Do **not** include code fences, extra commentary, or repeat "### End".
16
+
17
+ ### Structure:
18
+ # {{name}}
19
+ **Estimated Reading Time: {{duration}}**
20
+
21
+ ## Introduction
22
+ - Brief intro to the topic.
23
+
24
+ ## Key Concepts
25
+ {{formatted_subtopics}}
26
+
27
+ ## Explanation
28
+ - Detailed explanation using paragraphs, bullets, and examples.
29
+
30
+ ## Examples
31
+ - Include at least one relevant example.
32
+
33
+ ## Summary
34
+ - Key takeaways.
35
+
36
+ ### End
37
  """
38
 
39
+ # Create pipeline components
40
  builder = PromptBuilder(template=content_template)
 
41
  generator = HuggingFaceAPIGenerator(
42
  api_type="serverless_inference_api",
43
  api_params={"model": "meta-llama/Llama-3.2-3B-Instruct"},
44
  token=Secret.from_env_var("HF_API_TOKEN"),
45
+ generation_kwargs={"max_new_tokens": 5000, "stop": ["<stop>"]},
46
  )
47
 
48
  pipeline = Pipeline()
49
+ pipeline.add_component("prompt_builder", builder)
50
  pipeline.add_component("llm", generator)
 
 
 
 
51
  pipeline.connect("prompt_builder", "llm")
 
 
52
 
53
+ # Save the pipeline as a YAML file and attempt to draw a diagram
54
  with open("./pipelines/generate_module_content.yml", "w") as file:
55
  pipeline.dump(file)
56
 
57
+ try:
58
+ pipeline.draw(path=Path("generate_module_content_pipeline.png"))
59
+ except PipelineDrawingError:
60
+ print("⚠️ Mermaid diagram could not be generated (likely offline). Skipping pipeline drawing.")
61
+ except Exception as e:
62
+ print(f"⚠️ Unexpected error while drawing pipeline: {e}")
63
 
64
+ # Ensure output directory exists
65
+ Path("./modules").mkdir(parents=True, exist_ok=True)
66
+
67
+ # Detect technical modules
68
+ def is_technical_topic(module_name, subtopics):
69
+ keywords = ["API", "database", "code", "technical", "machine learning", "AI", "infrastructure", "engineering", "system", "security", "algorithm"]
70
+ combined_text = f"{module_name} {' '.join(subtopics)}".lower()
71
+ return any(keyword in combined_text for keyword in keywords)
72
+
73
+ # Generate content for all modules in the outline
74
  def generate_content_for_outline(outline):
75
+ content_results = {}
76
+
77
  for module in outline["modules"]:
78
+ is_technical = is_technical_topic(module['name'], module['subtopics'])
79
+ reading_speed = 150 if is_technical else 200
80
+ minutes = int(module['duration'].split()[0])
81
+ word_count = int(minutes * reading_speed)
82
+ formatted_subtopics = "\n".join([f"- {sub}" for sub in module["subtopics"]])
83
+
84
+ print(f"Generating '{module['name']}' at {reading_speed} WPM → {word_count} words")
85
+
86
+ try:
87
+ result = pipeline.run({
88
  "prompt_builder": {
89
+ "name": module['name'],
90
+ "duration": module['duration'],
91
+ "word_count": word_count,
92
+ "formatted_subtopics": formatted_subtopics,
93
  }
94
+ })
95
+
96
+ markdown_output = result["llm"]["replies"][0]
97
+ content_results[module["name"]] = markdown_output
98
+
99
+ # Save to .md file
100
+ filename = module["name"].replace(" ", "_").lower()
101
+ with open(f"./modules/{filename}.md", "w", encoding="utf-8") as f:
102
+ f.write(markdown_output)
103
+
104
+ except Exception as e:
105
+ print(f"Error generating content for module '{module['name']}': {e}")
106
+ content_results[module["name"]] = {"error": str(e)}
107
+
108
+ return content_results
109
 
110
  # Example outline to test the script
111
  updated_outline = {
 
117
  "subtopics": [
118
  "Definition of customer service",
119
  "Importance of customer service",
120
+ ],
121
  },
122
  {
123
  "name": "Handling Customer Complaints",
 
125
  "subtopics": [
126
  "Types of customer complaints",
127
  "How to handle customer complaints",
128
+ ],
129
  },
130
  ],
131
  }
132
 
133
+ # Generate content for the updated outline
134
  module_content = generate_content_for_outline(updated_outline)
135
  print(module_content)
pipelines/generate_module_content.yml CHANGED
@@ -1,14 +1,11 @@
1
  components:
2
- json_grabber:
3
- init_parameters: {}
4
- type: components.json_grabber.JSONGrabber
5
  llm:
6
  init_parameters:
7
  api_params:
8
  model: meta-llama/Llama-3.2-3B-Instruct
9
  api_type: serverless_inference_api
10
  generation_kwargs:
11
- max_new_tokens: 1000
12
  stop:
13
  - <stop>
14
  stop_sequences: []
@@ -19,37 +16,23 @@ components:
19
  strict: true
20
  type: env_var
21
  type: haystack.components.generators.hugging_face_api.HuggingFaceAPIGenerator
22
- output_validator:
23
- pydantic_model: classes.ModuleContent
24
- type: components.output_validator.OutputValidator
25
  prompt_builder:
26
  init_parameters:
27
  required_variables: null
28
- template: "\nYou are an instructional designer tasked with creating engaging\
29
- \ and comprehensive content alongside interactive learning activities \nfor\
30
- \ training modules. Your goal is to generate detailed educational material\
31
- \ that fully explains each sub module, ensuring that \nemployees gain a complete\
32
- \ understanding of the subject matter.\n\nTask: Produce valid mark down output\
33
- \ for the following training module.\nModule Details:\n{{module}}\n\nInstructions:\n\
34
- - Enclose the mark down between <start> and <stop>.\n- Do not include code\
35
- \ fences or additional commentary.\n- Ensure that the content in each sub\
36
- \ module is sufficiently detailed to properly educate an employee.\nExample\
37
- \ Format: <start> {\n \"content\": { \"Subtopic1\": \"detailed content explaining\
38
- \ the topic comprehensively\", \n\"Subtopic2\": \"in-depth explanation covering\
39
- \ all necessary details\" }, \n\"activities\": { \"Subtopic1\": \"interactive\
40
- \ activity or exercise for practice\",\n \"Subtopic2\": \"engaging learning\
41
- \ activity to reinforce the content\" } } <stop>\n\n{% if invalid_replies\
42
- \ and error_message %} Your previous JSON output was invalid. Error: {{error_message}}.\
43
- \ \nPlease return only valid JSON, with no extra text, enclosed by <start>\
44
- \ and <stop>. {% endif %}\n"
45
  variables: null
46
  type: haystack.components.builders.prompt_builder.PromptBuilder
47
  connections:
48
  - receiver: llm.prompt
49
  sender: prompt_builder.prompt
50
- - receiver: json_grabber.replies
51
- sender: llm.replies
52
- - receiver: output_validator.body
53
- sender: json_grabber.body
54
  max_runs_per_component: 100
55
  metadata: {}
 
1
  components:
 
 
 
2
  llm:
3
  init_parameters:
4
  api_params:
5
  model: meta-llama/Llama-3.2-3B-Instruct
6
  api_type: serverless_inference_api
7
  generation_kwargs:
8
+ max_new_tokens: 5000
9
  stop:
10
  - <stop>
11
  stop_sequences: []
 
16
  strict: true
17
  type: env_var
18
  type: haystack.components.generators.hugging_face_api.HuggingFaceAPIGenerator
 
 
 
19
  prompt_builder:
20
  init_parameters:
21
  required_variables: null
22
+ template: "\nYou are an instructional designer. Create a detailed, educational\
23
+ \ Markdown module titled \"{{name}}\" that takes {{duration}} to read.\n\n\
24
+ - Use **200 WPM** for general topics or **150 WPM** for technical ones.\n\
25
+ - Target word count: {{word_count}} \xB15%.\n- Output valid **Markdown only**\
26
+ \ using the structure below.\n- Do **not** include code fences, extra commentary,\
27
+ \ or repeat \"### End\".\n\n### Structure:\n# {{name}}\n**Estimated Reading\
28
+ \ Time: {{duration}}**\n\n## Introduction\n- Brief intro to the topic.\n\n\
29
+ ## Key Concepts\n{{formatted_subtopics}}\n\n## Explanation\n- Detailed explanation\
30
+ \ using paragraphs, bullets, and examples.\n\n## Examples\n- Include at least\
31
+ \ one relevant example.\n\n## Summary\n- Key takeaways.\n\n### End\n"
 
 
 
 
 
 
 
32
  variables: null
33
  type: haystack.components.builders.prompt_builder.PromptBuilder
34
  connections:
35
  - receiver: llm.prompt
36
  sender: prompt_builder.prompt
 
 
 
 
37
  max_runs_per_component: 100
38
  metadata: {}
pipelines/generate_outline.png DELETED
Binary file (100 kB)