beamlit 0.0.40rc84__py3-none-any.whl → 0.0.41__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.
beamlit/agents/chat.py CHANGED
@@ -1,11 +1,12 @@
1
1
  from logging import getLogger
2
2
  from typing import Tuple, Union
3
3
 
4
+ from langchain_core.language_models import BaseChatModel
5
+
4
6
  from beamlit.api.models import get_model
5
7
  from beamlit.authentication import get_authentication_headers, new_client
6
8
  from beamlit.common.settings import get_settings
7
9
  from beamlit.models import Model
8
- from langchain_core.language_models import BaseChatModel
9
10
 
10
11
  logger = getLogger(__name__)
11
12
 
@@ -4,8 +4,12 @@ from typing import Tuple, Type, Union
4
4
  from langchain_core.language_models.chat_models import BaseChatModel
5
5
  from langgraph.graph.graph import CompiledGraph
6
6
  from pydantic import Field
7
- from pydantic_settings import (BaseSettings, PydanticBaseSettingsSource,
8
- SettingsConfigDict, YamlConfigSettingsSource)
7
+ from pydantic_settings import (
8
+ BaseSettings,
9
+ PydanticBaseSettingsSource,
10
+ SettingsConfigDict,
11
+ YamlConfigSettingsSource,
12
+ )
9
13
 
10
14
  from beamlit.common.logger import init as init_logger
11
15
  from beamlit.models import Agent, Function, Model
@@ -1,5 +1,6 @@
1
1
  """Functions package providing function decorators and utilities."""
2
2
 
3
- from .decorator import function, get_functions, kit
3
+ from .common import get_functions
4
+ from .decorator import function, kit
4
5
 
5
6
  __all__ = ["function", "kit", "get_functions"]
