beamlit 0.0.19__py3-none-any.whl → 0.0.20__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. beamlit/agents/__init__.py +4 -0
  2. beamlit/agents/chat.py +87 -0
  3. beamlit/agents/decorator.py +147 -0
  4. beamlit/api/agents/create_agent.py +14 -9
  5. beamlit/api/agents/delete_agent_history.py +159 -0
  6. beamlit/api/agents/get_agent_deployment_logs.py +11 -11
  7. beamlit/api/{authentication_providers/list_organizations_for_authentication_provider.py → agents/get_agent_environment_logs.py} +30 -42
  8. beamlit/api/{authentication_providers/get_model_with_repo_for_authentication_provider.py → agents/get_agent_history.py} +43 -68
  9. beamlit/api/agents/list_agent_deployment_history.py +11 -11
  10. beamlit/api/agents/list_agent_deployments.py +11 -11
  11. beamlit/api/agents/list_agent_history.py +151 -0
  12. beamlit/api/agents/list_agents.py +11 -11
  13. beamlit/api/agents/put_agent_history.py +185 -0
  14. beamlit/api/agents/update_agent.py +14 -9
  15. beamlit/api/environments/list_environments.py +11 -11
  16. beamlit/api/functions/create_function.py +14 -9
  17. beamlit/api/functions/get_function_deployment_logs.py +11 -11
  18. beamlit/api/functions/get_function_environment_logs.py +151 -0
  19. beamlit/api/functions/list_function_deployments.py +11 -11
  20. beamlit/api/functions/list_functions.py +11 -11
  21. beamlit/api/functions/update_function.py +14 -9
  22. beamlit/api/history/get_agents_history.py +11 -11
  23. beamlit/api/history/list_agents_history.py +11 -11
  24. beamlit/api/integrations/create_integration_connection.py +167 -0
  25. beamlit/api/integrations/delete_integration_connection.py +158 -0
  26. beamlit/api/integrations/get_integration.py +97 -0
  27. beamlit/api/integrations/get_integration_connection.py +154 -0
  28. beamlit/api/integrations/get_integration_connection_model.py +97 -0
  29. beamlit/api/integrations/get_integration_model.py +97 -0
  30. beamlit/api/integrations/list_integration_connection_models.py +97 -0
  31. beamlit/api/integrations/list_integration_connections.py +139 -0
  32. beamlit/api/integrations/list_integration_models.py +97 -0
  33. beamlit/api/integrations/update_integration_connection.py +180 -0
  34. beamlit/api/invitations/list_all_pending_invitations.py +11 -11
  35. beamlit/api/locations/list_locations.py +11 -11
  36. beamlit/api/model_providers/list_model_providers.py +11 -11
  37. beamlit/api/models/get_model_deployment_logs.py +11 -11
  38. beamlit/api/{authentication_providers/list_models_for_authentication_provider.py → models/get_model_environment_logs.py} +30 -38
  39. beamlit/api/models/list_model_deployments.py +11 -11
  40. beamlit/api/models/list_models.py +11 -11
  41. beamlit/api/policies/list_policies.py +11 -11
  42. beamlit/api/service_accounts/get_workspace_service_accounts.py +11 -11
  43. beamlit/api/service_accounts/list_api_keys_for_service_account.py +11 -11
  44. beamlit/api/store/list_store_agents.py +11 -11
  45. beamlit/api/store/list_store_functions.py +11 -11
  46. beamlit/api/workspaces/list_workspace_users.py +11 -11
  47. beamlit/api/workspaces/list_workspaces.py +11 -11
  48. beamlit/authentication/__init__.py +29 -8
  49. beamlit/authentication/apikey.py +8 -2
  50. beamlit/authentication/authentication.py +66 -3
  51. beamlit/authentication/clientcredentials.py +108 -0
  52. beamlit/authentication/credentials.py +22 -8
  53. beamlit/authentication/device_mode.py +23 -13
  54. beamlit/common/__init__.py +13 -0
  55. beamlit/common/generate.py +183 -0
  56. beamlit/common/logger.py +29 -0
  57. beamlit/common/secrets.py +11 -0
  58. beamlit/common/settings.py +156 -0
  59. beamlit/common/utils.py +15 -0
  60. beamlit/functions/__init__.py +5 -0
  61. beamlit/functions/decorator.py +90 -0
  62. beamlit/functions/github/__init__.py +3 -0
  63. beamlit/functions/github/github.py +21 -0
  64. beamlit/functions/github/kit/__init__.py +7 -0
  65. beamlit/functions/github/kit/pull_request.py +51 -0
  66. beamlit/functions/math/__init__.py +3 -0
  67. beamlit/functions/math/math.py +40 -0
  68. beamlit/functions/search/__init__.py +3 -0
  69. beamlit/functions/search/search.py +15 -0
  70. beamlit/models/__init__.py +24 -0
  71. beamlit/models/acl.py +4 -2
  72. beamlit/models/agent.py +5 -3
  73. beamlit/models/agent_chain.py +4 -2
  74. beamlit/models/agent_configuration.py +4 -2
  75. beamlit/models/agent_deployment.py +41 -28
  76. beamlit/models/agent_deployment_configuration.py +4 -2
  77. beamlit/models/agent_deployment_configuration_type_0.py +43 -0
  78. beamlit/models/agent_deployment_history.py +7 -5
  79. beamlit/models/agent_deployment_history_event.py +11 -9
  80. beamlit/models/agent_deployment_pod_template.py +4 -2
  81. beamlit/models/agent_deployment_pod_template_type_0.py +43 -0
  82. beamlit/models/agent_history.py +165 -0
  83. beamlit/models/agent_history_event.py +131 -0
  84. beamlit/models/agent_metadata.py +144 -0
  85. beamlit/models/agent_release.py +4 -2
  86. beamlit/models/agent_spec.py +248 -0
  87. beamlit/models/agent_with_deployments.py +176 -0
  88. beamlit/models/api_key.py +4 -2
  89. beamlit/models/authentication_provider_model.py +8 -6
  90. beamlit/models/authentication_provider_organization.py +4 -2
  91. beamlit/models/configuration.py +12 -10
  92. beamlit/models/continent.py +4 -2
  93. beamlit/models/core_spec.py +185 -0
  94. beamlit/models/country.py +4 -2
  95. beamlit/models/create_api_key_for_service_account_body.py +4 -2
  96. beamlit/models/create_workspace_service_account_body.py +4 -2
  97. beamlit/models/create_workspace_service_account_response_200.py +4 -2
  98. beamlit/models/delete_workspace_service_account_response_200.py +4 -2
  99. beamlit/models/deployment_configuration.py +4 -2
  100. beamlit/models/deployment_configurations.py +22 -7
  101. beamlit/models/deployment_serverless_config.py +4 -2
  102. beamlit/models/deployment_serverless_config_type_0.py +220 -0
  103. beamlit/models/environment.py +9 -7
  104. beamlit/models/environment_metrics.py +26 -5
  105. beamlit/models/environment_spec.py +61 -0
  106. beamlit/models/flavor.py +11 -9
  107. beamlit/models/function.py +5 -3
  108. beamlit/models/function_configuration.py +4 -2
  109. beamlit/models/function_deployment.py +33 -20
  110. beamlit/models/function_deployment_configuration.py +4 -2
  111. beamlit/models/function_deployment_configuration_type_0.py +43 -0
  112. beamlit/models/function_deployment_pod_template.py +4 -2
  113. beamlit/models/function_deployment_pod_template_type_0.py +43 -0
  114. beamlit/models/function_kit.py +7 -5
  115. beamlit/models/function_metadata.py +144 -0
  116. beamlit/models/function_provider_ref.py +4 -2
  117. beamlit/models/function_release.py +4 -2
  118. beamlit/models/function_spec.py +246 -0
  119. beamlit/models/function_with_deployments.py +176 -0
  120. beamlit/models/get_workspace_service_accounts_response_200_item.py +4 -2
  121. beamlit/models/increase_and_rate_metric.py +104 -0
  122. beamlit/models/integration.py +198 -0
  123. beamlit/models/integration_config.py +45 -0
  124. beamlit/models/integration_connection.py +198 -0
  125. beamlit/models/integration_connection_config.py +45 -0
  126. beamlit/models/integration_connection_secret.py +61 -0
  127. beamlit/models/integration_connection_spec.py +99 -0
  128. beamlit/models/integration_model.py +144 -0
  129. beamlit/models/integration_secret.py +61 -0
  130. beamlit/models/invite_workspace_user_body.py +4 -2
  131. beamlit/models/labels_type_0.py +4 -2
  132. beamlit/models/location.py +7 -5
  133. beamlit/models/location_response.py +7 -5
  134. beamlit/models/metadata.py +135 -0
  135. beamlit/models/{labels.py → metadata_labels.py} +5 -5
  136. beamlit/models/metric.py +4 -2
  137. beamlit/models/metrics.py +68 -25
  138. beamlit/models/model.py +5 -3
  139. beamlit/models/model_deployment.py +27 -14
  140. beamlit/models/model_deployment_log.py +4 -2
  141. beamlit/models/model_deployment_metrics.py +11 -9
  142. beamlit/models/model_deployment_metrics_inference_per_second_per_region.py +7 -5
  143. beamlit/models/model_deployment_metrics_query_per_second_per_region_per_code.py +5 -3
  144. beamlit/models/model_deployment_pod_template.py +4 -2
  145. beamlit/models/model_deployment_pod_template_type_0.py +43 -0
  146. beamlit/models/model_metadata.py +144 -0
  147. beamlit/models/model_metrics.py +8 -6
  148. beamlit/models/model_provider.py +13 -11
  149. beamlit/models/model_provider_ref.py +4 -2
  150. beamlit/models/model_release.py +4 -2
  151. beamlit/models/model_spec.py +194 -0
  152. beamlit/models/model_with_deployments.py +8 -6
  153. beamlit/models/owner_fields.py +68 -0
  154. beamlit/models/pending_invitation.py +4 -2
  155. beamlit/models/pending_invitation_accept.py +5 -3
  156. beamlit/models/pending_invitation_render.py +7 -5
  157. beamlit/models/pending_invitation_render_invited_by.py +4 -2
  158. beamlit/models/pending_invitation_render_workspace.py +4 -2
  159. beamlit/models/pending_invitation_workspace_details.py +8 -6
  160. beamlit/models/pod_template_spec.py +43 -0
  161. beamlit/models/policy.py +22 -20
  162. beamlit/models/policy_location.py +11 -9
  163. beamlit/models/policy_spec.py +125 -0
  164. beamlit/models/provider_config.py +9 -16
  165. beamlit/models/qps.py +4 -2
  166. beamlit/models/resource_deployment_log.py +4 -2
  167. beamlit/models/resource_deployment_metrics.py +119 -9
  168. beamlit/models/resource_deployment_metrics_inference_per_region.py +77 -0
  169. beamlit/models/resource_deployment_metrics_inference_per_region_type_0.py +79 -0
  170. beamlit/models/resource_deployment_metrics_inference_per_second_per_region.py +7 -5
  171. beamlit/models/resource_deployment_metrics_inference_per_second_per_region_type_0.py +79 -0
  172. beamlit/models/resource_deployment_metrics_query_per_region_per_code.py +75 -0
  173. beamlit/models/resource_deployment_metrics_query_per_region_per_code_type_0.py +73 -0
  174. beamlit/models/resource_deployment_metrics_query_per_second_per_region_per_code.py +5 -3
  175. beamlit/models/resource_deployment_metrics_query_per_second_per_region_per_code_type_0.py +73 -0
  176. beamlit/models/resource_environment_metrics.py +210 -0
  177. beamlit/models/resource_environment_metrics_inference_per_second_per_region.py +79 -0
  178. beamlit/models/resource_environment_metrics_query_per_second_per_region_per_code.py +73 -0
  179. beamlit/models/resource_log.py +68 -0
  180. beamlit/models/resource_metrics.py +44 -6
  181. beamlit/models/runtime.py +25 -23
  182. beamlit/models/runtime_readiness_probe.py +4 -2
  183. beamlit/models/runtime_readiness_probe_type_0.py +43 -0
  184. beamlit/models/runtime_resources.py +4 -2
  185. beamlit/models/runtime_type_0.py +111 -0
  186. beamlit/models/runtime_type_0_readiness_probe.py +43 -0
  187. beamlit/models/runtime_type_0_readiness_probe_type_0.py +43 -0
  188. beamlit/models/runtime_type_0_resources.py +59 -0
  189. beamlit/models/serverless_config.py +4 -2
  190. beamlit/models/spec_configuration.py +68 -0
  191. beamlit/models/standard_fields_dynamo_db.py +4 -2
  192. beamlit/models/store_agent.py +8 -6
  193. beamlit/models/store_agent_configuration.py +4 -2
  194. beamlit/models/store_agent_labels.py +4 -2
  195. beamlit/models/store_agent_labels_type_0.py +43 -0
  196. beamlit/models/store_configuration.py +18 -16
  197. beamlit/models/store_configuration_option.py +4 -2
  198. beamlit/models/store_function.py +14 -12
  199. beamlit/models/store_function_configuration.py +4 -2
  200. beamlit/models/store_function_kit.py +7 -5
  201. beamlit/models/store_function_labels.py +4 -2
  202. beamlit/models/store_function_labels_type_0.py +43 -0
  203. beamlit/models/store_function_parameter.py +11 -9
  204. beamlit/models/time_fields.py +68 -0
  205. beamlit/models/update_workspace_service_account_body.py +4 -2
  206. beamlit/models/update_workspace_service_account_response_200.py +4 -2
  207. beamlit/models/update_workspace_user_role_body.py +4 -2
  208. beamlit/models/websocket_channel.py +86 -0
  209. beamlit/models/workspace.py +5 -3
  210. beamlit/models/workspace_labels.py +4 -2
  211. beamlit/models/workspace_user.py +4 -2
  212. beamlit/run.py +49 -0
  213. beamlit/serve/app.py +78 -0
  214. beamlit/serve/middlewares/__init__.py +4 -0
  215. beamlit/serve/middlewares/accesslog.py +14 -0
  216. beamlit/serve/middlewares/processtime.py +12 -0
  217. {beamlit-0.0.19.dist-info → beamlit-0.0.20.dist-info}/METADATA +11 -2
  218. beamlit-0.0.20.dist-info/RECORD +301 -0
  219. beamlit-0.0.19.dist-info/RECORD +0 -211
  220. /beamlit/api/{authentication_providers → integrations}/__init__.py +0 -0
  221. {beamlit-0.0.19.dist-info → beamlit-0.0.20.dist-info}/WHEEL +0 -0
