Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: support Jinja2 templating #5483

Merged
merged 7 commits into from
Mar 15, 2024
Merged

Python: support Jinja2 templating #5483

merged 7 commits into from
Mar 15, 2024

Conversation

moonbox3
Copy link
Contributor

Motivation and Context

Jinja2 is a heavily supported Python templating language and we're introducing it to SK Python.

Description

This PR brings in the ability to specify Jinja2 templates for use within SK Python:

Contribution Checklist

@moonbox3 moonbox3 requested a review from a team as a code owner March 14, 2024 21:09
@markwallace-microsoft markwallace-microsoft added the python Pull requests for the Python Semantic Kernel label Mar 14, 2024
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Mar 14, 2024

Py3.8 Test Coverage

Python 3.8 Test Coverage Report •
FileStmtsMissCoverMissing
semantic_kernel
   kernel.py3242991%195–199, 201–205, 207–211, 219–221, 240, 246, 248–252, 254–258, 260–265, 267, 312–316, 333–338, 345, 349–353, 366, 625
semantic_kernel/functions
   kernel_function.py64297%136, 155
TOTAL522799981% 

Python 3.8 Unit Test Overview

Tests Skipped Failures Errors Time
1131 11 💤 0 ❌ 0 🔥 20.223s ⏱️

Copy link
Contributor

@juliomenendez juliomenendez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a couple questions and sorry if I'm missing something but what's the difference between create_handlebars_helper_from_function and create_jinja2_helper_from_function?

python/pyproject.toml Outdated Show resolved Hide resolved
@moonbox3
Copy link
Contributor Author

Looks good. Just a couple questions and sorry if I'm missing something but what's the difference between create_handlebars_helper_from_function and create_jinja2_helper_from_function?

As we talked about offline, the handlebars helper function has a this parameter that contains the context when called by the compiler.

Copy link
Member

@eavanvalkenburg eavanvalkenburg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! One small nit to update, but otherwise let's get it in!

@moonbox3 moonbox3 enabled auto-merge March 15, 2024 13:19
@moonbox3 moonbox3 added this pull request to the merge queue Mar 15, 2024
Merged via the queue into microsoft:main with commit 0a1a7ca Mar 15, 2024
30 checks passed
@moonbox3 moonbox3 deleted the jinja2 branch March 15, 2024 13:31
LudoCorporateShark pushed a commit to LudoCorporateShark/semantic-kernel that referenced this pull request Aug 25, 2024
### Motivation and Context

Jinja2 is a heavily supported Python templating language and we're
introducing it to SK Python.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

This PR brings in the ability to specify Jinja2 templates for use within
SK Python:
- Closes microsoft#5343 

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests for the Python Semantic Kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python: Jinja2 prompt template support for Python
4 participants