@@ -0,0 +1,143 @@
1
+ """Decorators for creating function tools with Beamlit and LangChain integration."""
2
+ import ast
3
+ import asyncio
4
+ import importlib.util
5
+ import os
6
+ from logging import getLogger
7
+ from typing import Union
8
+
9
+ from langchain_core.tools import StructuredTool
10
+ from langchain_core.tools.base import create_schema_from_function
11
+
12
+ from beamlit.authentication import new_client
13
+ from beamlit.client import AuthenticatedClient
14
+ from beamlit.common import slugify
15
+ from beamlit.common.settings import get_settings
16
+ from beamlit.functions.remote.remote import RemoteToolkit
17
+ from beamlit.models import AgentChain
18
+
19
+ logger = getLogger(__name__)
20
+
21
+ def get_functions(
22
+ remote_functions:Union[list[str], None]=None,
23
+ client:Union[AuthenticatedClient, None]=None,
24
+ dir:Union[str, None]=None,
25
+ chain:Union[list[AgentChain], None]=None,
26
+ remote_functions_empty:bool=True,
27
+ from_decorator:str="function",
28
+ warning:bool=True,
29
+ ):
30
+ from beamlit.agents.chain import ChainToolkit
31
+
32
+ settings = get_settings()
33
+ if client is None:
34
+ client = new_client()
35
+ if dir is None:
36
+ dir = settings.agent.functions_directory
37
+
38
+ functions = []
39
+ logger = getLogger(__name__)
40
+ settings = get_settings()
41
+
42
+ # Walk through all Python files in functions directory and subdirectories
43
+ if not os.path.exists(dir):
44
+ if remote_functions_empty and warning:
45
+ logger.warn(f"Functions directory {dir} not found")
46
+ if os.path.exists(dir):
47
+ for root, _, files in os.walk(dir):
48
+ for file in files:
49
+ if file.endswith(".py"):
50
+ file_path = os.path.join(root, file)
51
+ # Read and compile the file content
52
+ with open(file_path) as f:
53
+ try:
54
+ file_content = f.read()
55
+ # Parse the file content to find decorated functions
56
+ tree = ast.parse(file_content)
57
+
58
+ # Look for function definitions with decorators
59
+ for node in ast.walk(tree):
60
+ if (
61
+ not isinstance(node, ast.FunctionDef)
62
+ and not isinstance(node, ast.AsyncFunctionDef)
63
+ ) or len(node.decorator_list) == 0:
64
+ continue
65
+ decorator = node.decorator_list[0]
66
+
67
+ decorator_name = ""
68
+ if isinstance(decorator, ast.Call):
69
+ decorator_name = decorator.func.id
70
+ if isinstance(decorator, ast.Name):
71
+ decorator_name = decorator.id
72
+ if decorator_name == from_decorator:
73
+ # Get the function name and decorator name
74
+ func_name = node.name
75
+
76
+ # Import the module to get the actual function
77
+ spec = importlib.util.spec_from_file_location(func_name, file_path)
78
+ module = importlib.util.module_from_spec(spec)
79
+ spec.loader.exec_module(module)
80
+ # Check if kit=True in the decorator arguments
81
+ is_kit = False
82
+ if isinstance(decorator, ast.Call):
83
+ for keyword in decorator.keywords:
84
+ if keyword.arg == "kit" and isinstance(
85
+ keyword.value, ast.Constant
86
+ ):
87
+ is_kit = keyword.value.value
88
+ if is_kit and not settings.remote:
89
+ kit_functions = get_functions(
90
+ client=client,
91
+ dir=os.path.join(root),
92
+ remote_functions_empty=remote_functions_empty,
93
+ from_decorator="kit",
94
+ )
95
+ functions.extend(kit_functions)
96
+
97
+ # Get the decorated function
98
+ if not is_kit and hasattr(module, func_name):
99
+ func = getattr(module, func_name)
100
+ if settings.remote:
101
+ toolkit = RemoteToolkit(client, slugify(func.__name__))
102
+ toolkit.initialize()
103
+ functions.extend(toolkit.get_tools())
104
+ else:
105
+ if asyncio.iscoroutinefunction(func):
106
+ functions.append(
107
+ StructuredTool(
108
+ name=func.__name__,
109
+ description=func.__doc__,
110
+ func=func,
111
+ coroutine=func,
112
+ args_schema=create_schema_from_function(func.__name__, func)
113
+ )
114
+ )
115
+ else:
116
+
117
+ functions.append(
118
+ StructuredTool(
119
+ name=func.__name__,
120
+ description=func.__doc__,
121
+ func=func,
122
+ args_schema=create_schema_from_function(func.__name__, func)
123
+ )
124
+ )
125
+ except Exception as e:
126
+ logger.warning(f"Error processing {file_path}: {e!s}")
127
+
128
+ if remote_functions:
129
+ for function in remote_functions:
130
+ try:
131
+ toolkit = RemoteToolkit(client, function)
132
+ toolkit.initialize()
133
+ functions.extend(toolkit.get_tools())
134
+ except Exception as e:
135
+ logger.warn(f"Failed to initialize remote function {function}: {e!s}")
136
+
137
+ if chain:
138
+ toolkit = ChainToolkit(client, chain)
139
+ toolkit.initialize()
140
+ functions.extend(toolkit.get_tools())
141
+
142
+ return functions
143
+
@@ -1,151 +1,15 @@
1
1
  """Decorators for creating function tools with Beamlit and LangChain integration."""
2
- import ast
3
2
  import asyncio
4
3
  import functools
5
- import importlib.util
6
- import os
7
4
  from collections.abc import Callable
8
5
  from logging import getLogger
9
- from typing import Union
10
6
 
11
7
  from fastapi import Request
12
- from langchain_core.tools import StructuredTool
13
- from langchain_core.tools.base import create_schema_from_function
14
8
 
15
- from beamlit.authentication import new_client
16
- from beamlit.client import AuthenticatedClient
17
- from beamlit.common import slugify
18
- from beamlit.common.settings import get_settings
19
- from beamlit.functions.remote.remote import RemoteToolkit
20
- from beamlit.models import AgentChain, Function, FunctionKit
9
+ from beamlit.models import Function, FunctionKit
21
10
 
