Commit ·
a817a92
1
Parent(s): 2e28ff5
updated name of generate_script to generate_outline to better reflect function
Browse files
app.py
CHANGED
|
@@ -29,9 +29,9 @@ class ScriptRequest(BaseModel):
|
|
| 29 |
time: str
|
| 30 |
|
| 31 |
|
| 32 |
-
@app.post("/generate-
|
| 33 |
async def generate_script(req: ScriptRequest):
|
| 34 |
-
with open("./pipelines/
|
| 35 |
content = file.read()
|
| 36 |
|
| 37 |
pipe = Pipeline.loads(content)
|
|
|
|
| 29 |
time: str
|
| 30 |
|
| 31 |
|
| 32 |
+
@app.post("/generate-outline")
|
| 33 |
async def generate_script(req: ScriptRequest):
|
| 34 |
+
with open("./pipelines/generate_outline.yml", "r") as file:
|
| 35 |
content = file.read()
|
| 36 |
|
| 37 |
pipe = Pipeline.loads(content)
|
pipelines/{generate_script.py → generate_outline.py}
RENAMED
|
@@ -45,7 +45,7 @@ pipeline.connect("json_grabber.body", "output_validator.body")
|
|
| 45 |
pipeline.connect("output_validator.invalid_replies", "prompt_builder.invalid_replies")
|
| 46 |
pipeline.connect("output_validator.error_message", "prompt_builder.error_message")
|
| 47 |
|
| 48 |
-
with open("./pipelines/
|
| 49 |
pipeline.dump(file)
|
| 50 |
|
| 51 |
|
|
|
|
| 45 |
pipeline.connect("output_validator.invalid_replies", "prompt_builder.invalid_replies")
|
| 46 |
pipeline.connect("output_validator.error_message", "prompt_builder.error_message")
|
| 47 |
|
| 48 |
+
with open("./pipelines/generate_outline.yml", "w") as file:
|
| 49 |
pipeline.dump(file)
|
| 50 |
|
| 51 |
|
pipelines/{generate_script.yml → generate_outline.yml}
RENAMED
|
File without changes
|
pipelines/update_script.py
CHANGED
|
@@ -2,26 +2,43 @@ 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 |
|
| 6 |
template = """
|
| 7 |
-
You are a training manager
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
-
|
| 18 |
-
-
|
| 19 |
-
-
|
| 20 |
-
-
|
| 21 |
-
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
"""
|
| 26 |
|
| 27 |
builder = PromptBuilder(template=template)
|
|
@@ -30,18 +47,28 @@ generator = HuggingFaceAPIGenerator(
|
|
| 30 |
api_type="serverless_inference_api",
|
| 31 |
api_params={"model": "meta-llama/Meta-Llama-3-8B-Instruct"},
|
| 32 |
token=Secret.from_env_var("HF_API_TOKEN"),
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
pipeline = Pipeline()
|
| 36 |
pipeline.add_component("prompt_builder", PromptBuilder(template=template))
|
| 37 |
pipeline.add_component("llm", generator)
|
| 38 |
pipeline.connect("prompt_builder", "llm")
|
| 39 |
-
|
| 40 |
-
with open("update_script.yml", "w") as file:
|
| 41 |
pipeline.dump(file)
|
| 42 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
results = pipeline.run(
|
| 44 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
)
|
| 46 |
print(results)
|
| 47 |
-
"""
|
|
|
|
| 2 |
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.
|
| 9 |
+
**Task**: Revise the following script based on the provided notes.
|
| 10 |
+
**Script**:
|
| 11 |
+
{{script}}
|
| 12 |
+
**Notes**:
|
| 13 |
+
{{notes}}
|
| 14 |
+
**Schema**: The script follows the provided JSON schema, which you can refer to here: [Schema Link or Description].
|
| 15 |
+
**Instructions**:
|
| 16 |
+
- Ensure the response is a JSON object that strictly follows the schema.
|
| 17 |
+
- Make sure your response is a dict and not a list.
|
| 18 |
+
- Only return the updated JSON object.
|
| 19 |
+
- Do not include the schema in your response.
|
| 20 |
+
- Put this string: "<start>" right before the JSON object.
|
| 21 |
+
- Put this string: "<stop>" right after the JSON object.
|
| 22 |
+
- Ensure the response is unique and does not repeat any previous content.
|
| 23 |
+
**Example Format**:
|
| 24 |
+
<start>
|
| 25 |
+
{
|
| 26 |
+
"title": "Example Title",
|
| 27 |
+
"objectives": ["Objective 1", "Objective 2"],
|
| 28 |
+
"duration": "1 hour",
|
| 29 |
+
"modules": [
|
| 30 |
+
{
|
| 31 |
+
"name": "Module 1",
|
| 32 |
+
"duration": "10 minutes",
|
| 33 |
+
"subtopics": ["Subtopic 1", "Subtopic 2"],
|
| 34 |
+
"features": ["video"]
|
| 35 |
+
}
|
| 36 |
+
],
|
| 37 |
+
"summary": "Example summary."
|
| 38 |
+
}
|
| 39 |
+
<stop>
|
| 40 |
+
**Schema Reference**:
|
| 41 |
+
{{schema}}
|
| 42 |
"""
|
| 43 |
|
| 44 |
builder = PromptBuilder(template=template)
|
|
|
|
| 47 |
api_type="serverless_inference_api",
|
| 48 |
api_params={"model": "meta-llama/Meta-Llama-3-8B-Instruct"},
|
| 49 |
token=Secret.from_env_var("HF_API_TOKEN"),
|
| 50 |
+
generation_kwargs={"max_new_tokens": 1024, "stop": ["<stop>"]},
|
| 51 |
)
|
| 52 |
|
| 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 |
+
{
|
| 67 |
+
"prompt_builder": {
|
| 68 |
+
"script": test_script,
|
| 69 |
+
"schema": CourseOutline.model_json_schema(),
|
| 70 |
+
"notes": "Add a module to talk about how to handle unjustifiedly rude customers",
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
)
|
| 74 |
print(results)
|
|
|