-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new function syntax with jinja Add more capabilities to prompt fiddle --------- Co-authored-by: Sam Lijin <[email protected]> Co-authored-by: Aaron Villalpando <[email protected]>
- Loading branch information
1 parent
47404e3
commit 4582bdd
Showing
440 changed files
with
23,388 additions
and
7,604 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
name: Release clients/python-ffi | ||
|
||
on: | ||
push: | ||
branches: | ||
- sam/maturin2 | ||
|
||
permissions: | ||
contents: read | ||
id-token: write | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
_: | ||
- runs_on: ubuntu-latest | ||
target: x86_64 | ||
name: x86_64-unknown-linux-gnu | ||
|
||
- runs_on: ubuntu-latest | ||
target: aarch64 | ||
name: aarch64-unknown-linux-gnu | ||
|
||
- runs_on: macos-latest | ||
target: x86_64 | ||
name: x86_64-apple-darwin | ||
|
||
- runs_on: macos-latest | ||
target: aarch64 | ||
name: aarch64-apple-darwin | ||
|
||
- runs_on: windows-latest | ||
target: x64 | ||
name: x86_64-pc-windows-msvc | ||
|
||
runs-on: ${{ matrix._.runs_on }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
architecture: ${{ matrix._.runs_on == 'windows-latest' && 'x64' || null }} | ||
|
||
- name: Build wheels | ||
uses: PyO3/maturin-action@v1 | ||
with: | ||
target: ${{ matrix._.target }} | ||
command: build | ||
args: --release --out dist --manifest-path clients/python-ffi/Cargo.toml | ||
sccache: "true" | ||
manylinux: ${{ matrix._.runs_on == 'ubuntu-latest' && 'auto' || null }} | ||
|
||
- name: Upload wheels | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: wheels-${{ matrix._.name }} | ||
path: dist | ||
|
||
publish: | ||
runs-on: ubuntu-latest | ||
needs: [build] | ||
steps: | ||
- uses: actions/download-artifact@v4 | ||
|
||
- run: mkdir dist && mv wheels-*/* dist | ||
|
||
# authz is managed via OIDC configured at https://pypi.org/manage/project/baml-core-ffi/settings/publishing/ | ||
# it is pinned to this filename, so renaming this file is not safe!!: release_python_ffi.yaml | ||
- name: Publish package to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 |
70 changes: 70 additions & 0 deletions
70
client-tests/test1/python/baml_client/__do_not_import/functions/fx_analyzeproductreview.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# This file is generated by the BAML compiler. | ||
# Do not edit this file directly. | ||
# Instead, edit the BAML files and recompile. | ||
|
||
# ruff: noqa: E501,F401 | ||
# flake8: noqa: E501,F401 | ||
# pylint: disable=unused-import,line-too-long | ||
# fmt: off | ||
|
||
from ..types.classes.cls_reviewanalysis import ReviewAnalysis | ||
from ..types.enums.enm_reviewhelpfulness import ReviewHelpfulness | ||
from ..types.enums.enm_reviewsentiment import ReviewSentiment | ||
from ..types.partial.classes.cls_reviewanalysis import PartialReviewAnalysis | ||
from baml_core.stream import AsyncStream | ||
from baml_lib._impl.functions import BaseBAMLFunction | ||
from typing import AsyncIterator, Callable, Protocol, runtime_checkable | ||
|
||
|
||
IAnalyzeProductReviewOutput = ReviewAnalysis | ||
|
||
@runtime_checkable | ||
class IAnalyzeProductReview(Protocol): | ||
""" | ||
This is the interface for a function. | ||
Args: | ||
product_review: str | ||
Returns: | ||
ReviewAnalysis | ||
""" | ||
|
||
async def __call__(self, *, product_review: str) -> ReviewAnalysis: | ||
... | ||
|
||
|
||
|
||
@runtime_checkable | ||
class IAnalyzeProductReviewStream(Protocol): | ||
""" | ||
This is the interface for a stream function. | ||
Args: | ||
product_review: str | ||
Returns: | ||
AsyncStream[ReviewAnalysis, PartialReviewAnalysis] | ||
""" | ||
|
||
def __call__(self, *, product_review: str | ||
) -> AsyncStream[ReviewAnalysis, PartialReviewAnalysis]: | ||
... | ||
class IBAMLAnalyzeProductReview(BaseBAMLFunction[ReviewAnalysis, PartialReviewAnalysis]): | ||
def __init__(self) -> None: | ||
super().__init__( | ||
"AnalyzeProductReview", | ||
IAnalyzeProductReview, | ||
["default_config"], | ||
) | ||
|
||
async def __call__(self, *args, **kwargs) -> ReviewAnalysis: | ||
return await self.get_impl("").run(*args, **kwargs) | ||
|
||
def stream(self, *args, **kwargs) -> AsyncStream[ReviewAnalysis, PartialReviewAnalysis]: | ||
res = self.get_impl("").stream(*args, **kwargs) | ||
return res | ||
|
||
BAMLAnalyzeProductReview = IBAMLAnalyzeProductReview() | ||
|
||
__all__ = [ "BAMLAnalyzeProductReview" ] |
183 changes: 183 additions & 0 deletions
183
client-tests/test1/python/baml_client/__do_not_import/functions/fx_analyzeproductreview.pyi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
# This file is generated by the BAML compiler. | ||
# Do not edit this file directly. | ||
# Instead, edit the BAML files and recompile. | ||
|
||
# ruff: noqa: E501,F401 | ||
# flake8: noqa: E501,F401 | ||
# pylint: disable=unused-import,line-too-long | ||
# fmt: off | ||
|
||
from ..types.classes.cls_reviewanalysis import ReviewAnalysis | ||
from ..types.enums.enm_reviewhelpfulness import ReviewHelpfulness | ||
from ..types.enums.enm_reviewsentiment import ReviewSentiment | ||
from ..types.partial.classes.cls_reviewanalysis import PartialReviewAnalysis | ||
from baml_core.stream import AsyncStream | ||
from typing import Callable, Protocol, runtime_checkable | ||
|
||
|
||
import typing | ||
|
||
import pytest | ||
from contextlib import contextmanager | ||
from unittest import mock | ||
|
||
ImplName = typing.Literal["default_config"] | ||
|
||
T = typing.TypeVar("T", bound=typing.Callable[..., typing.Any]) | ||
CLS = typing.TypeVar("CLS", bound=type) | ||
|
||
|
||
IAnalyzeProductReviewOutput = ReviewAnalysis | ||
|
||
@runtime_checkable | ||
class IAnalyzeProductReview(Protocol): | ||
""" | ||
This is the interface for a function. | ||
Args: | ||
product_review: str | ||
Returns: | ||
ReviewAnalysis | ||
""" | ||
|
||
async def __call__(self, *, product_review: str) -> ReviewAnalysis: | ||
... | ||
|
||
|
||
|
||
@runtime_checkable | ||
class IAnalyzeProductReviewStream(Protocol): | ||
""" | ||
This is the interface for a stream function. | ||
Args: | ||
product_review: str | ||
Returns: | ||
AsyncStream[ReviewAnalysis, PartialReviewAnalysis] | ||
""" | ||
|
||
def __call__(self, *, product_review: str | ||
) -> AsyncStream[ReviewAnalysis, PartialReviewAnalysis]: | ||
... | ||
class BAMLAnalyzeProductReviewImpl: | ||
async def run(self, *, product_review: str) -> ReviewAnalysis: | ||
... | ||
|
||
def stream(self, *, product_review: str | ||
) -> AsyncStream[ReviewAnalysis, PartialReviewAnalysis]: | ||
... | ||
|
||
class IBAMLAnalyzeProductReview: | ||
def register_impl( | ||
self, name: ImplName | ||
) -> typing.Callable[[IAnalyzeProductReview, IAnalyzeProductReviewStream], None]: | ||
... | ||
|
||
async def __call__(self, *, product_review: str) -> ReviewAnalysis: | ||
... | ||
|
||
def stream(self, *, product_review: str | ||
) -> AsyncStream[ReviewAnalysis, PartialReviewAnalysis]: | ||
... | ||
|
||
def get_impl(self, name: ImplName) -> BAMLAnalyzeProductReviewImpl: | ||
... | ||
|
||
@contextmanager | ||
def mock(self) -> typing.Generator[mock.AsyncMock, None, None]: | ||
""" | ||
Utility for mocking the AnalyzeProductReviewInterface. | ||
Usage: | ||
```python | ||
# All implementations are mocked. | ||
async def test_logic() -> None: | ||
with baml.AnalyzeProductReview.mock() as mocked: | ||
mocked.return_value = ... | ||
result = await AnalyzeProductReviewImpl(...) | ||
assert mocked.called | ||
``` | ||
""" | ||
... | ||
|
||
@typing.overload | ||
def test(self, test_function: T) -> T: | ||
""" | ||
Provides a pytest.mark.parametrize decorator to facilitate testing different implementations of | ||
the AnalyzeProductReviewInterface. | ||
Args: | ||
test_function : T | ||
The test function to be decorated. | ||
Usage: | ||
```python | ||
# All implementations will be tested. | ||
@baml.AnalyzeProductReview.test | ||
async def test_logic(AnalyzeProductReviewImpl: IAnalyzeProductReview) -> None: | ||
result = await AnalyzeProductReviewImpl(...) | ||
``` | ||
""" | ||
... | ||
|
||
@typing.overload | ||
def test(self, *, exclude_impl: typing.Iterable[ImplName] = [], stream: bool = False) -> pytest.MarkDecorator: | ||
""" | ||
Provides a pytest.mark.parametrize decorator to facilitate testing different implementations of | ||
the AnalyzeProductReviewInterface. | ||
Args: | ||
exclude_impl : Iterable[ImplName] | ||
The names of the implementations to exclude from testing. | ||
stream: bool | ||
If set, will return a streamable version of the test function. | ||
Usage: | ||
```python | ||
# All implementations except the given impl will be tested. | ||
@baml.AnalyzeProductReview.test(exclude_impl=["implname"]) | ||
async def test_logic(AnalyzeProductReviewImpl: IAnalyzeProductReview) -> None: | ||
result = await AnalyzeProductReviewImpl(...) | ||
``` | ||
```python | ||
# Streamable version of the test function. | ||
@baml.AnalyzeProductReview.test(stream=True) | ||
async def test_logic(AnalyzeProductReviewImpl: IAnalyzeProductReviewStream) -> None: | ||
async for result in AnalyzeProductReviewImpl(...): | ||
... | ||
``` | ||
""" | ||
... | ||
|
||
@typing.overload | ||
def test(self, test_class: typing.Type[CLS]) -> typing.Type[CLS]: | ||
""" | ||
Provides a pytest.mark.parametrize decorator to facilitate testing different implementations of | ||
the AnalyzeProductReviewInterface. | ||
Args: | ||
test_class : Type[CLS] | ||
The test class to be decorated. | ||
Usage: | ||
```python | ||
# All implementations will be tested in every test method. | ||
@baml.AnalyzeProductReview.test | ||
class TestClass: | ||
def test_a(self, AnalyzeProductReviewImpl: IAnalyzeProductReview) -> None: | ||
... | ||
def test_b(self, AnalyzeProductReviewImpl: IAnalyzeProductReview) -> None: | ||
... | ||
``` | ||
""" | ||
... | ||
|
||
BAMLAnalyzeProductReview: IBAMLAnalyzeProductReview |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.