22
11
  logger = getLogger(__name__)
23
12
 
24
- def get_functions(
25
- remote_functions:Union[list[str], None]=None,
26
- client:Union[AuthenticatedClient, None]=None,
27
- dir:Union[str, None]=None,
28
- chain:Union[list[AgentChain], None]=None,
29
- remote_functions_empty:bool=True,
30
- from_decorator:str="function",
31
- warning:bool=True,
32
- ):
33
- from beamlit.agents.chain import ChainToolkit
34
-
35
- settings = get_settings()
36
- if client is None:
37
- client = new_client()
38
- if dir is None:
39
- dir = settings.agent.functions_directory
40
-
41
- functions = []
42
- logger = getLogger(__name__)
43
- settings = get_settings()
44
-
45
- # Walk through all Python files in functions directory and subdirectories
46
- if not os.path.exists(dir):
47
- if remote_functions_empty and warning:
48
- logger.warn(f"Functions directory {dir} not found")
49
- if os.path.exists(dir):
50
- for root, _, files in os.walk(dir):
51
- for file in files:
52
- if file.endswith(".py"):
53
- file_path = os.path.join(root, file)
54
- # Read and compile the file content
55
- with open(file_path) as f:
56
- try:
57
- file_content = f.read()
58
- # Parse the file content to find decorated functions
59
- tree = ast.parse(file_content)
60
-
61
- # Look for function definitions with decorators
62
- for node in ast.walk(tree):
63
- if (
64
- not isinstance(node, ast.FunctionDef)
65
- and not isinstance(node, ast.AsyncFunctionDef)
66
- ) or len(node.decorator_list) == 0:
67
- continue
68
- decorator = node.decorator_list[0]
69
-
70
- decorator_name = ""
71
- if isinstance(decorator, ast.Call):
72
- decorator_name = decorator.func.id
73
- if isinstance(decorator, ast.Name):
74
- decorator_name = decorator.id
75
- if decorator_name == from_decorator:
76
- # Get the function name and decorator name
77
- func_name = node.name
78
-
79
- # Import the module to get the actual function
80
- spec = importlib.util.spec_from_file_location(func_name, file_path)
81
- module = importlib.util.module_from_spec(spec)
82
- spec.loader.exec_module(module)
83
- # Check if kit=True in the decorator arguments
84
- is_kit = False
85
- if isinstance(decorator, ast.Call):
86
- for keyword in decorator.keywords:
87
- if keyword.arg == "kit" and isinstance(
88
- keyword.value, ast.Constant
89
- ):
90
- is_kit = keyword.value.value
91
- if is_kit and not settings.remote:
92
- kit_functions = get_functions(
93
- client=client,
94
- dir=os.path.join(root),
95
- remote_functions_empty=remote_functions_empty,
96
- from_decorator="kit",
97
- )
98
- functions.extend(kit_functions)
99
-
100
- # Get the decorated function
101
- if not is_kit and hasattr(module, func_name):
102
- func = getattr(module, func_name)
103
- if settings.remote:
104
- toolkit = RemoteToolkit(client, slugify(func.__name__))
105
- toolkit.initialize()
106
- functions.extend(toolkit.get_tools())
107
- else:
108
- if asyncio.iscoroutinefunction(func):
109
- functions.append(
110
- StructuredTool(
111
- name=func.__name__,
112
- description=func.__doc__,
113
- func=func,
114
- coroutine=func,
115
- args_schema=create_schema_from_function(func.__name__, func)
116
- )
117
- )
118
- else:
119
-
120
- functions.append(
121
- StructuredTool(
122
- name=func.__name__,
123
- description=func.__doc__,
124
- func=func,
125
- args_schema=create_schema_from_function(func.__name__, func)
126
- )
127
- )
128
- except Exception as e:
129
- logger.warning(f"Error processing {file_path}: {e!s}")
130
-
131
- if remote_functions:
132
- for function in remote_functions:
133
- try:
134
- toolkit = RemoteToolkit(client, function)
135
- toolkit.initialize()
136
- functions.extend(toolkit.get_tools())
137
- except Exception as e:
138
- logger.warn(f"Failed to initialize remote function {function}: {e!s}")
139
-
140
- if chain:
141
- toolkit = ChainToolkit(client, chain)
142
- toolkit.initialize()
143
- functions.extend(toolkit.get_tools())
144
-
145
- return functions
146
-
147
-
148
-
149
13
  def kit(bl_kit: FunctionKit = None, **kwargs: dict) -> Callable:
150
14
  """Create function tools with Beamlit and LangChain integration."""
151
15
 
@@ -1,5 +1,4 @@
1
1
  import asyncio
2
- import urllib.parse
3
2
  import warnings
4
3
  from typing import Any, Callable
5
4
 
@@ -7,9 +7,10 @@ import pydantic
7
7
  import typing_extensions as t
8
8
  from langchain_core.tools.base import BaseTool, ToolException
9
9
 
10
- from beamlit.api.functions import get_function
10
+ from beamlit.api.functions import get_function, list_functions
11
11
  from beamlit.authentication.authentication import AuthenticatedClient
12
12
  from beamlit.common.settings import get_settings
13
+ from beamlit.errors import UnexpectedStatus
13
14
  from beamlit.functions.mcp.mcp import MCPClient, MCPToolkit
14
15
  from beamlit.models import Function, StoreFunctionParameter
15
16
  from beamlit.run import RunClient
@@ -88,7 +89,22 @@ class RemoteToolkit:
88
89
  def initialize(self) -> None:
89
90
  """Initialize the session and retrieve tools list"""
90
91
  if self._function is None:
91
- self._function = get_function.sync_detailed(self.function, client=self.client).parsed
92
+ try:
93
+ response = get_function.sync_detailed(self.function, client=self.client)
94
+ self._function = response.parsed
95
+ except UnexpectedStatus as e:
96
+ settings = get_settings()
97
+ functions = list_functions.sync_detailed(
98
+ client=self.client,
99
+ environment=settings.environment,
100
+ ).parsed
101
+ names = [
102
+ f.metadata.name
103
+ for f in functions
104
+ ]
105
+ raise RuntimeError(
106
+ f"error: {e.status_code}. Available functions: {', '.join(names)}"
107
+ )
92
108
 
93
109
  @t.override
94
110
  def get_tools(self) -> list[BaseTool]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beamlit
3
- Version: 0.0.40rc84
3
+ Version: 0.0.41
4
4
  Summary: Add your description here
5
5
  Author-email: cploujoux <ch.ploujoux@gmail.com>
6
6
  Requires-Python: >=3.12
@@ -6,7 +6,7 @@ beamlit/run.py,sha256=HtDYDjD7oVfQ8r3T5_t4qN5UDJOJfsQILi45Z21ArAg,1446
6
6
  beamlit/types.py,sha256=E1hhDh_zXfsSQ0NCt9-uw90_Mr5iIlsdfnfvxv5HarU,1005
7
7
  beamlit/agents/__init__.py,sha256=bWsFaXUbAps3IsL3Prti89m1s714vICXodbQi77h3vY,206
8
8
  beamlit/agents/chain.py,sha256=vfCjiFHuu02uTTGicxMlFzjyICQkIjpXrBGs-7uJEsg,2826
9
- beamlit/agents/chat.py,sha256=5iv6dM7Xlg2oP2cGgAlpFreJl4P8GZAiN8MM3v0YVYs,4714
9
+ beamlit/agents/chat.py,sha256=6iZuaP25hUvrKdth-6sbtqxkZ1wM0Fv13eRttxNZlIU,4715
10
10
  beamlit/agents/decorator.py,sha256=R5evLoproCgYjKXmH-Vq31r6G2lzZvUitXD1NoTflcA,6014
