martinezjandrew commited on
Commit
3b671a6
·
1 Parent(s): eb58818

update_outline is now working and updated root page

Browse files
app.py CHANGED
@@ -26,9 +26,10 @@ async def root():
26
  <body>
27
  <h1>Welcome to TrainingCourseGen!</h1>
28
  <p>This is a tool to create generative courses for training managers.</p>
29
- <p><a href="https://github.com/Zoqi-Andrew-Senior-Project/ScriboAI-Consumer">Github for customer-serving side of the project.</p>
30
  <p><a href="https://martinezjandrew-trainingcoursegen.hf.space/docs">Hugging Face Space hosted Docs.</a></p>
31
  <p><a href="http://localhost:8000/docs">Local host hosted docs</a></p>
 
32
  """
33
  return HTMLResponse(content=content, status_code=200)
34
 
@@ -63,9 +64,9 @@ class ScriptUpdate(BaseModel):
63
  notes: str = ""
64
 
65
 
66
- @app.post("/update-script")
67
  async def update_script(req: ScriptUpdate):
68
- with open("./pipelines/update_script.yml", "r") as file:
69
  content = file.read()
70
 
71
  pipe = Pipeline.loads(content)
 
26
  <body>
27
  <h1>Welcome to TrainingCourseGen!</h1>
28
  <p>This is a tool to create generative courses for training managers.</p>
29
+ <p><a href="https://github.com/Zoqi-Andrew-Senior-Project/ScriboAI-Consumer" target="_blank" rel="noopener noreferrer">Github for customer-serving side of the project.</p>
30
  <p><a href="https://martinezjandrew-trainingcoursegen.hf.space/docs">Hugging Face Space hosted Docs.</a></p>
31
  <p><a href="http://localhost:8000/docs">Local host hosted docs</a></p>
32
+ </html>
33
  """
34
  return HTMLResponse(content=content, status_code=200)
35
 
 
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:
70
  content = file.read()
71
 
72
  pipe = Pipeline.loads(content)
pipelines/generate_outline.png ADDED
pipelines/generate_outline.py CHANGED
@@ -5,6 +5,7 @@ from haystack.utils import Secret
5
  from components.output_validator import OutputValidator
6
  from components.json_grabber import JSONGrabber
7
  from classes import CourseOutline
 
8
 
9
  output_validator = OutputValidator(pydantic_model=CourseOutline)
10
 
@@ -38,7 +39,6 @@ pipeline.add_component("prompt_builder", PromptBuilder(template=template))
38
  pipeline.add_component("llm", generator)
39
  pipeline.add_component("json_grabber", instance=JSONGrabber())
40
  pipeline.add_component("output_validator", output_validator)
41
-
42
  pipeline.connect("prompt_builder", "llm")
43
  pipeline.connect("llm.replies", "json_grabber.replies")
44
  pipeline.connect("json_grabber.body", "output_validator.body")
