Skip to content

Commit

Permalink
Refactor prompt handling WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlicardo committed Jan 10, 2025
1 parent 38e58ed commit 21f5694
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 372 deletions.
3 changes: 3 additions & 0 deletions src/bpmn_assistant/prompts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .prompt_template_processor import PromptTemplateProcessor

__all__ = ["PromptTemplateProcessor"]
323 changes: 0 additions & 323 deletions src/bpmn_assistant/prompts/create_bpmn.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Message history:

::message_history
{{ message_history }}

---

Expand All @@ -12,7 +12,7 @@ The last user message indicates that the user wanted to create or modify a BPMN

You have made the requested modification to the BPMN process, and this is the updated BPMN process in JSON format:
```json
::process
{{ process }}
```

Make a final comment to the user, explaining that the BPMN process has been successfully created or modified.
Expand Down
45 changes: 45 additions & 0 deletions src/bpmn_assistant/prompts/prompt_template_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os

from jinja2 import Environment, FileSystemLoader, select_autoescape


class PromptTemplateProcessor:
def __init__(self, prompts_dir=os.path.dirname(os.path.abspath(__file__))):
"""
Initialize the template processor with a directory containing prompt templates.
Args:
prompts_dir (str): Path to the directory containing prompt templates
"""
self.env = Environment(
loader=FileSystemLoader(prompts_dir),
autoescape=select_autoescape(),
trim_blocks=True,
lstrip_blocks=True,
)

def render_template(self, template_name, **kwargs):
"""
Render a template with the provided variables.
Args:
template_name (str): Name of the template file
**kwargs: Variables to pass to the template
Returns:
str: Rendered template string
"""
template = self.env.get_template(template_name)
return template.render(**kwargs)


if __name__ == "__main__":
processor = PromptTemplateProcessor()

variables = {
"message_history": "This should be the message history!",
# "process": "This should be the BPMN process, which is optional!",
}

prompt = processor.render_template("respond_to_query.jinja2", **variables)
print(prompt)
Loading

0 comments on commit 21f5694

Please sign in to comment.