11
11
  beamlit/agents/thread.py,sha256=LN5Ss-uOf5_hdB0WV1dqpn-N-pDJB3C2hUvlCzdqtdk,519
12
12
  beamlit/api/__init__.py,sha256=zTSiG_ujSjAqWPyc435YXaX9XTlpMjiJWBbV-f-YtdA,45
@@ -135,25 +135,18 @@ beamlit/common/error.py,sha256=f9oJDFxhoHK-vpjxBgEp0NwWIk0N_THPemUI7uQxVzU,270
135
135
  beamlit/common/instrumentation.py,sha256=L4Y6Xu7rQwIHngfp-d0LtWxReaPte6rIzykvkDaIyzE,9288
136
136
  beamlit/common/logger.py,sha256=nN_dSOl4bs13QU3Rod-w3e3jYOnlSrHx3_bs-ACY6Aw,1115
137
137
  beamlit/common/secrets.py,sha256=sid81bOe3LflkMKDHwBsBs9nIju8bp5-v9qU9gkyNMc,212
138
- beamlit/common/settings.py,sha256=TOHmf9haMq_VUEcbeaWeuS8zRVjLtVdcA0aGhNg32iA,3772
138
+ beamlit/common/settings.py,sha256=C7iZrLLvl6ap5VCVCYOoK20WdSFqacmd6HtaeZ7SF6s,3760
139
139
  beamlit/common/slugify.py,sha256=nR29r37IdWS2i44ZC6ZsXRgqKPYmvMGtFQ7BuIQUTlc,90
140
140
  beamlit/common/utils.py,sha256=jouz5igBvT37Xn_e94-foCHyQczVim-UzVcoIF6RWJ4,657
141
141
  beamlit/deploy/__init__.py,sha256=GS7l7Jtm2yKs7iNLKcfjYO-rAhUzggQ3xiYSf3oxLBY,91
142
142
  beamlit/deploy/deploy.py,sha256=J5VvXWeyIyz6CWy2ctld28T7sVfas-kiJZ1nx6Zw7t0,10374
143
143
  beamlit/deploy/format.py,sha256=U6UZEFAYLnGJJ7O2YmSdlUUFhnWNGAv6NZ-DW4KTgvI,2049
144
144
  beamlit/deploy/parser.py,sha256=Ga0poCZkoRnuTw082QnTcNGCBJncoRAnVsn8-1FsaJE,6907
145
- beamlit/functions/__init__.py,sha256=NcQPZZNfWhAJ1T1F6Xn21LFPMbZ7aMR2Sve3uZOkBCQ,170
146
- beamlit/functions/decorator.py,sha256=99oHbss0RZ6Km7Gf62otun1az9waZM0GPaOJvvwbmOI,8541
147
- beamlit/functions/github/__init__.py,sha256=gYnUkeegukOfbymdabuuJkScvH-_ZJygX05BoqkPn0o,49
148
- beamlit/functions/github/github.py,sha256=RfzWMT9nwPjsCOJr_-emN7eJHCIt2WsvkT9tq8-HfeA,568
149
- beamlit/functions/github/kit/__init__.py,sha256=jBwPqZv6C23_utukohxqXZwrlicNlI7PYPUj0Den7Cw,136
150
- beamlit/functions/github/kit/pull_request.py,sha256=wQVeRBakiqu-2ouflO8p1z7D5u07KNsitwyNRrp0KjM,1357
151
- beamlit/functions/math/__init__.py,sha256=wie4WME8jT-WpFRrtu-lDlHW31Mg6K2cwstjkUdLF3o,43
152
- beamlit/functions/math/math.py,sha256=CpoLJGwuvwCPGnVC8k9GYuIyvfUYPDQHKlZg3cx-z-A,1049
153
- beamlit/functions/mcp/mcp.py,sha256=c7OpmC_zIx1fc2lwoPiyJk_yMyRxWiwCpy9hvRV_C0Y,4080
154
- beamlit/functions/remote/remote.py,sha256=NldBFEostIX7yLw8ZE12MgVqhVpvKB4Z6FiQUBhPFsc,4207
155
- beamlit/functions/search/__init__.py,sha256=5NAthQ9PBwrkNg1FpLRx4flauvv0HyWuwaVS589c1Pw,49
156
- beamlit/functions/search/search.py,sha256=8s9ECltq7YE17j6rTxb12uY2EQY4_eTLHmwlIMThI0w,515
145
+ beamlit/functions/__init__.py,sha256=oejZ6GVd4-2kGKsOwRUq1u2AuSyrrn9kWIuH6WxMqhE,189
146
+ beamlit/functions/common.py,sha256=HbP_F7IYywB2jqxobjkjFqDaIsJXym-HPeOfLzoHSBo,7014
147
+ beamlit/functions/decorator.py,sha256=ZtSQsPLI70WKwi2jPhA7DaqREQUINpqt9BDVugeV_sg,1714
148
+ beamlit/functions/mcp/mcp.py,sha256=JnkeIh9jDyiZstBA0OH57aGx2JjEJ_DPtnM17Xw6ykM,4060
149
+ beamlit/functions/remote/remote.py,sha256=pY7gsmonkH8iN1anscMIWX-tW__OaBw14bodSUy1lCE,4845
157
150
  beamlit/models/__init__.py,sha256=DB2EBTVX5lTO7CzXvZaqiPtgc9n8SMPu59zGD5_Vvno,9652