@@ -48,6 +48,7 @@ pipeline.connect("output_validator.error_message", "prompt_builder.error_message
48
  with open("./pipelines/generate_outline.yml", "w") as file:
49
  pipeline.dump(file)
50
 
 
51
 
52
  """
53
 
@@ -63,9 +64,6 @@ results = pipeline.run(
63
  }
64
  }
65
  )
66
- from haystack.core.pipeline.template import Path
67
-
68
- pipeline.draw(path=Path("pipeline.png"))
69
  print(type(results))
70
  print(results)
71
  """
 
5
  from components.output_validator import OutputValidator
6
  from components.json_grabber import JSONGrabber
7
  from classes import CourseOutline
8
+ from haystack.core.pipeline.template import Path
9
 
10
  output_validator = OutputValidator(pydantic_model=CourseOutline)
11
 
 
39
  pipeline.add_component("llm", generator)
40
  pipeline.add_component("json_grabber", instance=JSONGrabber())
41
  pipeline.add_component("output_validator", output_validator)
 
42
  pipeline.connect("prompt_builder", "llm")
43
  pipeline.connect("llm.replies", "json_grabber.replies")
44
  pipeline.connect("json_grabber.body", "output_validator.body")
 
48
  with open("./pipelines/generate_outline.yml", "w") as file:
49
  pipeline.dump(file)
50
 
51
+ pipeline.draw(path=Path("generate_outline.png"))
52
 
53
  """
54
 
 
64
  }
65
  }
66
  )
 
 
 
67
  print(type(results))
68
  print(results)
69
  """
pipelines/{update_script.py → update_outline.py} RENAMED
@@ -3,6 +3,9 @@ from haystack.components.builders import PromptBuilder
3
  from haystack.components.generators import HuggingFaceAPIGenerator
4
  from haystack.utils import Secret
5
  from classes import CourseOutline
 
 
 
6
 
7
  template = """
8
  You are a training manager tasked with creating an online, asynchronous course for new employees.
@@ -39,6 +42,11 @@ You are a training manager tasked with creating an online, asynchronous course f
39
  <stop>
40
  **Schema Reference**:
41
  {{schema}}
 
 
 
 
 
42
  """
43
 
44
  builder = PromptBuilder(template=template)
@@ -53,14 +61,60 @@ generator = HuggingFaceAPIGenerator(
53
  pipeline = Pipeline()
54
  pipeline.add_component("prompt_builder", PromptBuilder(template=template))
55
  pipeline.add_component("llm", generator)
 
 
 
 
56
  pipeline.connect("prompt_builder", "llm")
57
- """
 
 
 
 
58
  with open("./pipelines/update_script.yml", "w") as file:
59
  pipeline.dump(file)
 
 
 
60
  """
61
 
62
  test_script = """
63
- {'title': 'Customer Service Essentials', 'objectives': ['Understand the importance of customer service', 'Learn how to handle customer complaints', 'Develop effective communication skills'], 'duration': '1 hour', 'modules': [{'name': 'Introduction to Customer Service', 'duration': '10 minutes', 'subtopics': ['Definition of customer service', 'Importance of customer service'], 'features': ['video']}, {'name': 'Handling Customer Complaints', 'duration': '20 minutes', 'subtopics': ['Types of customer complaints', 'How to handle customer complaints'], 'features': ['interactive']}, {'name': 'Effective Communication Skills', 'duration': '30 minutes', 'subtopics': ['Active listening', 'Clear communication'], 'features': ['image']}], 'summary': 'This course provides an overview of customer service essentials, including how to handle customer complaints and develop effective communication skills.'}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  """
65
  results = pipeline.run(
66
  {
@@ -72,3 +126,4 @@ results = pipeline.run(
72
  }
73
  )
74
  print(results)
 
 
3
  from haystack.components.generators import HuggingFaceAPIGenerator
4
  from haystack.utils import Secret
5
  from classes import CourseOutline
6
+ from components.output_validator import OutputValidator
7
+ from components.json_grabber import JSONGrabber
8
+ from haystack.core.pipeline.template import Path
9
 
10
  template = """
11
  You are a training manager tasked with creating an online, asynchronous course for new employees.
 
42
  <stop>
43
  **Schema Reference**:
44
  {{schema}}
45
+ {% if invalid_replies and error_message %}
46
+ You already created the following output in a previous attempt: {{invalid_replies}}
47
+ However, this doesn't comply with the format requirements from above and triggered this Python exception: {{error_message}}
48
+ Correct the output and try again. Just return the corrected output without any extra explanations.
49
+ {% endif %}
50
  """
51
 
52
  builder = PromptBuilder(template=template)
 
61
  pipeline = Pipeline()
62
  pipeline.add_component("prompt_builder", PromptBuilder(template=template))
63
  pipeline.add_component("llm", generator)
64
+ pipeline.add_component("json_grabber", instance=JSONGrabber())
65
+ pipeline.add_component(
66
+ "output_validator", instance=OutputValidator(pydantic_model=CourseOutline)
67
+ )
68
  pipeline.connect("prompt_builder", "llm")
69
+ pipeline.connect("llm.replies", "json_grabber.replies")
70
+ pipeline.connect("json_grabber.body", "output_validator.body")
71
+ pipeline.connect("output_validator.invalid_replies", "prompt_builder.invalid_replies")
72
+ pipeline.connect("output_validator.error_message", "prompt_builder.error_message")
73
+
74
  with open("./pipelines/update_script.yml", "w") as file:
75
  pipeline.dump(file)
76
+
77
+ pipeline.draw(path=Path("update_outline.png"))
78
+
79
  """
80
 
81
  test_script = """
82
+ {
83
+ "title": "Customer Service Essentials",
84
+ "objectives": [
85
+ "Understand the importance of customer service",
86
+ "Learn how to handle customer complaints",
87
+ "Develop effective communication skills",
88
+ ],
89
+ "duration": "1 hour",
90
+ "modules": [
91
+ {
92
+ "name": "Introduction to Customer Service",
93
+ "duration": "10 minutes",
94
+ "subtopics": [
95
+ "Definition of customer service",
96
+ "Importance of customer service",
97
+ ],
98
+ "features": ["video"],
99
+ },
100
+ {
101
+ "name": "Handling Customer Complaints",
102
+ "duration": "20 minutes",
103
+ "subtopics": [
104
+ "Types of customer complaints",
105
+ "How to handle customer complaints",
106
+ ],
107
+ "features": ["interactive"],
108
+ },
109
+ {
110
+ "name": "Effective Communication Skills",
111
+ "duration": "30 minutes",
112
+ "subtopics": ["Active listening", "Clear communication"],
113
+ "features": ["image"],
114
+ },
115
+ ],
116
+ "summary": "This course provides an overview of customer service essentials, including how to handle customer complaints and develop effective communication skills.",
117
+ }
118
  """
119
  results = pipeline.run(
120
  {
 
126
  }
127
  )
128
  print(results)
129
+ """
pipelines/update_script.yml CHANGED
@@ -1,36 +1,64 @@
1
  components:
 
 
 
2
  llm:
3
  init_parameters:
4
  api_params:
5
  model: meta-llama/Meta-Llama-3-8B-Instruct
6
  api_type: serverless_inference_api
7
  generation_kwargs:
8
- max_new_tokens: 1028
 
 
9
  stop_sequences: []
10
  streaming_callback: null
11
  token:
12
  env_vars:
13
- - HF_API_TOKEN
14
  strict: true
15
  type: env_var
16
  type: haystack.components.generators.hugging_face_api.HuggingFaceAPIGenerator
 
 
 
17
  prompt_builder:
18
  init_parameters:
19
  required_variables: null
20
- template:
21
- "\nYou are a training manager. You are tasked to create an online,\
22
- \ asynchronous course for new employees. You previously generated a script\
23
- \ and provided it to the user. The user requested some changes to be made.\
24
- \ \nThe user provided the following feedback:\n{{ notes }}\n\nHere's the script\
25
- \ you previously created with possible changes made by the user.\n{{ script\
26
- \ }}\n\nThe outline should include the following:\n- Course Objectives\n-\
27
- \ Main Topics\n- Subtopics for each Main Topic\n- Interactive Activities (if\
28
- \ applicable)\n- Estimated time for each topic within {{ time }}\n- Assessments\
29
- \ or quizzes (if any)\n- Additional Resources\n- Conclusion\n"
 
 
 
 
 
 
 
 
 
 
 
 
30
  variables: null
31
  type: haystack.components.builders.prompt_builder.PromptBuilder
32
  connections:
33
- - receiver: llm.prompt
34
- sender: prompt_builder.prompt
 
 
 
 
 
 
 
 
35
  max_runs_per_component: 100
36
  metadata: {}
 
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/Meta-Llama-3-8B-Instruct
9
  api_type: serverless_inference_api
10
  generation_kwargs:
11
+ max_new_tokens: 1024
12
+ stop:
13
+ - <stop>
14
  stop_sequences: []
15
  streaming_callback: null
16
  token:
17
  env_vars:
18
+ - HF_API_TOKEN
19
  strict: true
20
  type: env_var
21
  type: haystack.components.generators.hugging_face_api.HuggingFaceAPIGenerator
22
+ output_validator:
23
+ pydantic_model: classes.CourseOutline
24
+ type: components.output_validator.OutputValidator
25
  prompt_builder:
26
  init_parameters:
27
  required_variables: null
28
+ template: "\nYou are a training manager tasked with creating an online, asynchronous\
29
+ \ course for new employees.\n**Task**: Revise the following script based on\
30
+ \ the provided notes.\n**Script**:\n{{script}}\n**Notes**:\n{{notes}}\n**Schema**:\
31
+ \ The script follows the provided JSON schema, which you can refer to here:\
32
+ \ [Schema Link or Description].\n**Instructions**:\n- Ensure the response\
33
+ \ is a JSON object that strictly follows the schema.\n- Make sure your response\
34
+ \ is a dict and not a list.\n- Only return the updated JSON object.\n- Do\
35
+ \ not include the schema in your response.\n- Put this string: \"<start>\"\
36
+ \ right before the JSON object.\n- Put this string: \"<stop>\" right after\
37
+ \ the JSON object.\n- Ensure the response is unique and does not repeat any\
38
+ \ previous content.\n**Example Format**:\n<start>\n{\n \"title\": \"Example\
39
+ \ Title\",\n \"objectives\": [\"Objective 1\", \"Objective 2\"],\n \"\
40
+ duration\": \"1 hour\",\n \"modules\": [\n {\n \"name\"\
41
+ : \"Module 1\",\n \"duration\": \"10 minutes\",\n \"\
42
+ subtopics\": [\"Subtopic 1\", \"Subtopic 2\"],\n \"features\":\
43
+ \ [\"video\"]\n }\n ],\n \"summary\": \"Example summary.\"\n\
44
+ }\n<stop>\n**Schema Reference**:\n{{schema}}\n{% if invalid_replies and error_message\
45
+ \ %}\n You already created the following output in a previous attempt: {{invalid_replies}}\n\
46
+ \ However, this doesn't comply with the format requirements from above and\
47
+ \ triggered this Python exception: {{error_message}}\n Correct the output\
48
+ \ and try again. Just return the corrected output without any extra explanations.\n\
49
+ {% endif %}\n"
50
  variables: null
51
  type: haystack.components.builders.prompt_builder.PromptBuilder
52
  connections:
53
+ - receiver: llm.prompt
54
+ sender: prompt_builder.prompt
55
+ - receiver: json_grabber.replies
56
+ sender: llm.replies
57
+ - receiver: output_validator.body
58
+ sender: json_grabber.body
59
+ - receiver: prompt_builder.invalid_replies
60
+ sender: output_validator.invalid_replies
61
+ - receiver: prompt_builder.error_message
62
+ sender: output_validator.error_message
63
  max_runs_per_component: 100
64
  metadata: {}