Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d7f8a46
Prompty support within Azure AI Inference SDK
YusakuNo1 Oct 16, 2024
1e25075
Fix unit test
YusakuNo1 Oct 16, 2024
ffeaab8
Address PR feedback with copyright, merge PromptConfig to PromptTemplate
YusakuNo1 Oct 18, 2024
44d2f2c
Add comment and set model_name as optional
YusakuNo1 Oct 18, 2024
2d1d132
Bug fixes
YusakuNo1 Oct 22, 2024
9f7b679
Updated parameter names from PM feedbacks
YusakuNo1 Oct 22, 2024
b4f2d5b
Merge branch 'main' into users/daviwu/prompty
YusakuNo1 Oct 22, 2024
b7657e5
Merge branch 'main' into users/daviwu/prompty
YusakuNo1 Oct 28, 2024
38eb258
Improve sample code and unit tests
YusakuNo1 Oct 28, 2024
aa28df4
Update readme and comments
YusakuNo1 Oct 28, 2024
9a1eb79
Rename files
YusakuNo1 Oct 28, 2024
1252b3a
Address PR comment
YusakuNo1 Oct 29, 2024
b3e8616
add Pydantic as dependency
YusakuNo1 Oct 29, 2024
c43f88e
Fix type errors
YusakuNo1 Oct 29, 2024
e9cab12
Fix spelling issues
YusakuNo1 Oct 29, 2024
24c3ced
Address PR comments and fix linter issues
YusakuNo1 Oct 29, 2024
19316b8
Fix type import for "Self"
YusakuNo1 Oct 30, 2024
ed718cb
Change to keyword-only constructor and fix linter issues
YusakuNo1 Oct 30, 2024
ebfa1f8
Rename function `from_message` to `from_str`; `render` to `create_mes…
YusakuNo1 Nov 1, 2024
25a0365
Change from `from_str` to `from_string`
YusakuNo1 Nov 1, 2024
6b8ad60
Merge branch 'main' into users/daviwu/prompty
YusakuNo1 Nov 3, 2024
a7a0bf2
Merge latest code from `microsoft/prompty` and resolve linter issues
YusakuNo1 Nov 3, 2024
4b43b46
Fix PR comment
YusakuNo1 Nov 4, 2024
633c84f
Fix PR comments
YusakuNo1 Nov 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address PR comment
  • Loading branch information
YusakuNo1 committed Oct 29, 2024
commit 1252b3aedb054616676c13ef4af7ecc271c490e1
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@

from ._renderers import MustacheRenderer
from ._parsers import PromptyChatParser
from ._utils import load
from ._patch import patch_sdk as _patch_sdk, PromptTemplate

# Register the Mustache renderer and parser
InvokerFactory().register_renderer("mustache", MustacheRenderer)
InvokerFactory().register_parser("prompty.chat", PromptyChatParser)

__all__ = [
"load",
"Prompty",
"PromptTemplate",
]
Expand Down
17 changes: 10 additions & 7 deletions sdk/ai/azure-ai-inference/azure/ai/inference/prompts/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
"""

import azure.ai.inference.prompts as prompts
from typing import Any, Dict, List
from ._core import Prompty
from ._utils import prepare
from ._utils import load, prepare
from ._mustache import render


Expand All @@ -26,15 +26,16 @@ class PromptTemplate:
:type model_name: str
"""

@staticmethod
def from_prompty(file_path: str):
@classmethod
def from_prompty(cls, file_path: str):
if not file_path:
raise ValueError("Please provide file_path")
prompty = prompts.load(file_path)
prompty = load(file_path)
return PromptTemplate(prompty=prompty)

@staticmethod
@classmethod
def from_message(
cls,
prompt_template: str,
api: str = "chat",
model_name: str | None = None
Expand Down Expand Up @@ -64,7 +65,7 @@ def __init__(
else:
raise ValueError("Please invalid arguments for PromptConfig")

def render(self, data: dict[str, any] | None = None, **kwargs):
def render(self, data: dict[str, Any] | None = None, **kwargs) -> List[Dict[str, Any]]:
if data is None:
data = kwargs

Expand All @@ -74,6 +75,8 @@ def render(self, data: dict[str, any] | None = None, **kwargs):
elif "prompt_template" in self._parameters:
system_prompt = render(self._parameters["prompt_template"], data)
return [{"role": "system", "content": system_prompt}]
else:
raise ValueError("Please provide valid prompt template")


def patch_sdk():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
`your-azure-region` is the Azure region where your model is deployed.
2) AZURE_AI_CHAT_KEY - Your model key (a 32-character string). Keep it secret.
"""
# mypy: disable-error-code="union-attr"
# pyright: reportAttributeAccessIssue=false


def sample_chat_completions_from_input_prompt_string():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
`your-azure-region` is the Azure region where your model is deployed.
2) AZURE_AI_CHAT_KEY - Your model key (a 32-character string). Keep it secret.
"""
# mypy: disable-error-code="union-attr"
# pyright: reportAttributeAccessIssue=false


def sample_chat_completions_from_input_prompty():
Expand Down