Skip to content

Commit

Permalink
Merge pull request #48 from microsoft/python
Browse files Browse the repository at this point in the history
added more precise versioning
  • Loading branch information
sethjuarez authored Jul 23, 2024
2 parents d53e67a + 527d28c commit cf179df
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 28 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/prompty-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
- uses: actions/checkout@v4

- uses: pdm-project/setup-pdm@v4
with:
python-version: 3.9
cache: true

- name: install dependencies
working-directory: ./runtime/prompty
Expand All @@ -36,14 +39,6 @@ jobs:
working-directory: ./runtime/prompty
run: pdm run pytest

- name: build package
working-directory: ./runtime/prompty
run: pdm build -vv

- name: package version
working-directory: ./runtime/prompty
run: cat prompty/_version.py

- name: Publish package distributions to PyPI
working-directory: ./runtime/prompty
run: pdm publish
10 changes: 0 additions & 10 deletions runtime/prompty/prompty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@
from .parsers import *
from .executors import *
from .processors import *
from ._version import __version__

__all__ = [
"load",
"prepare",
"run",
"execute",
"headless",
"__version__",
]


def load_global_config(
Expand Down
1 change: 0 additions & 1 deletion runtime/prompty/prompty/_version.py

This file was deleted.

14 changes: 7 additions & 7 deletions runtime/prompty/prompty/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from .tracer import Trace
from openai import AzureOpenAI
from .core import Invoker, InvokerFactory, Prompty
from ._version import __version__
import importlib.metadata

VERSION = importlib.metadata.version("prompty")


@InvokerFactory.register_executor("azure")
Expand Down Expand Up @@ -38,8 +40,8 @@ def __init__(self, prompty: Prompty) -> None:

self.client = AzureOpenAI(
default_headers={
"User-Agent": f"prompty/{__version__}",
"x-ms-useragent": f"prompty/{__version__}",
"User-Agent": f"prompty{VERSION}",
"x-ms-useragent": f"prompty/{VERSION}",
},
**kwargs,
)
Expand Down Expand Up @@ -67,7 +69,7 @@ def invoke(self, data: any) -> any:
messages=data if isinstance(data, list) else [data],
**self.parameters,
)

elif self.api == "completion":
response = self.client.completions.create(
prompt=data.item,
Expand All @@ -82,14 +84,12 @@ def invoke(self, data: any) -> any:
**self.parameters,
)



elif self.api == "image":
raise NotImplementedError("Azure OpenAI Image API is not implemented yet")

if hasattr(response, "usage") and response.usage:
Trace.add("completion_tokens", response.usage.completion_tokens)
Trace.add("prompt_tokens", response.usage.prompt_tokens)
Trace.add("total_tokens", response.usage.total_tokens)

return response
3 changes: 1 addition & 2 deletions runtime/prompty/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ dev = ["pytest>=8.2.2"]
source = "scm"
tag_filter = "python/*"
tag_regex = '^python/(?:\D*)?(?P<version>([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|c|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev(0|[1-9][0-9]*))?$)$'
write_to = "../prompty/_version.py"
write_template = "__version__ = '{}'"


[tool.pdm.scripts]
prompty = { call = "prompty.cli:run" }
Expand Down

0 comments on commit cf179df

Please sign in to comment.