158
151
  beamlit/models/acl.py,sha256=tH67gsl_BMaviSbTaaIkO1g9cWZgJ6VgAnYVjQSzGZY,3952
159
152
  beamlit/models/agent.py,sha256=w2f_d_nLGVHW7blklH34Nmm2TI3MCoEiQN3HMVga5XI,4002
@@ -285,6 +278,6 @@ beamlit/serve/app.py,sha256=ROS_tb9cO4GvOQKCwloyAzpYraTdIb3oG6sChXikeNw,3285
285
278
  beamlit/serve/middlewares/__init__.py,sha256=1dVmnOmhAQWvWktqHkKSIX-YoF6fmMU8xkUQuhg_rJU,148
286
279
  beamlit/serve/middlewares/accesslog.py,sha256=Mu4T4_9OvHybjA0ApzZFpgi2C8f3X1NbUk-76v634XM,631
287
280
  beamlit/serve/middlewares/processtime.py,sha256=lDAaIasZ4bwvN-HKHvZpaD9r-yrkVNZYx4abvbjbrCg,411
288
- beamlit-0.0.40rc84.dist-info/METADATA,sha256=IIgQeS831MisY-EbiNZqA54a05M-Cb3h_2LT3dxqT7o,3715
289
- beamlit-0.0.40rc84.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
290
- beamlit-0.0.40rc84.dist-info/RECORD,,
281
+ beamlit-0.0.41.dist-info/METADATA,sha256=ooEf3PaA3aQv8FjRaaNdt4lKqp5WjfqrghGbxAs6OXU,3711
282
+ beamlit-0.0.41.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
283
+ beamlit-0.0.41.dist-info/RECORD,,
@@ -1,3 +0,0 @@
1
- from .github import github
2
-
3
- __all__ = ["github"]
@@ -1,20 +0,0 @@
1
- from beamlit.common.secrets import Secret
2
-
3
- from . import kit
4
-
5
-
6
- def github(name: str, *args):
7
- """This function kit is used to perform actions on Github."""
8
- github_token = Secret.get("GITHUB_TOKEN")
9
- if not github_token:
10
- raise ValueError("github_token missing from configuration.")
11
-
12
- modes = {}
13
-
14
- for func_name in dir(kit):
15
- if not func_name.startswith("_"):
16
- modes[func_name] = getattr(kit, func_name)
17
- if name not in modes:
18
- msg = f"Invalid mode: {name}"
19
- raise ValueError(msg)
20
- return modes[name](*args)
@@ -1,7 +0,0 @@
1
- """Kit for interacting with GitHub."""
2
-
3
- from .pull_request import list_open_pull_requests
4
-
5
- __all__ = [
6
- "list_open_pull_requests",
7
- ]
@@ -1,51 +0,0 @@
1
- """Functions for interacting with GitHub pull requests."""
2
-
3
- from typing import Any
4
-
5
- from github import Auth, Github, PullRequest
6
- from pydash import pick
7
-
8
- from beamlit.common.secrets import Secret
9
-
10
-
11
- def list_open_pull_requests(
12
- repository: str,
13
- ):
14
- """
15
- This function will fetch a list of the repository's Pull Requests (PRs).
16
- It will return the title, and PR number of 5 PRs.
17
- """
18
- auth = Auth.Token(Secret.get("GITHUB_TOKEN"))
19
- gh = Github(auth=auth)
20
- repo = gh.get_repo(repository)
21
- return [_format_pull_request(pr) for pr in repo.get_pulls(state="open")[:5]]
22
-
23
-
24
- def _format_pull_request(pr: PullRequest) -> dict[str, Any]:
25
- raw_data = pr.raw_data
26
- raw_data["reviewers"] = [reviewer["login"] for reviewer in raw_data["requested_reviewers"]]
27
- raw_data["assignees"] = [assignee["login"] for assignee in raw_data["assignees"]]
28
-
29
- return pick(
30
- raw_data,
31
- [
32
- "id",
33
- "title",
34
- "labels",
35
- "number",
36
- "html_url",
37
- "diff_url",
38
- "patch_url",
39
- "commits",
40
- "additions",
41
- "deletions",
42
- "changed_files",
43
- "comments",
44
- "state",
45
- "user.login",
46
- "assignees",
47
- "reviewers",
48
- "created_at",
49
- "updated_at",
50
- ],
51
- )
@@ -1,3 +0,0 @@
1
- from .math import math
2
-
3
- __all__ = ["math"]
@@ -1,40 +0,0 @@
1
- import math as math_operation
2
- import operator
3
-
4
-
5
- def math(query: str):
6
- """A function for performing mathematical calculations.."""
7
- safe_dict = {
8
- "abs": abs,
9
- "round": round,
10
- "min": min,
11
- "max": max,
12
- "pow": math_operation.pow,
13
- "sqrt": math_operation.sqrt,
14
- "sin": math_operation.sin,
15
- "cos": math_operation.cos,
16
- "tan": math_operation.tan,
17
- "pi": math_operation.pi,
18
- "e": math_operation.e,
19
- }
20
-
21
- # Add basic arithmetic operators
22
- safe_dict.update(
23
- {
24
- "+": operator.add,
25
- "-": operator.sub,
26
- "*": operator.mul,
27
- "/": operator.truediv,
28
- "**": operator.pow,
29
- "%": operator.mod,
30
- }
31
- )
32
-
33
- try:
34
- # Replace 'x' with '*'
35
- query = query.replace("x", "*")
36
-
37
- # Evaluate the expression in a restricted environment
38
- return eval(query, {"__builtins__": {}}, safe_dict)
39
- except Exception as e:
40
- raise ValueError(f"Invalid expression: {str(e)}")
@@ -1,3 +0,0 @@
1
- from .search import search
2
-
3
- __all__ = ["search"]
@@ -1,15 +0,0 @@
1
- from langchain_community.tools.tavily_search.tool import TavilySearchResults
2
-
3
- from beamlit.common.secrets import Secret
4
-
5
-
6
- def search(query: str):
7
- """
8
- A search engine optimized for comprehensive, accurate, and trusted results.
9
- Useful for when you need to answer questions about current events.
10
- Input should be a search query.
11
- """
12
- api_key = Secret.get("TAVILY_API_KEY")
13
- tavily = TavilySearchResults(api_key=api_key, max_results=2)
14
- result = tavily.invoke(input=query)
15
- return result