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.
- beamlit/agents/__init__.py +4 -0
- beamlit/agents/chat.py +87 -0
- beamlit/agents/decorator.py +147 -0
- beamlit/api/agents/create_agent.py +14 -9
- beamlit/api/agents/delete_agent_history.py +159 -0
- beamlit/api/agents/get_agent_deployment_logs.py +11 -11
- beamlit/api/{authentication_providers/list_organizations_for_authentication_provider.py → agents/get_agent_environment_logs.py} +30 -42
- beamlit/api/{authentication_providers/get_model_with_repo_for_authentication_provider.py → agents/get_agent_history.py} +43 -68
- beamlit/api/agents/list_agent_deployment_history.py +11 -11
- beamlit/api/agents/list_agent_deployments.py +11 -11
- beamlit/api/agents/list_agent_history.py +151 -0
- beamlit/api/agents/list_agents.py +11 -11
- beamlit/api/agents/put_agent_history.py +185 -0
- beamlit/api/agents/update_agent.py +14 -9
- beamlit/api/environments/list_environments.py +11 -11
- beamlit/api/functions/create_function.py +14 -9
- beamlit/api/functions/get_function_deployment_logs.py +11 -11
- beamlit/api/functions/get_function_environment_logs.py +151 -0
- beamlit/api/functions/list_function_deployments.py +11 -11
- beamlit/api/functions/list_functions.py +11 -11
- beamlit/api/functions/update_function.py +14 -9
- beamlit/api/history/get_agents_history.py +11 -11
- beamlit/api/history/list_agents_history.py +11 -11
- beamlit/api/integrations/create_integration_connection.py +167 -0
- beamlit/api/integrations/delete_integration_connection.py +158 -0
- beamlit/api/integrations/get_integration.py +97 -0
- beamlit/api/integrations/get_integration_connection.py +154 -0
- beamlit/api/integrations/get_integration_connection_model.py +97 -0
- beamlit/api/integrations/get_integration_model.py +97 -0
- beamlit/api/integrations/list_integration_connection_models.py +97 -0
- beamlit/api/integrations/list_integration_connections.py +139 -0
- beamlit/api/integrations/list_integration_models.py +97 -0
- beamlit/api/integrations/update_integration_connection.py +180 -0
- beamlit/api/invitations/list_all_pending_invitations.py +11 -11
- beamlit/api/locations/list_locations.py +11 -11
- beamlit/api/model_providers/list_model_providers.py +11 -11
- beamlit/api/models/get_model_deployment_logs.py +11 -11
- beamlit/api/{authentication_providers/list_models_for_authentication_provider.py → models/get_model_environment_logs.py} +30 -38
- beamlit/api/models/list_model_deployments.py +11 -11
- beamlit/api/models/list_models.py +11 -11
- beamlit/api/policies/list_policies.py +11 -11
- beamlit/api/service_accounts/get_workspace_service_accounts.py +11 -11
- beamlit/api/service_accounts/list_api_keys_for_service_account.py +11 -11
- beamlit/api/store/list_store_agents.py +11 -11
- beamlit/api/store/list_store_functions.py +11 -11
- beamlit/api/workspaces/list_workspace_users.py +11 -11
- beamlit/api/workspaces/list_workspaces.py +11 -11
- beamlit/authentication/__init__.py +29 -8
- beamlit/authentication/apikey.py +8 -2
- beamlit/authentication/authentication.py +66 -3
- beamlit/authentication/clientcredentials.py +108 -0
- beamlit/authentication/credentials.py +22 -8
- beamlit/authentication/device_mode.py +23 -13
- beamlit/common/__init__.py +13 -0
- beamlit/common/generate.py +183 -0
- beamlit/common/logger.py +29 -0
- beamlit/common/secrets.py +11 -0
- beamlit/common/settings.py +156 -0
- beamlit/common/utils.py +15 -0
- beamlit/functions/__init__.py +5 -0
- beamlit/functions/decorator.py +90 -0
- beamlit/functions/github/__init__.py +3 -0
- beamlit/functions/github/github.py +21 -0
- beamlit/functions/github/kit/__init__.py +7 -0
- beamlit/functions/github/kit/pull_request.py +51 -0
- beamlit/functions/math/__init__.py +3 -0
- beamlit/functions/math/math.py +40 -0
- beamlit/functions/search/__init__.py +3 -0
- beamlit/functions/search/search.py +15 -0
- beamlit/models/__init__.py +24 -0
- beamlit/models/acl.py +4 -2
- beamlit/models/agent.py +5 -3
- beamlit/models/agent_chain.py +4 -2
- beamlit/models/agent_configuration.py +4 -2
- beamlit/models/agent_deployment.py +41 -28
- beamlit/models/agent_deployment_configuration.py +4 -2
- beamlit/models/agent_deployment_configuration_type_0.py +43 -0
- beamlit/models/agent_deployment_history.py +7 -5
- beamlit/models/agent_deployment_history_event.py +11 -9
- beamlit/models/agent_deployment_pod_template.py +4 -2
- beamlit/models/agent_deployment_pod_template_type_0.py +43 -0
- beamlit/models/agent_history.py +165 -0
- beamlit/models/agent_history_event.py +131 -0
- beamlit/models/agent_metadata.py +144 -0
- beamlit/models/agent_release.py +4 -2
- beamlit/models/agent_spec.py +248 -0
- beamlit/models/agent_with_deployments.py +176 -0
- beamlit/models/api_key.py +4 -2
- beamlit/models/authentication_provider_model.py +8 -6
- beamlit/models/authentication_provider_organization.py +4 -2
- beamlit/models/configuration.py +12 -10
- beamlit/models/continent.py +4 -2
- beamlit/models/core_spec.py +185 -0
- beamlit/models/country.py +4 -2
- beamlit/models/create_api_key_for_service_account_body.py +4 -2
- beamlit/models/create_workspace_service_account_body.py +4 -2
- beamlit/models/create_workspace_service_account_response_200.py +4 -2
- beamlit/models/delete_workspace_service_account_response_200.py +4 -2
- beamlit/models/deployment_configuration.py +4 -2
- beamlit/models/deployment_configurations.py +22 -7
- beamlit/models/deployment_serverless_config.py +4 -2
- beamlit/models/deployment_serverless_config_type_0.py +220 -0
- beamlit/models/environment.py +9 -7
- beamlit/models/environment_metrics.py +26 -5
- beamlit/models/environment_spec.py +61 -0
- beamlit/models/flavor.py +11 -9
- beamlit/models/function.py +5 -3
- beamlit/models/function_configuration.py +4 -2
- beamlit/models/function_deployment.py +33 -20
- beamlit/models/function_deployment_configuration.py +4 -2
- beamlit/models/function_deployment_configuration_type_0.py +43 -0
- beamlit/models/function_deployment_pod_template.py +4 -2
- beamlit/models/function_deployment_pod_template_type_0.py +43 -0
- beamlit/models/function_kit.py +7 -5
- beamlit/models/function_metadata.py +144 -0
- beamlit/models/function_provider_ref.py +4 -2
- beamlit/models/function_release.py +4 -2
- beamlit/models/function_spec.py +246 -0
- beamlit/models/function_with_deployments.py +176 -0
- beamlit/models/get_workspace_service_accounts_response_200_item.py +4 -2
- beamlit/models/increase_and_rate_metric.py +104 -0
- beamlit/models/integration.py +198 -0
- beamlit/models/integration_config.py +45 -0
- beamlit/models/integration_connection.py +198 -0
- beamlit/models/integration_connection_config.py +45 -0
- beamlit/models/integration_connection_secret.py +61 -0
- beamlit/models/integration_connection_spec.py +99 -0
- beamlit/models/integration_model.py +144 -0
- beamlit/models/integration_secret.py +61 -0
- beamlit/models/invite_workspace_user_body.py +4 -2
- beamlit/models/labels_type_0.py +4 -2
- beamlit/models/location.py +7 -5
- beamlit/models/location_response.py +7 -5
- beamlit/models/metadata.py +135 -0
- beamlit/models/{labels.py → metadata_labels.py} +5 -5
- beamlit/models/metric.py +4 -2
- beamlit/models/metrics.py +68 -25
- beamlit/models/model.py +5 -3
- beamlit/models/model_deployment.py +27 -14
- beamlit/models/model_deployment_log.py +4 -2
- beamlit/models/model_deployment_metrics.py +11 -9
- beamlit/models/model_deployment_metrics_inference_per_second_per_region.py +7 -5
- beamlit/models/model_deployment_metrics_query_per_second_per_region_per_code.py +5 -3
- beamlit/models/model_deployment_pod_template.py +4 -2
- beamlit/models/model_deployment_pod_template_type_0.py +43 -0
- beamlit/models/model_metadata.py +144 -0
- beamlit/models/model_metrics.py +8 -6
- beamlit/models/model_provider.py +13 -11
- beamlit/models/model_provider_ref.py +4 -2
- beamlit/models/model_release.py +4 -2
- beamlit/models/model_spec.py +194 -0
- beamlit/models/model_with_deployments.py +8 -6
- beamlit/models/owner_fields.py +68 -0
- beamlit/models/pending_invitation.py +4 -2
- beamlit/models/pending_invitation_accept.py +5 -3
- beamlit/models/pending_invitation_render.py +7 -5
- beamlit/models/pending_invitation_render_invited_by.py +4 -2
- beamlit/models/pending_invitation_render_workspace.py +4 -2
- beamlit/models/pending_invitation_workspace_details.py +8 -6
- beamlit/models/pod_template_spec.py +43 -0
- beamlit/models/policy.py +22 -20
- beamlit/models/policy_location.py +11 -9
- beamlit/models/policy_spec.py +125 -0
- beamlit/models/provider_config.py +9 -16
- beamlit/models/qps.py +4 -2
- beamlit/models/resource_deployment_log.py +4 -2
- beamlit/models/resource_deployment_metrics.py +119 -9
- beamlit/models/resource_deployment_metrics_inference_per_region.py +77 -0
- beamlit/models/resource_deployment_metrics_inference_per_region_type_0.py +79 -0
- beamlit/models/resource_deployment_metrics_inference_per_second_per_region.py +7 -5
- beamlit/models/resource_deployment_metrics_inference_per_second_per_region_type_0.py +79 -0
- beamlit/models/resource_deployment_metrics_query_per_region_per_code.py +75 -0
- beamlit/models/resource_deployment_metrics_query_per_region_per_code_type_0.py +73 -0
- beamlit/models/resource_deployment_metrics_query_per_second_per_region_per_code.py +5 -3
- beamlit/models/resource_deployment_metrics_query_per_second_per_region_per_code_type_0.py +73 -0
- beamlit/models/resource_environment_metrics.py +210 -0
- beamlit/models/resource_environment_metrics_inference_per_second_per_region.py +79 -0
- beamlit/models/resource_environment_metrics_query_per_second_per_region_per_code.py +73 -0
- beamlit/models/resource_log.py +68 -0
- beamlit/models/resource_metrics.py +44 -6
- beamlit/models/runtime.py +25 -23
- beamlit/models/runtime_readiness_probe.py +4 -2
- beamlit/models/runtime_readiness_probe_type_0.py +43 -0
- beamlit/models/runtime_resources.py +4 -2
- beamlit/models/runtime_type_0.py +111 -0
- beamlit/models/runtime_type_0_readiness_probe.py +43 -0
- beamlit/models/runtime_type_0_readiness_probe_type_0.py +43 -0
- beamlit/models/runtime_type_0_resources.py +59 -0
- beamlit/models/serverless_config.py +4 -2
- beamlit/models/spec_configuration.py +68 -0
- beamlit/models/standard_fields_dynamo_db.py +4 -2
- beamlit/models/store_agent.py +8 -6
- beamlit/models/store_agent_configuration.py +4 -2
- beamlit/models/store_agent_labels.py +4 -2
- beamlit/models/store_agent_labels_type_0.py +43 -0
- beamlit/models/store_configuration.py +18 -16
- beamlit/models/store_configuration_option.py +4 -2
- beamlit/models/store_function.py +14 -12
- beamlit/models/store_function_configuration.py +4 -2
- beamlit/models/store_function_kit.py +7 -5
- beamlit/models/store_function_labels.py +4 -2
- beamlit/models/store_function_labels_type_0.py +43 -0
- beamlit/models/store_function_parameter.py +11 -9
- beamlit/models/time_fields.py +68 -0
- beamlit/models/update_workspace_service_account_body.py +4 -2
- beamlit/models/update_workspace_service_account_response_200.py +4 -2
- beamlit/models/update_workspace_user_role_body.py +4 -2
- beamlit/models/websocket_channel.py +86 -0
- beamlit/models/workspace.py +5 -3
- beamlit/models/workspace_labels.py +4 -2
- beamlit/models/workspace_user.py +4 -2
- beamlit/run.py +49 -0
- beamlit/serve/app.py +78 -0
- beamlit/serve/middlewares/__init__.py +4 -0
- beamlit/serve/middlewares/accesslog.py +14 -0
- beamlit/serve/middlewares/processtime.py +12 -0
- {beamlit-0.0.19.dist-info → beamlit-0.0.20.dist-info}/METADATA +11 -2
- beamlit-0.0.20.dist-info/RECORD +301 -0
- beamlit-0.0.19.dist-info/RECORD +0 -211
- /beamlit/api/{authentication_providers → integrations}/__init__.py +0 -0
- {beamlit-0.0.19.dist-info → beamlit-0.0.20.dist-info}/WHEEL +0 -0
@@ -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
|
beamlit/common/utils.py
ADDED
@@ -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,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,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,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,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,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
|
beamlit/models/__init__.py
CHANGED
@@ -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,
|
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:
|
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,
|
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[
|
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:
|
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
|
|
beamlit/models/agent_chain.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Any,
|
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:
|
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,
|
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:
|
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
|
|