-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c57a961
commit 07cfba0
Showing
20 changed files
with
667 additions
and
19 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "finic-py" | ||
version = "0.1.29" | ||
version = "0.1.30" | ||
description = "Finic.ai is a platform for building and deploying browser automations. This is the Python client for Finic" | ||
authors = ["Ayan Bandyopadhyay <[email protected]>", "jasonwcfan <[email protected]>"] | ||
readme = "README.md" | ||
|
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,32 @@ | ||
############################################################################### | ||
# | ||
# Welcome to Baml! To use this generated code, please run the following: | ||
# | ||
# $ pip install baml | ||
# | ||
############################################################################### | ||
|
||
# This file was generated by BAML: please do not edit it. Instead, edit the | ||
# BAML files and re-generate this code. | ||
# | ||
# ruff: noqa: E501,F401 | ||
# flake8: noqa: E501,F401 | ||
# pylint: disable=unused-import,line-too-long | ||
# fmt: off | ||
from . import types | ||
from . import tracing | ||
from . import partial_types | ||
from .globals import reset_baml_env_vars | ||
|
||
|
||
from .sync_client import b | ||
|
||
|
||
|
||
__all__ = [ | ||
"b", | ||
"partial_types", | ||
"tracing", | ||
"types", | ||
"reset_baml_env_vars", | ||
] |
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,135 @@ | ||
############################################################################### | ||
# | ||
# Welcome to Baml! To use this generated code, please run the following: | ||
# | ||
# $ pip install baml | ||
# | ||
############################################################################### | ||
|
||
# This file was generated by BAML: please do not edit it. Instead, edit the | ||
# BAML files and re-generate this code. | ||
# | ||
# ruff: noqa: E501,F401 | ||
# flake8: noqa: E501,F401 | ||
# pylint: disable=unused-import,line-too-long | ||
# fmt: off | ||
from typing import Any, Dict, List, Optional, TypeVar, Union, TypedDict, Type | ||
from typing_extensions import NotRequired | ||
import pprint | ||
|
||
import baml_py | ||
from pydantic import BaseModel, ValidationError, create_model | ||
|
||
from . import partial_types, types | ||
from .type_builder import TypeBuilder | ||
from .globals import DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX, DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME | ||
|
||
|
||
OutputType = TypeVar('OutputType') | ||
|
||
def coerce(cls: Type[BaseModel], parsed: Any) -> Any: | ||
try: | ||
return cls.model_validate({"inner": parsed}).inner # type: ignore | ||
except ValidationError as e: | ||
raise TypeError( | ||
"Internal BAML error while casting output to {}\n{}".format( | ||
cls.__name__, | ||
pprint.pformat(parsed) | ||
) | ||
) from e | ||
|
||
# Define the TypedDict with optional parameters having default values | ||
class BamlCallOptions(TypedDict, total=False): | ||
tb: NotRequired[TypeBuilder] | ||
client_registry: NotRequired[baml_py.baml_py.ClientRegistry] | ||
|
||
class BamlAsyncClient: | ||
__runtime: baml_py.BamlRuntime | ||
__ctx_manager: baml_py.BamlCtxManager | ||
__stream_client: "BamlStreamClient" | ||
|
||
def __init__(self, runtime: baml_py.BamlRuntime, ctx_manager: baml_py.BamlCtxManager): | ||
self.__runtime = runtime | ||
self.__ctx_manager = ctx_manager | ||
self.__stream_client = BamlStreamClient(self.__runtime, self.__ctx_manager) | ||
|
||
@property | ||
def stream(self): | ||
return self.__stream_client | ||
|
||
|
||
|
||
async def GeneratePlaywrightCode( | ||
self, | ||
intent: str,element: types.Element,existing_code: str, | ||
baml_options: BamlCallOptions = {}, | ||
) -> types.ResponseFormat: | ||
__tb__ = baml_options.get("tb", None) | ||
if __tb__ is not None: | ||
tb = __tb__._tb | ||
else: | ||
tb = None | ||
__cr__ = baml_options.get("client_registry", None) | ||
|
||
raw = await self.__runtime.call_function( | ||
"GeneratePlaywrightCode", | ||
{ | ||
"intent": intent,"element": element,"existing_code": existing_code, | ||
}, | ||
self.__ctx_manager.get(), | ||
tb, | ||
__cr__, | ||
) | ||
mdl = create_model("GeneratePlaywrightCodeReturnType", inner=(types.ResponseFormat, ...)) | ||
return coerce(mdl, raw.parsed()) | ||
|
||
|
||
|
||
class BamlStreamClient: | ||
__runtime: baml_py.BamlRuntime | ||
__ctx_manager: baml_py.BamlCtxManager | ||
|
||
def __init__(self, runtime: baml_py.BamlRuntime, ctx_manager: baml_py.BamlCtxManager): | ||
self.__runtime = runtime | ||
self.__ctx_manager = ctx_manager | ||
|
||
|
||
def GeneratePlaywrightCode( | ||
self, | ||
intent: str,element: types.Element,existing_code: str, | ||
baml_options: BamlCallOptions = {}, | ||
) -> baml_py.BamlStream[partial_types.ResponseFormat, types.ResponseFormat]: | ||
__tb__ = baml_options.get("tb", None) | ||
if __tb__ is not None: | ||
tb = __tb__._tb | ||
else: | ||
tb = None | ||
__cr__ = baml_options.get("client_registry", None) | ||
|
||
raw = self.__runtime.stream_function( | ||
"GeneratePlaywrightCode", | ||
{ | ||
"intent": intent, | ||
"element": element, | ||
"existing_code": existing_code, | ||
}, | ||
None, | ||
self.__ctx_manager.get(), | ||
tb, | ||
__cr__, | ||
) | ||
|
||
mdl = create_model("GeneratePlaywrightCodeReturnType", inner=(types.ResponseFormat, ...)) | ||
partial_mdl = create_model("GeneratePlaywrightCodePartialReturnType", inner=(partial_types.ResponseFormat, ...)) | ||
|
||
return baml_py.BamlStream[partial_types.ResponseFormat, types.ResponseFormat]( | ||
raw, | ||
lambda x: coerce(partial_mdl, x), | ||
lambda x: coerce(mdl, x), | ||
self.__ctx_manager.get(), | ||
) | ||
|
||
|
||
b = BamlAsyncClient(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME, DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX) | ||
|
||
__all__ = ["b"] |
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,41 @@ | ||
############################################################################### | ||
# | ||
# Welcome to Baml! To use this generated code, please run the following: | ||
# | ||
# $ pip install baml | ||
# | ||
############################################################################### | ||
|
||
# This file was generated by BAML: please do not edit it. Instead, edit the | ||
# BAML files and re-generate this code. | ||
# | ||
# ruff: noqa: E501,F401 | ||
# flake8: noqa: E501,F401 | ||
# pylint: disable=unused-import,line-too-long | ||
# fmt: off | ||
import os | ||
|
||
from baml_py import BamlCtxManager, BamlRuntime | ||
from baml_py.baml_py import BamlError | ||
from .inlinedbaml import get_baml_files | ||
from typing import Dict | ||
|
||
DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME = BamlRuntime.from_files( | ||
"baml_src", | ||
get_baml_files(), | ||
os.environ.copy() | ||
) | ||
DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX = BamlCtxManager(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME) | ||
|
||
def reset_baml_env_vars(env_vars: Dict[str, str]): | ||
if DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.allow_reset(): | ||
DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME.reset( | ||
"baml_src", | ||
get_baml_files(), | ||
env_vars | ||
) | ||
DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.reset() | ||
else: | ||
raise BamlError("Cannot reset BAML environment variables while there are active BAML contexts.") | ||
|
||
__all__ = [] |
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,25 @@ | ||
############################################################################### | ||
# | ||
# Welcome to Baml! To use this generated code, please run the following: | ||
# | ||
# $ pip install baml | ||
# | ||
############################################################################### | ||
|
||
# This file was generated by BAML: please do not edit it. Instead, edit the | ||
# BAML files and re-generate this code. | ||
# | ||
# ruff: noqa: E501,F401 | ||
# flake8: noqa: E501,F401 | ||
# pylint: disable=unused-import,line-too-long | ||
# fmt: off | ||
|
||
file_map = { | ||
|
||
"clients.baml": "// Learn more about clients at https://docs.boundaryml.com/docs/snippets/clients/overview", | ||
"copilot.baml": "class Attribute {\n name string\n value string\n}\n\nclass Element {\n tagName string\n attributes Attribute[]\n textContent string\n outerHTML string\n}\n\nenum InputDataType {\n TEXT\n NUMBER\n}\n\nclass ResponseFormat {\n elementIdentifier string @description(\"A descriptive identifier for this element, for example: 'login-button'\")\n code string\n}\n\nfunction GeneratePlaywrightCode(intent: string, element: Element, existing_code: string) -> ResponseFormat {\n client \"anthropic/claude-3-5-sonnet-20240620\"\n prompt #\"\n Given a the user's intent and info about an element on a web page, generate python code that uses Playwright to interact with the page according to the user's intent. \n Use `finic.selectors.get(<element_identifier>)` to get the selector for the element, using the elementIdentifier from the response format.\n \n The existing code is provided. You should generate code that starts on the line exactly after the last line of the existing code.\n\n User's intent: {{ intent }}\n\n Element info:\n {{ element }}\n\n Existing code:\n ```python\n {{ existing_code }}\n ```\n\n Make sure to provide the code response as a markdown code block and start your response as follows:\n ```python\n\n {{ ctx.output_format }}\n \"#\n}", | ||
"generators.baml": "// This helps use auto generate libraries you can use in the language of\n// your choice. You can have multiple generators if you use multiple languages.\n// Just ensure that the output_dir is different for each generator.\ngenerator target {\n // Valid values: \"python/pydantic\", \"typescript\", \"ruby/sorbet\", \"rest/openapi\"\n output_type \"python/pydantic\"\n\n // Where the generated code will be saved (relative to baml_src/)\n output_dir \"../\"\n\n // The version of the BAML package you have installed (e.g. same version as your baml-py or @boundaryml/baml).\n // The BAML VSCode extension version should also match this version.\n version \"0.60.0\"\n\n // Valid values: \"sync\", \"async\"\n // This controls what `b.FunctionName()` will be (sync or async).\n default_client_mode sync\n}\n", | ||
} | ||
|
||
def get_baml_files(): | ||
return file_map |
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,49 @@ | ||
############################################################################### | ||
# | ||
# Welcome to Baml! To use this generated code, please run the following: | ||
# | ||
# $ pip install baml | ||
# | ||
############################################################################### | ||
|
||
# This file was generated by BAML: please do not edit it. Instead, edit the | ||
# BAML files and re-generate this code. | ||
# | ||
# ruff: noqa: E501,F401 | ||
# flake8: noqa: E501,F401 | ||
# pylint: disable=unused-import,line-too-long | ||
# fmt: off | ||
import baml_py | ||
from enum import Enum | ||
from pydantic import BaseModel, ConfigDict | ||
from typing import Dict, List, Optional, Union | ||
|
||
from . import types | ||
|
||
############################################################################### | ||
# | ||
# These types are used for streaming, for when an instance of a type | ||
# is still being built up and any of its fields is not yet fully available. | ||
# | ||
############################################################################### | ||
|
||
|
||
class Attribute(BaseModel): | ||
|
||
|
||
name: Optional[str] = None | ||
value: Optional[str] = None | ||
|
||
class Element(BaseModel): | ||
|
||
|
||
tagName: Optional[str] = None | ||
attributes: List["Attribute"] | ||
textContent: Optional[str] = None | ||
outerHTML: Optional[str] = None | ||
|
||
class ResponseFormat(BaseModel): | ||
|
||
|
||
elementIdentifier: Optional[str] = None | ||
code: Optional[str] = None |
Oops, something went wrong.