Skip to content

Commit

Permalink
Complete code sample
Browse files Browse the repository at this point in the history
  • Loading branch information
hellovai committed Nov 24, 2023
1 parent 9bf02a4 commit 31b608a
Show file tree
Hide file tree
Showing 46 changed files with 1,212 additions and 292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
name="GPT35",
provider="baml-openai-chat",
retry_policy=None,
redactions=["api_key"],
options=dict(
model="gpt-3.5-turbo",
api_key=environ['OPENAI_API_KEY'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
# fmt: off

from baml_core.provider_manager import LLMManager
from os import environ


GPT35_YES_NO = LLMManager.add_llm(
name="GPT35_YES_NO",
provider="baml-openai-chat",
retry_policy=None,
redactions=["api_key"],
options=dict(
model="gpt-3.5-turbo",
api_key=environ['OPENAI_API_KEY'],
logit_bias={" yes": 100, " no": 100},
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
# fmt: off

from baml_core.provider_manager import LLMManager
from os import environ


GPT4 = LLMManager.add_llm(
name="GPT4",
provider="baml-openai-chat",
retry_policy=None,
redactions=["api_key"],
options=dict(
model="gpt-4-1106-preview",
api_key=environ['OPENAI_API_KEY'],
temperature=0.1,
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
# fmt: off

from baml_core.provider_manager import LLMManager
from os import environ


GPTInstruct = LLMManager.add_llm(
name="GPTInstruct",
provider="baml-openai-completion",
retry_policy=None,
redactions=["api_key"],
options=dict(
model="gpt-3.5-instruct",
api_key=environ['OPENAI_API_KEY'],
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
name="Main",
provider="baml-fallback",
retry_policy=None,
redactions=[],
options=dict(
strategy=["GPT4", "GPT35"],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class IClassifyIntent(Protocol):
This is the interface for a function.
Args:
arg: str
query: str
Returns:
List[Intent]
"""

async def __call__(self, arg: str, /) -> List[Intent]:
async def __call__(self, *, query: str) -> List[Intent]:
...


Expand All @@ -35,9 +35,12 @@ def __init__(self) -> None:
super().__init__(
"ClassifyIntent",
IClassifyIntent,
["v1", "v2"],
["simple", "with_adapter"],
)

async def __call__(self, *args, **kwargs) -> List[Intent]:
return await self.get_impl("simple").run(*args, **kwargs)

BAMLClassifyIntent = IBAMLClassifyIntent()

__all__ = [ "BAMLClassifyIntent" ]
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import typing

import pytest

ImplName = typing.Literal["v1", "v2"]
ImplName = typing.Literal["simple", "with_adapter"]

T = typing.TypeVar("T", bound=typing.Callable[..., typing.Any])
CLS = typing.TypeVar("CLS", bound=type)
Expand All @@ -29,18 +29,18 @@ class IClassifyIntent(Protocol):
This is the interface for a function.
Args:
arg: str
query: str
Returns:
List[Intent]
"""

async def __call__(self, arg: str, /) -> List[Intent]:
async def __call__(self, *, query: str) -> List[Intent]:
...


class BAMLClassifyIntentImpl:
async def run(self, arg: str, /) -> List[Intent]:
async def run(self, *, query: str) -> List[Intent]:
...

class IBAMLClassifyIntent:
Expand All @@ -49,6 +49,9 @@ class IBAMLClassifyIntent:
) -> typing.Callable[[IClassifyIntent], IClassifyIntent]:
...

async def __call__(self, *, query: str) -> List[Intent]:
...

def get_impl(self, name: ImplName) -> BAMLClassifyIntentImpl:
...

Expand Down Expand Up @@ -85,9 +88,9 @@ class IBAMLClassifyIntent:
Usage:
```python
# All implementations except "v1" will be tested.
# All implementations except "simple" will be tested.
@baml.ClassifyIntent.test(exclude_impl=["v1"])
@baml.ClassifyIntent.test(exclude_impl=["simple"])
def test_logic(ClassifyIntentImpl: IClassifyIntent) -> None:
result = await ClassifyIntentImpl(...)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
# fmt: off

from ..types.classes.cls_attendee import Attendee
from ..types.classes.cls_conversation import Conversation
from ..types.classes.cls_meetingrequest import MeetingRequest
from ..types.classes.cls_message import Message
from ..types.enums.enm_usertype import UserType
from baml_lib._impl.functions import BaseBAMLFunction
from typing import Protocol, runtime_checkable

Expand All @@ -21,14 +24,14 @@ class IExtractMeetingRequestInfo(Protocol):
This is the interface for a function.
Args:
query: str
convo: Conversation
now: str
Returns:
MeetingRequest
"""

async def __call__(self, *, query: str, now: str) -> MeetingRequest:
async def __call__(self, *, convo: Conversation, now: str) -> MeetingRequest:
...


Expand All @@ -37,9 +40,12 @@ def __init__(self) -> None:
super().__init__(
"ExtractMeetingRequestInfo",
IExtractMeetingRequestInfo,
["v1", "robust"],
["simple", "robust"],
)

async def __call__(self, *args, **kwargs) -> MeetingRequest:
return await self.get_impl("simple").run(*args, **kwargs)

BAMLExtractMeetingRequestInfo = IBAMLExtractMeetingRequestInfo()

__all__ = [ "BAMLExtractMeetingRequestInfo" ]
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
# fmt: off

from ..types.classes.cls_attendee import Attendee
from ..types.classes.cls_conversation import Conversation
from ..types.classes.cls_meetingrequest import MeetingRequest
from ..types.classes.cls_message import Message
from ..types.enums.enm_usertype import UserType
from typing import Protocol, runtime_checkable


import typing

import pytest

ImplName = typing.Literal["v1", "robust"]
ImplName = typing.Literal["simple", "robust"]

T = typing.TypeVar("T", bound=typing.Callable[..., typing.Any])
CLS = typing.TypeVar("CLS", bound=type)
Expand All @@ -30,19 +33,19 @@ class IExtractMeetingRequestInfo(Protocol):
This is the interface for a function.
Args:
query: str
convo: Conversation
now: str
Returns:
MeetingRequest
"""

async def __call__(self, *, query: str, now: str) -> MeetingRequest:
async def __call__(self, *, convo: Conversation, now: str) -> MeetingRequest:
...


class BAMLExtractMeetingRequestInfoImpl:
async def run(self, *, query: str, now: str) -> MeetingRequest:
async def run(self, *, convo: Conversation, now: str) -> MeetingRequest:
...

class IBAMLExtractMeetingRequestInfo:
Expand All @@ -51,6 +54,9 @@ class IBAMLExtractMeetingRequestInfo:
) -> typing.Callable[[IExtractMeetingRequestInfo], IExtractMeetingRequestInfo]:
...

async def __call__(self, *, convo: Conversation, now: str) -> MeetingRequest:
...

def get_impl(self, name: ImplName) -> BAMLExtractMeetingRequestInfoImpl:
...

Expand Down Expand Up @@ -87,9 +93,9 @@ class IBAMLExtractMeetingRequestInfo:
Usage:
```python
# All implementations except "v1" will be tested.
# All implementations except "simple" will be tested.
@baml.ExtractMeetingRequestInfo.test(exclude_impl=["v1"])
@baml.ExtractMeetingRequestInfo.test(exclude_impl=["simple"])
def test_logic(ExtractMeetingRequestInfoImpl: IExtractMeetingRequestInfo) -> None:
result = await ExtractMeetingRequestInfoImpl(...)
```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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_conversation import Conversation
from ..types.classes.cls_meetingrequestpartial import MeetingRequestPartial
from ..types.classes.cls_message import Message
from ..types.enums.enm_usertype import UserType
from baml_lib._impl.functions import BaseBAMLFunction
from typing import Protocol, runtime_checkable


IExtractMeetingRequestInfoPartialOutput = MeetingRequestPartial

@runtime_checkable
class IExtractMeetingRequestInfoPartial(Protocol):
"""
This is the interface for a function.
Args:
convo: Conversation
now: str
Returns:
MeetingRequestPartial
"""

async def __call__(self, *, convo: Conversation, now: str) -> MeetingRequestPartial:
...


class IBAMLExtractMeetingRequestInfoPartial(BaseBAMLFunction[MeetingRequestPartial]):
def __init__(self) -> None:
super().__init__(
"ExtractMeetingRequestInfoPartial",
IExtractMeetingRequestInfoPartial,
["v1"],
)

async def __call__(self, *args, **kwargs) -> MeetingRequestPartial:
return await self.get_impl("v1").run(*args, **kwargs)

BAMLExtractMeetingRequestInfoPartial = IBAMLExtractMeetingRequestInfoPartial()

__all__ = [ "BAMLExtractMeetingRequestInfoPartial" ]
Loading

0 comments on commit 31b608a

Please sign in to comment.