@@ -0,0 +1,11 @@
1
+ import os
2
+
3
+
4
+ class Secret:
5
+ @staticmethod
6
+ def get(name: str):
7
+ return os.getenv(name, os.getenv(f"bl_{name}"))
8
+
9
+ @staticmethod
10
+ def set(name: str, value: str):
11
+ os.environ[name] = value
@@ -0,0 +1,156 @@
1
+ import os
2
+ from logging import getLogger
3
+ from typing import List, Tuple, Type, Union
4
+
5
+ from langchain_core.language_models.chat_models import BaseChatModel
6
+ from langgraph.graph.graph import CompiledGraph
7
+ from pydantic import Field
8
+ from pydantic_settings import (
9
+ BaseSettings,
10
+ PydanticBaseSettingsSource,
11
+ SettingsConfigDict,
12
+ YamlConfigSettingsSource,
13
+ )
14
+
15
+ from beamlit.api.functions import get_function_deployment
16
+ from beamlit.api.models import get_model_deployment
17
+ from beamlit.client import AuthenticatedClient
18
+ from beamlit.common.logger import init as init_logger
19
+ from beamlit.models.agent_deployment import AgentDeployment
20
+ from beamlit.models.function_deployment import FunctionDeployment
21
+ from beamlit.models.model_deployment import ModelDeployment
22
+ from beamlit.types import UNSET, Unset
23
+
24
+ global SETTINGS
25
+ SETTINGS = None
26
+
27
+
28
+ def get_settings():
29
+ return SETTINGS
30
+
31
+
32
+ class SettingsAgent(BaseSettings):
33
+ agent: Union[None, CompiledGraph, BaseChatModel] = None
34
+ chain: Union[Unset, List[AgentDeployment]] = UNSET
35
+ model: Union[Unset, ModelDeployment] = UNSET
36
+ functions: Union[Unset, List[FunctionDeployment]] = UNSET
37
+ functions_directory: str = Field(default="src/functions")
38
+ chat_model: Union[None, BaseChatModel] = None
39
+ module: str = Field(default="main.main")
40
+
41
+
42
+ class SettingsAuthentication(BaseSettings):
43
+ api_key: Union[None, str] = None
44
+ jwt: Union[None, str] = None
45
+ client_credentials: Union[None, str] = None
46
+
47
+
48
+ class SettingsServer(BaseSettings):
49
+ module: str = Field(default="main.main")
50
+ port: int = Field(default=80)
51
+ host: str = Field(default="0.0.0.0")
52
+
53
+
54
+ class Settings(BaseSettings):
55
+ model_config = SettingsConfigDict(
56
+ yaml_file="beamlit.yaml",
57
+ env_prefix="bl_",
58
+ env_nested_delimiter="_",
59
+ )
60
+
61
+ workspace: str
62
+ environment: str
63
+ type: str = Field(default="agent")
64
+ name: str = Field(default="beamlit-agent")
65
+ base_url: str = Field(default="https://api.beamlit.dev/v0")
66
+ run_url: str = Field(default="https://run.beamlit.dev")
67
+ log_level: str = Field(default="INFO")
68
+ agent: SettingsAgent = SettingsAgent()
69
+ server: SettingsServer = SettingsServer()
70
+ authentication: SettingsAuthentication = SettingsAuthentication()
71
+
72
+ @classmethod
73
+ def settings_customise_sources(
74
+ cls,
75
+ settings_cls: Type[BaseSettings],
76
+ init_settings: PydanticBaseSettingsSource,
77
+ env_settings: PydanticBaseSettingsSource,
78
+ dotenv_settings: PydanticBaseSettingsSource,
79
+ file_secret_settings: PydanticBaseSettingsSource,
80
+ ) -> Tuple[PydanticBaseSettingsSource, ...]:
81
+ return (
82
+ env_settings,
83
+ dotenv_settings,
84
+ file_secret_settings,
85
+ YamlConfigSettingsSource(settings_cls),
86
+ init_settings,
87
+ )
88
+
89
+
90
+ def init_agent(
91
+ client: AuthenticatedClient,
92
+ destination: str = f"{os.getcwd()}/src/beamlit_generated.py",
93
+ ):
94
+ from beamlit.api.agents import get_agent_deployment
95
+ from beamlit.common.generate import generate
96
+
97
+ logger = getLogger(__name__)
98
+ settings = get_settings()
99
+ # Init configuration from environment variables
100
+ if settings.agent.functions or settings.agent.chain:
101
+ return
102
+
103
+ # Init configuration from beamlit control plane
104
+ name = settings.name
105
+ env = settings.environment
106
+
107
+ agent_deployment = get_agent_deployment.sync(name, env, client=client)
108
+ function_deployments = []
109
+ agent_chain_deployments = []
110
+ if agent_deployment.functions:
111
+ for function in agent_deployment.functions:
112
+ function_deployment = get_function_deployment.sync(function, env, client=client)
113
+ function_deployments.append(function_deployment)
114
+ settings.agent.functions = function_deployments
115
+
116
+ if agent_deployment.agent_chain:
117
+ for chain in agent_deployment.agent_chain:
118
+ if chain.enabled:
119
+ agent_deployment = get_agent_deployment.sync(chain.name, env, client=client)
120
+ if chain.description:
121
+ agent_deployment.description = chain.description
122
+ agent_chain_deployments.append(agent_deployment)
123
+ settings.agent.chain = agent_chain_deployments
124
+ if agent_deployment.model:
125
+ model_deployment = get_model_deployment.sync(agent_deployment.model, env, client=client)
126
+ settings.agent.model = model_deployment
127
+
128
+ content_generate = generate(destination, dry_run=True)
129
+ compared_content = None
130
+ if os.path.exists(destination):
131
+ compared_content = open(destination).read()
132
+
133
+ if not os.path.exists(destination) or (
134
+ compared_content and content_generate != compared_content
135
+ ):
136
+ logger.info("Generating agent code")
137
+ generate(destination)
138
+
139
+
140
+ def init() -> Settings:
141
+ """Parse the beamlit.yaml file to get configurations."""
142
+ from beamlit.authentication.credentials import current_context
143
+
144
+ global SETTINGS
145
+
146
+ context = current_context()
147
+ kwargs = {}
148
+ if context.workspace:
149
+ kwargs["workspace"] = context.workspace
150
+ if context.environment:
151
+ kwargs["environment"] = context.environment
152
+
153
+ SETTINGS = Settings(**kwargs)
154
+ init_logger(SETTINGS.log_level)
155
+
156
+ return SETTINGS
@@ -0,0 +1,15 @@
1
+ import filecmp
2
+ import os
3
+ import shutil
4
+
5
+
6
+ def copy_folder(source_folder: str, destination_folder: str):
7
+ for file in os.listdir(source_folder):
8
+ if os.path.isdir(f"{source_folder}/{file}"):
9
+ if not os.path.exists(f"{destination_folder}/{file}"):
10
+ os.makedirs(f"{destination_folder}/{file}")
11
+ copy_folder(f"{source_folder}/{file}", f"{destination_folder}/{file}")
12
+ elif not os.path.exists(f"{destination_folder}/{file}") or not filecmp.cmp(
13
+ f"{source_folder}/{file}", f"{destination_folder}/{file}"
14
+ ):
15
+ shutil.copy(f"{source_folder}/{file}", f"{destination_folder}/{file}")
@@ -0,0 +1,5 @@
1
+ """Functions package providing function decorators and utilities."""
2
+
3
+ from .decorator import function, kit
4
+
5
+ __all__ = ["function", "kit"]
@@ -0,0 +1,90 @@
1
+ """Decorators for creating function tools with Beamlit and LangChain integration."""
2
+
3
+ from collections.abc import Callable
4
+ from logging import getLogger
5
+
6
+ from langchain_core.tools import create_schema_from_function, tool
7
+
8
+ from beamlit.authentication import new_client
9
+ from beamlit.common.settings import get_settings
10
+ from beamlit.models import FunctionDeployment, FunctionKit
11
+ from beamlit.run import RunClient
12
+
13
+ logger = getLogger(__name__)
14
+
15
+
16
+ def get_remote_function(func: Callable, bl_function: FunctionDeployment):
17
+ settings = get_settings()
18
+
19
+ def _partial(*args, **kwargs):
20
+ # Get function signature parameters
21
+ try:
22
+ client = new_client()
23
+ run_client = RunClient(client)
24
+ name = (bl_function and bl_function.function) or func.__name__
25
+ logger.debug(
26
+ f"Calling remote function: NAME={name}"
27
+ f" PARAMS={kwargs} ENVIRONMENT={settings.environment}"
28
+ )
29
+ response = run_client.run(
30
+ resource_type="function",
31
+ resource_name=name,
32
+ environment=settings.environment,
33
+ method="POST",
34
+ headers={},
35
+ json=kwargs,
36
+ )
37
+ if response.status_code >= 400:
38
+ content = f"{response.status_code}:{response.text}"
39
+ return f"Error calling remote function: {content}"
40
+ logger.debug(
41
+ f"Response from remote function: NAME={name}"
42
+ f" RESPONSE={response.json()} ENVIRONMENT={settings.environment}"
43
+ )
44
+ return response.json()
45
+ except Exception as e:
46
+ logger.error(f"Error calling function {bl_function.id}: {e}")
47
+ raise e
48
+
49
+ remote_func = _partial
50
+ remote_func.__name__ = func.__name__
51
+ remote_func.__doc__ = func.__doc__
52
+ return remote_func
53
+
54
+
55
+ def kit(bl_kit: FunctionKit = None, **kwargs: dict) -> Callable:
56
+ """Create function tools with Beamlit and LangChain integration."""
57
+
58
+ def wrapper(func: Callable) -> Callable:
59
+ if bl_kit and not func.__doc__ and bl_kit.description:
60
+ func.__doc__ = bl_kit.description
61
+ return tool(func, **kwargs)
62
+
63
+ return wrapper
64
+
65
+
66
+ def function(
67
+ *args, bl_function: FunctionDeployment = None, kit=False, **kwargs: dict
68
+ ) -> Callable:
69
+ """Create function tools with Beamlit and LangChain integration."""
70
+ settings = get_settings()
71
+
72
+ def wrapper(func: Callable) -> Callable:
73
+ if bl_function and not func.__doc__ and bl_function.description:
74
+ func.__doc__ = bl_function.description
75
+ if (
76
+ settings.environment == "development"
77
+ or settings.environment == "production"
78
+ ):
79
+ remote_func = get_remote_function(func, bl_function)
80
+ if not kwargs.get("args_schema"):
81
+ kwargs["args_schema"] = create_schema_from_function(
82
+ func.__name__,
83
+ func,
84
+ parse_docstring=func.__doc__,
85
+ )
86
+ return tool(remote_func, **kwargs)
87
+ return tool(func, **kwargs)
88
+
89
+ return wrapper
90
+ return wrapper
@@ -0,0 +1,3 @@
1
+ from .github import github
2
+
3
+ __all__ = ["github"]
@@ -0,0 +1,21 @@
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)
21
+ return modes[name](*args)
@@ -0,0 +1,7 @@
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
+ ]
@@ -0,0 +1,51 @@
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
+ )
@@ -0,0 +1,3 @@
1
+ from .math import math
2
+
3
+ __all__ = ["math"]
@@ -0,0 +1,40 @@
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)}")
@@ -0,0 +1,3 @@
1
+ from .search import search
2
+
3
+ __all__ = ["search"]
@@ -0,0 +1,15 @@
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
@@ -10,6 +10,7 @@ from .agent_deployment_history import AgentDeploymentHistory
10
10
  from .agent_deployment_history_event import AgentDeploymentHistoryEvent
