Skip to content

Commit

Permalink
update version of package
Browse files Browse the repository at this point in the history
  • Loading branch information
narenaryan committed May 10, 2024
2 parents b81e403 + 6b8f3f0 commit 9d500b3
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 59 deletions.
40 changes: 22 additions & 18 deletions examples/basic-calculator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ This is an example of how to use PromptML to generate final Generative AI prompt
1. Parse `calculator.pml` using promptml parser to generate a prompt context
2. Pass context to Jinja2 environment with a template called `calculator.jinja2`

This will print an output of below:
This will print an output of below:

```txt
Context: You are a calculator app who can perform various kinds of mathematical operations.

Follow the below instructions step-by-step for objective:
1. Think about how you can add two numbers together.
2. Return only the answer.

Domain: Education

Audience: Education
Task Difficulty: Beginner

Reply in tone: Friendly

Follow the below instructions step-by-step for objective:
1. Think about how you can add two numbers together.
2. Return only the answer.

Objective: What is the sum of 5 and 6?
```

Expand All @@ -27,26 +28,29 @@ This is the final prompt to be used for Generative AI systems.
## Running instructions

1. Create a virtual environment in this directory:
```bash

```bash
python3 -m venv .venv
```

2. Activate virtual environment

```bash
source .venv/bin/activate
```
```bash
source .venv/bin/activate
```

3. Install Jinja2 and promptml

```bash
pip install -r requirements.txt
```
```bash
pip install -r requirements.txt
```

Note: If `promptml` package is not available on PyPi, you can locally build the Wheel package and install it. See [BUILD.md](../../BUILD.md) file for instructions.
Note: If `promptml` package is not available on PyPi, you can locally build the Wheel package and install it. See [BUILD.md](../../BUILD.md) file for instructions.

4. Run the program

```bash
python main.py
```
```bash
python main.py
```

5. Play around with `calculator.pml` and re-run the program to see the change in output.
10 changes: 6 additions & 4 deletions examples/basic-calculator/calculator.jinja2
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
Context: {{ prompt.context }}

Domain: {{ prompt.metadata.domain }}

Task Difficulty: {{ prompt.constraints.difficulty }}

Reply in tone: {{ prompt.constraints.tone }}

Follow the below instructions step-by-step for objective:
{% for instruction in prompt.instructions -%}
{{loop.index}}. {{ instruction }}
{% endfor %}

Audience: {{ prompt.metadata.domain }}
Task Difficulty: {{ prompt.metadata.difficulty }}
Reply in tone: {{ prompt.constraints.tone }}

Objective: {{ prompt.objective }}
9 changes: 3 additions & 6 deletions examples/basic-calculator/calculator.pml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@
@tone
Friendly
@end
@end
@metadata
@domain
Education
@end

@difficulty
Beginner
@end
@end
@metadata
domain: 'Mathematics'
@end
@end
38 changes: 20 additions & 18 deletions examples/poem-writer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This is an example of how to use PromptML to generate final Generative AI prompt
1. Parse `poem.pml` using promptml parser to generate a prompt context
2. Pass context to Jinja2 environment with a template called `poem.jinja2`

This will print an output of below:
This will print an output of below:

```txt
Context: You are a master poem writer who is creative and imaginative. You identify the beauty in the world and express it through your words and use vivid imagery and descriptive language to create a poem.
Expand All @@ -24,17 +24,16 @@ Examples:
And the hunter home from the hill.

input: My Heart Leaps Up
output: My heart leaps up when I behold
output: My heart leaps up when I behold
A rainbow in the sky:
So was it when my life began;
So is it now I am a man;
So be it when I shall grow old,
So was it when my life began;
So is it now I am a man;
So be it when I shall grow old,
Or let me die!
The Child is father of the Man;
And I could wish my days to be
Bound each to each by natural piety.

Audience: Arts
Task Difficulty: Beginner
Reply in tone: Melancholic

Expand All @@ -46,26 +45,29 @@ This is the final prompt to be used for Generative AI systems.
## Running instructions

1. Create a virtual environment in this directory:
```bash

```bash
python3 -m venv .venv
```

2. Activate virtual environment

```bash
source .venv/bin/activate
```
```bash
source .venv/bin/activate
```

3. Install Jinja2 and promptml

```bash
pip install -r requirements.txt
```
```bash
pip install -r requirements.txt
```

Note: If `promptml` package is not available on PyPi, you can locally build the Wheel package and install it. See [BUILD.md](../../BUILD.md) file for instructions.
Note: If `promptml` package is not available on PyPi, you can locally build the Wheel package and install it. See [BUILD.md](../../BUILD.md) file for instructions.

4. Run the program

```bash
python main.py
```
```bash
python main.py
```

5. Play around with `poem.pml` by giving different examples, and re-run the program to see the change in output.
3 changes: 1 addition & 2 deletions examples/poem-writer/poem.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ Examples:
{%- endfor %}
{% endfor %}

Audience: {{ prompt.metadata.domain }}
Task Difficulty: {{ prompt.metadata.difficulty }}
Task Difficulty: {{ prompt.constraints.difficulty }}
Reply in tone: {{ prompt.constraints.tone }}

Objective: {{ prompt.objective }}
19 changes: 8 additions & 11 deletions examples/poem-writer/poem.pml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@end
@examples
@example
@input
@input
Requiem
@end
@output
Expand All @@ -28,11 +28,11 @@
@end

@output
My heart leaps up when I behold
My heart leaps up when I behold
A rainbow in the sky:
So was it when my life began;
So is it now I am a man;
So be it when I shall grow old,
So was it when my life began;
So is it now I am a man;
So be it when I shall grow old,
Or let me die!
The Child is father of the Man;
And I could wish my days to be
Expand All @@ -48,14 +48,11 @@
@tone
Melancholic
@end
@end
@metadata
@domain
Arts
@end

@difficulty
Beginner
@end
@end
@category
Poem
@end
@end
20 changes: 20 additions & 0 deletions examples/recommend-challenges/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from promptml.parser import PromptParserFromFile
from jinja2 import Environment, FileSystemLoader


def main():
template_loader = FileSystemLoader(searchpath="./")
template_env = Environment(loader=template_loader)
template_file = "recommend.jinja2"
template = template_env.get_template(template_file)

# Parse PromptML code and generate context
prompt_parser = PromptParserFromFile('recommend.pml')
prompt = prompt_parser.parse()

# Render the template with the prompt context
template_output = template.render(prompt=prompt)
print(template_output)

if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions examples/recommend-challenges/recommend.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Context: {{ prompt.context }}

Objective: {{ prompt.objective }}
18 changes: 18 additions & 0 deletions examples/recommend-challenges/recommend.pml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@prompt
@context
You are an experienced Python trainer. You understand the level of trainee and
provides guidance accordingly.
@end

@objective
Provide three Python take home challenges which have a combination of following aspects:
1. Conditional statements
2. Loops
3. User input
Return the challenges in form of a table.
@end

@category
Education & Programming
@end
@end
2 changes: 2 additions & 0 deletions examples/recommend-challenges/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jinja2
promptml

0 comments on commit 9d500b3

Please sign in to comment.