flyteplugins-openai 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,3 @@
1
+ from ._function_tools import function_tool
2
+
3
+ __all__ = ["function_tool"]
@@ -0,0 +1,85 @@
1
+ import inspect
2
+ import json
3
+ import typing
4
+ from dataclasses import asdict, dataclass
5
+ from functools import partial
6
+
7
+ import agents
8
+ from agents import FunctionTool as OpenAIFunctionTool
9
+ from agents import function_tool as openai_function_tool
10
+ from agents.function_schema import function_schema
11
+ from agents.tool_context import ToolContext
12
+ from flyte._task import AsyncFunctionTaskTemplate, TaskTemplate
13
+ from flyte.models import NativeInterface
14
+ from packaging import version
15
+
16
+ MIN_PACKAGE_VERSION = "0.2.4"
17
+ assert version.parse(agents.__version__) >= version.parse(MIN_PACKAGE_VERSION), (
18
+ f"The agents package needs to be at least version {MIN_PACKAGE_VERSION}, found version {agents.__version__}"
19
+ )
20
+
21
+
22
+ @dataclass
23
+ class FunctionTool(OpenAIFunctionTool):
24
+ """
25
+ Flyte-compatible replacement for agents.FunctionTool
26
+
27
+ This is a dataclass that includes additional fields that are not present in
28
+ the OpenAI FunctionTool dataclass so that the tool can be used as a flyte
29
+ task.
30
+ """
31
+
32
+ task: TaskTemplate | None = None
33
+ native_interface: NativeInterface | None = None
34
+ report: bool = False
35
+
36
+ async def execute(self, *args, **kwargs):
37
+ return await self.task.execute(*args, **kwargs)
38
+
39
+
40
+ def function_tool(
41
+ func: AsyncFunctionTaskTemplate | typing.Callable | None = None,
42
+ **kwargs,
43
+ ) -> FunctionTool | OpenAIFunctionTool:
44
+ """Flyte-compatible replacement for @agents.function_tool
45
+
46
+ **kwargs are forwarded to the underlying @agents.function_tool decorator.
47
+ For @flyte.trace functions, this just forwards all the arguments to the
48
+ agents.function_tool decorator:
49
+ https://openai.github.io/openai-agents-python/ref/tool/#agents.tool.function_tool
50
+
51
+ For @TaskEnvironment.task functions, this will create a flyte-compatible
52
+ FunctionTool dataclass that can run tools as flyte tasks.
53
+ """
54
+ if func is None:
55
+ return partial(function_tool, **kwargs)
56
+
57
+ if isinstance(func, AsyncFunctionTaskTemplate):
58
+
59
+ async def _on_invoke_tool(ctx: ToolContext[typing.Any], input: str) -> typing.Any:
60
+ json_data: dict[str, typing.Any] = json.loads(input) if input else {}
61
+ schema = function_schema(func.func)
62
+ parsed = schema.params_pydantic_model(**json_data) if json_data else schema.params_pydantic_model()
63
+ args, kwargs_dict = schema.to_call_args(parsed)
64
+ if inspect.iscoroutinefunction(func.func):
65
+ out = await func(*args, **kwargs_dict)
66
+ else:
67
+ out = func(*args, **kwargs_dict)
68
+ return out
69
+
70
+ _openai_fn_tool = asdict(openai_function_tool(func.func, **kwargs))
71
+ _openai_fn_tool.pop("on_invoke_tool")
72
+ _openai_fn_tool.pop("_is_agent_tool")
73
+ _openai_fn_tool.pop("_is_codex_tool")
74
+ _openai_fn_tool.pop("_agent_instance")
75
+ return FunctionTool(
76
+ native_interface=func.native_interface,
77
+ task=func,
78
+ report=func.report,
79
+ on_invoke_tool=_on_invoke_tool,
80
+ **_openai_fn_tool,
81
+ )
82
+
83
+ # regular callables or flyte.trace-decorated functions should use the
84
+ # openai-agents function_tool decorator
85
+ return openai_function_tool(func, **kwargs)
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.4
2
+ Name: flyteplugins-openai
3
+ Version: 2.0.0
4
+ Summary: OpenAI plugin for flyte
5
+ Author-email: Niels Bantilan <cosmicbboy@users.noreply.github.com>
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: openai-agents>=0.2.4
9
+ Requires-Dist: flyte
10
+
11
+ # Flyte OpenAI Plugin
12
+
13
+ This plugin provides a drop-in replacement for OpenAI packages. It provides
14
+ drop-in replacements for functionality in the `openai-agents` package so that
15
+ it works on Flyte.
16
+
17
+ To install the plugin, run the following command:
18
+
19
+ ```bash
20
+ pip install --pre flyteplugins-openai
21
+ ```
@@ -0,0 +1,7 @@
1
+ flyteplugins/openai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ flyteplugins/openai/agents/__init__.py,sha256=fXfkrE1cbLBPjcytMOHyBexMj4_YMyZumhBC4QTzdcc,72
3
+ flyteplugins/openai/agents/_function_tools.py,sha256=9MNZYta168MwiiPKLhW9JzZLNr2wM8d-rFE8E1Qm_yU,3207
4
+ flyteplugins_openai-2.0.0.dist-info/METADATA,sha256=1J6IdXMkDNra01WfkB0kCJKpLsvqSCbs1GfyIYZiaQE,583
5
+ flyteplugins_openai-2.0.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
6
+ flyteplugins_openai-2.0.0.dist-info/top_level.txt,sha256=cgd779rPu9EsvdtuYgUxNHHgElaQvPn74KhB5XSeMBE,13
7
+ flyteplugins_openai-2.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ flyteplugins