11
11
  from .agent_deployment_pod_template import AgentDeploymentPodTemplate
12
12
  from .agent_release import AgentRelease
13
+ from .agent_with_deployments import AgentWithDeployments
13
14
  from .api_key import ApiKey
14
15
  from .authentication_provider_model import AuthenticationProviderModel
15
16
  from .authentication_provider_organization import AuthenticationProviderOrganization
@@ -34,7 +35,16 @@ from .function_deployment_pod_template import FunctionDeploymentPodTemplate
34
35
  from .function_kit import FunctionKit
35
36
  from .function_provider_ref import FunctionProviderRef
36
37
  from .function_release import FunctionRelease
38
+ from .function_with_deployments import FunctionWithDeployments
37
39
  from .get_workspace_service_accounts_response_200_item import GetWorkspaceServiceAccountsResponse200Item
40
+ from .increase_and_rate_metric import IncreaseAndRateMetric
41
+ from .integration import Integration
42
+ from .integration_config import IntegrationConfig
43
+ from .integration_connection import IntegrationConnection
44
+ from .integration_connection_config import IntegrationConnectionConfig
45
+ from .integration_connection_secret import IntegrationConnectionSecret
46
+ from .integration_model import IntegrationModel
47
+ from .integration_secret import IntegrationSecret
38
48
  from .invite_workspace_user_body import InviteWorkspaceUserBody
