martinezjandrew commited on
Commit
71b8ef4
·
1 Parent(s): 502fa51

initial project

Browse files
.dockerignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ __pycache__/
2
+ *.pyc
3
+ README.md
4
+ .venv/
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ __pycache__/
2
+ .venv/
3
+ *.pyc
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+ ENV PATH="/home/user/.local/bin:$PATH"
9
+
10
+ WORKDIR /app
11
+
12
+ COPY --chown=user ./requirements.txt requirements.txt
13
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
+
15
+ COPY --chown=user . /app
16
+
17
+ EXPOSE 8000
18
+
19
+ #CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
20
+ CMD ["fastapi", "run", "app.py", "--port", "8000"]
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from haystack import Pipeline
3
+ from pydantic import BaseModel
4
+
5
+ app = FastAPI()
6
+
7
+
8
+ @app.get("/")
9
+ async def root():
10
+ return {"message": "Hello World"}
11
+
12
+
13
+ class Query(BaseModel):
14
+ topic: str
15
+ time: str
16
+
17
+
18
+ @app.post("/test")
19
+ async def test(query: Query):
20
+ with open("./pipelines/test.yml", "r") as file:
21
+ content = file.read()
22
+
23
+ pipe = Pipeline.loads(content)
24
+
25
+ results = pipe.run({"prompt_builder": {"topic": query.topic, "time": query.time}})
26
+
27
+ return {"response": results}
pipelines/.gradio/flagged/dataset1.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ Text,timestamp
2
+ "tell me a story about a time you were in a situation where you had to make a decision and you didn’t know what to do. What was the outcome?
3
+ I was in a situation where I had to make a decision and I didn’t know what to do. I was in a situation where I had to make a decision and I didn’t know what to do. I was in a situation where I had to make a decision and I didn’t know what to do. I was in a situation where I had",2024-11-11 00:10:45.021000
pipelines/pipeline1.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
6
+ template = """
7
+ You are a training manager. You are tasked to create an online, asynchronous course for new employees. \
8
+ Create an outline for a course about {{ topic }} with a length of {{ time }}.
9
+ The outline should include the following:
10
+ - Course Objectives
11
+ - Main Topics
12
+ - Subtopics for each Main Topic
13
+ - Interactive Activities (if applicable)
14
+ - Estimated time for each topic within {{ time }}
15
+ - Assessments or quizzes (if any)
16
+ - Additional Resources
17
+ - Conclusion
18
+ """
19
+
20
+ builder = PromptBuilder(template=template)
21
+
22
+ generator = HuggingFaceAPIGenerator(
23
+ api_type="serverless_inference_api",
24
+ api_params={"model": "meta-llama/Meta-Llama-3-8B-Instruct"},
25
+ token=Secret.from_env_var("HF_API_TOKEN"),
26
+ )
27
+
28
+ pipeline = Pipeline()
29
+ pipeline.add_component("prompt_builder", PromptBuilder(template=template))
30
+ pipeline.add_component("llm", generator)
31
+ pipeline.connect("prompt_builder", "llm")
32
+
33
+ with open("test.yml", "w") as file:
34
+ pipeline.dump(file)
35
+ """
36
+ results = pipeline.run(
37
+ {"prompt_builder": {"topic": "Artificial Intelligence", "time": "one hour"}}
38
+ )
39
+ print(results)
40
+ """
pipelines/test.yml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: 512
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
+
22
+ You are a training manager. You are tasked to create an online, asynchronous
23
+ course for new employees. Create an outline for a course about {{ topic }}
24
+ with a length of {{ time }}.
25
+
26
+ The outline should include the following:
27
+
28
+ - Course Objectives
29
+
30
+ - Main Topics
31
+
32
+ - Subtopics for each Main Topic
33
+
34
+ - Interactive Activities (if applicable)
35
+
36
+ - Estimated time for each topic within {{ time }}
37
+
38
+ - Assessments or quizzes (if any)
39
+
40
+ - Additional Resources
41
+
42
+ - Conclusion
43
+
44
+ '
45
+ variables: null
46
+ type: haystack.components.builders.prompt_builder.PromptBuilder
47
+ connections:
48
+ - receiver: llm.prompt
49
+ sender: prompt_builder.prompt
50
+ max_runs_per_component: 100
51
+ metadata: {}
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi[standard]
2
+ haystack-ai
3
+ uvicorn[standard]
4
+ huggingface_hub