39
49
  from .labels_type_0 import LabelsType0
40
50
  from .location import Location
@@ -67,9 +77,11 @@ from .provider_config import ProviderConfig
67
77
  from .qps import QPS
68
78
  from .resource_deployment_log import ResourceDeploymentLog
69
79
  from .resource_deployment_metrics import ResourceDeploymentMetrics
80
+ from .resource_deployment_metrics_inference_per_region import ResourceDeploymentMetricsInferencePerRegion
70
81
  from .resource_deployment_metrics_inference_per_second_per_region import (
71
82
  ResourceDeploymentMetricsInferencePerSecondPerRegion,
72
83
  )
84
+ from .resource_deployment_metrics_query_per_region_per_code import ResourceDeploymentMetricsQueryPerRegionPerCode
73
85
  from .resource_deployment_metrics_query_per_second_per_region_per_code import (
74
86
  ResourceDeploymentMetricsQueryPerSecondPerRegionPerCode,
75
87
  )
@@ -107,6 +119,7 @@ __all__ = (
107
119
  "AgentDeploymentHistoryEvent",
108
120
  "AgentDeploymentPodTemplate",
109
121
  "AgentRelease",
122
+ "AgentWithDeployments",
110
123
  "ApiKey",
111
124
  "AuthenticationProviderModel",
112
125
  "AuthenticationProviderOrganization",
@@ -131,7 +144,16 @@ __all__ = (
131
144
  "FunctionKit",
132
145
  "FunctionProviderRef",
133
146
  "FunctionRelease",
147
+ "FunctionWithDeployments",
134
148
  "GetWorkspaceServiceAccountsResponse200Item",
149
+ "IncreaseAndRateMetric",
150
+ "Integration",
151
+ "IntegrationConfig",
152
+ "IntegrationConnection",
153
+ "IntegrationConnectionConfig",
154
+ "IntegrationConnectionSecret",
155
+ "IntegrationModel",
156
+ "IntegrationSecret",
135
157
  "InviteWorkspaceUserBody",
136
158
  "LabelsType0",
137
159
  "Location",
@@ -162,7 +184,9 @@ __all__ = (
162
184
  "QPS",
163
185
  "ResourceDeploymentLog",
164
186
  "ResourceDeploymentMetrics",
187
+ "ResourceDeploymentMetricsInferencePerRegion",
165
188
  "ResourceDeploymentMetricsInferencePerSecondPerRegion",
189
+ "ResourceDeploymentMetricsQueryPerRegionPerCode",
166
190
  "ResourceDeploymentMetricsQueryPerSecondPerRegionPerCode",
167
191
  "ResourceMetrics",
168
192
  "Runtime",
beamlit/models/acl.py CHANGED
@@ -1,4 +1,4 @@
1
- from typing import Any, Type, TypeVar, Union
1
+ from typing import Any, TypeVar, Union
2
2
 
3
3
  from attrs import define as _attrs_define
4
4
  from attrs import field as _attrs_field
@@ -91,7 +91,9 @@ class ACL:
91
91
  return field_dict
92
92
 
93
93
  @classmethod
94
- def from_dict(cls: Type[T], src_dict: dict[str, Any]) -> T:
94
+ def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
95
+ if not src_dict:
96
+ return None
95
97
  d = src_dict.copy()
96
98
  created_at = d.pop("created_at", UNSET)
97
99
 
beamlit/models/agent.py CHANGED
@@ -1,4 +1,4 @@
1
- from typing import TYPE_CHECKING, Any, Dict, Type, TypeVar, Union, cast
1
+ from typing import TYPE_CHECKING, Any, TypeVar, Union, cast
2
2
 
3
3
  from attrs import define as _attrs_define
4
4
  from attrs import field as _attrs_field
@@ -50,7 +50,7 @@ class Agent:
50
50
 
51
51
  display_name = self.display_name
52
52
 
53
- labels: Union[Dict[str, Any], None, Unset]
53
+ labels: Union[None, Unset, dict[str, Any]]
54
54
  if isinstance(self.labels, Unset):
55
55
  labels = UNSET
56
56
  elif isinstance(self.labels, LabelsType0):
@@ -85,9 +85,11 @@ class Agent:
85
85
  return field_dict
86
86
 
87
87
  @classmethod
88
- def from_dict(cls: Type[T], src_dict: dict[str, Any]) -> T:
88
+ def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
89
89
  from ..models.labels_type_0 import LabelsType0
90
90
 
91
+ if not src_dict:
92
+ return None
91
93
  d = src_dict.copy()
92
94
  created_at = d.pop("created_at", UNSET)
93
95
 
@@ -1,4 +1,4 @@
1
- from typing import Any, Type, TypeVar, Union
1
+ from typing import Any, TypeVar, Union
2
2
 
3
3
  from attrs import define as _attrs_define
4
4
  from attrs import field as _attrs_field
@@ -43,7 +43,9 @@ class AgentChain:
43
43
  return field_dict
44
44
 
45
45
  @classmethod
46
- def from_dict(cls: Type[T], src_dict: dict[str, Any]) -> T:
46
+ def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
47
+ if not src_dict:
48
+ return None
47
49
  d = src_dict.copy()
48
50
  description = d.pop("description", UNSET)
49
51
 
@@ -1,4 +1,4 @@
1
- from typing import Any, Type, TypeVar, Union
1
+ from typing import Any, TypeVar, Union
2
2
 
3
3
  from attrs import define as _attrs_define
4
4
  from attrs import field as _attrs_field
@@ -37,7 +37,9 @@ class AgentConfiguration:
37
37
  return field_dict
38
38
 
39
39
  @classmethod
40
- def from_dict(cls: Type[T], src_dict: dict[str, Any]) -> T:
40
+ def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
41
+ if not src_dict:
42
+ return None
41
43
  d = src_dict.copy()
42
44
  secret = d.pop("secret", UNSET)
43
45