beamlit 0.0.24rc20__py3-none-any.whl → 0.0.24rc21__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. beamlit/agents/chat.py +37 -11
  2. beamlit/agents/decorator.py +97 -65
  3. beamlit/api/agents/create_agent.py +9 -14
  4. beamlit/api/agents/delete_agent.py +22 -1
  5. beamlit/api/agents/delete_agent_history.py +2 -6
  6. beamlit/api/agents/get_agent.py +22 -1
  7. beamlit/api/agents/get_agent_environment_logs.py +11 -11
  8. beamlit/api/agents/get_agent_history.py +2 -6
  9. beamlit/api/agents/get_agent_metrics.py +22 -1
  10. beamlit/api/agents/list_agent_history.py +11 -11
  11. beamlit/api/agents/list_agents.py +36 -4
  12. beamlit/api/agents/put_agent_history.py +2 -6
  13. beamlit/api/agents/update_agent.py +9 -14
  14. beamlit/api/functions/create_function.py +9 -14
  15. beamlit/api/functions/delete_function.py +22 -1
  16. beamlit/api/functions/get_function.py +22 -1
  17. beamlit/api/functions/get_function_environment_logs.py +11 -11
  18. beamlit/api/functions/get_function_metrics.py +22 -1
  19. beamlit/api/functions/list_functions.py +36 -4
  20. beamlit/api/functions/update_function.py +9 -14
  21. beamlit/api/history/get_agents_history.py +12 -12
  22. beamlit/api/history/list_agents_history.py +12 -12
  23. beamlit/api/integrations/get_integration_connection.py +16 -12
  24. beamlit/api/integrations/get_integration_connection_model.py +8 -1
  25. beamlit/api/integrations/get_integration_model.py +8 -1
  26. beamlit/api/locations/list_locations.py +12 -12
  27. beamlit/api/models/create_model.py +13 -14
  28. beamlit/api/models/delete_model.py +22 -1
  29. beamlit/api/models/get_model.py +22 -1
  30. beamlit/api/models/get_model_environment_logs.py +11 -11
  31. beamlit/api/models/get_model_metrics.py +38 -13
  32. beamlit/api/models/list_models.py +36 -4
  33. beamlit/api/models/update_model.py +13 -14
  34. beamlit/api/privateclusters/__init__.py +0 -0
  35. beamlit/api/{agents/get_agent_deployment_metrics.py → privateclusters/create_private_cluster.py} +28 -55
  36. beamlit/api/{functions/list_function_deployments.py → privateclusters/delete_private_cluster.py} +38 -37
  37. beamlit/api/{agents/get_agent_deployment.py → privateclusters/get_private_cluster.py} +40 -44
  38. beamlit/api/privateclusters/get_private_cluster_health.py +97 -0
  39. beamlit/api/{agents/list_agent_deployments.py → privateclusters/list_private_clusters.py} +30 -45
  40. beamlit/api/{models/list_model_deployments.py → privateclusters/update_private_cluster.py} +38 -45
  41. beamlit/api/privateclusters/update_private_cluster_health.py +97 -0
  42. beamlit/authentication/device_mode.py +3 -9
  43. beamlit/common/generate.py +47 -34
  44. beamlit/common/settings.py +29 -27
  45. beamlit/deploy/deploy.py +101 -342
  46. beamlit/deploy/format.py +70 -0
  47. beamlit/deploy/parser.py +175 -0
  48. beamlit/functions/decorator.py +8 -11
  49. beamlit/models/__init__.py +64 -78
  50. beamlit/models/acl.py +4 -22
  51. beamlit/models/agent.py +34 -95
  52. beamlit/models/agent_history.py +7 -5
  53. beamlit/models/agent_history_event.py +11 -9
  54. beamlit/models/agent_metadata.py +5 -3
  55. beamlit/models/agent_spec.py +54 -45
  56. beamlit/models/api_key.py +14 -14
  57. beamlit/models/configuration.py +11 -0
  58. beamlit/models/core_spec.py +45 -32
  59. beamlit/models/{model_deployment_metrics_query_per_second_per_region_per_code.py → core_spec_configurations.py} +22 -22
  60. beamlit/models/environment.py +33 -105
  61. beamlit/models/environment_metadata.py +146 -0
  62. beamlit/models/environment_spec.py +8 -6
  63. beamlit/models/function.py +34 -95
  64. beamlit/models/function_metadata.py +5 -3
  65. beamlit/models/function_spec.py +53 -40
  66. beamlit/models/integration_connection.py +31 -137
  67. beamlit/models/integration_connection_spec.py +6 -4
  68. beamlit/models/metadata.py +5 -3
  69. beamlit/models/metadata_labels.py +4 -2
  70. beamlit/models/model.py +33 -94
  71. beamlit/models/model_metadata.py +5 -3
  72. beamlit/models/{function_provider_ref.py → model_private_cluster.py} +23 -14
  73. beamlit/models/model_provider.py +27 -43
  74. beamlit/models/model_spec.py +45 -32
  75. beamlit/models/owner_fields.py +4 -2
  76. beamlit/models/pending_invitation.py +14 -14
  77. beamlit/models/pod_template_spec.py +4 -2
  78. beamlit/models/policy.py +33 -159
  79. beamlit/models/policy_spec.py +24 -28
  80. beamlit/models/private_cluster.py +183 -0
  81. beamlit/models/{model_provider_ref.py → private_location.py} +7 -16
  82. beamlit/models/resource_deployment_metrics.py +0 -108
  83. beamlit/models/resource_environment_metrics.py +143 -71
  84. beamlit/models/{resource_deployment_metrics_inference_per_region.py → resource_environment_metrics_inference_per_region.py} +5 -5
  85. beamlit/models/resource_environment_metrics_inference_per_second_per_region.py +9 -11
  86. beamlit/models/{resource_deployment_metrics_query_per_region_per_code.py → resource_environment_metrics_query_per_region_per_code.py} +5 -5
  87. beamlit/models/resource_environment_metrics_query_per_second_per_region_per_code.py +5 -3
  88. beamlit/models/resource_log.py +4 -2
  89. beamlit/models/runtime.py +20 -2
  90. beamlit/models/serverless_config.py +28 -21
  91. beamlit/models/spec_configuration.py +7 -5
  92. beamlit/models/store_agent.py +14 -14
  93. beamlit/models/store_function.py +14 -14
  94. beamlit/models/time_fields.py +4 -2
  95. beamlit/models/websocket_channel.py +4 -2
  96. beamlit/models/workspace.py +23 -14
  97. beamlit/run.py +0 -1
  98. beamlit/serve/app.py +1 -0
  99. beamlit/serve/middlewares/accesslog.py +3 -1
  100. {beamlit-0.0.24rc20.dist-info → beamlit-0.0.24rc21.dist-info}/METADATA +1 -1
  101. beamlit-0.0.24rc21.dist-info/RECORD +243 -0
  102. beamlit/api/agents/delete_agent_deployment.py +0 -163
  103. beamlit/api/agents/delete_agent_deployment_history.py +0 -172
  104. beamlit/api/agents/get_agent_deployment_history.py +0 -172
  105. beamlit/api/agents/get_agent_deployment_logs.py +0 -164
  106. beamlit/api/agents/list_agent_deployment_history.py +0 -164
  107. beamlit/api/agents/put_agent_deployment.py +0 -185
  108. beamlit/api/agents/put_agent_deployment_history.py +0 -198
  109. beamlit/api/functions/delete_function_deployment.py +0 -163
  110. beamlit/api/functions/get_function_deployment.py +0 -163
  111. beamlit/api/functions/get_function_deployment_logs.py +0 -164
  112. beamlit/api/functions/get_function_deployment_metrics.py +0 -159
  113. beamlit/api/functions/put_function_deployment.py +0 -185
  114. beamlit/api/models/delete_model_deployment.py +0 -171
  115. beamlit/api/models/get_model_deployment.py +0 -171
  116. beamlit/api/models/get_model_deployment_logs.py +0 -168
  117. beamlit/api/models/get_model_deployment_metrics.py +0 -163
  118. beamlit/api/models/put_model_deployment.py +0 -193
  119. beamlit/models/agent_configuration.py +0 -70
  120. beamlit/models/agent_deployment.py +0 -340
  121. beamlit/models/agent_deployment_configuration.py +0 -45
  122. beamlit/models/agent_deployment_configuration_type_0.py +0 -43
  123. beamlit/models/agent_deployment_history.py +0 -185
  124. beamlit/models/agent_deployment_history_event.py +0 -133
  125. beamlit/models/agent_deployment_pod_template.py +0 -45
  126. beamlit/models/agent_deployment_pod_template_type_0.py +0 -43
  127. beamlit/models/agent_with_deployments.py +0 -176
  128. beamlit/models/authentication_provider_model.py +0 -144
  129. beamlit/models/authentication_provider_organization.py +0 -88
  130. beamlit/models/deployment_configuration.py +0 -70
  131. beamlit/models/deployment_configurations.py +0 -58
  132. beamlit/models/deployment_serverless_config.py +0 -131
  133. beamlit/models/deployment_serverless_config_type_0.py +0 -220
  134. beamlit/models/function_configuration.py +0 -70
  135. beamlit/models/function_deployment.py +0 -340
  136. beamlit/models/function_deployment_configuration.py +0 -45
  137. beamlit/models/function_deployment_configuration_type_0.py +0 -43
  138. beamlit/models/function_deployment_pod_template.py +0 -45
  139. beamlit/models/function_deployment_pod_template_type_0.py +0 -43
  140. beamlit/models/function_with_deployments.py +0 -176
  141. beamlit/models/integration.py +0 -198
  142. beamlit/models/integration_config.py +0 -45
  143. beamlit/models/integration_secret.py +0 -61
  144. beamlit/models/labels_type_0.py +0 -45
  145. beamlit/models/location.py +0 -122
  146. beamlit/models/model_deployment.py +0 -296
  147. beamlit/models/model_deployment_log.py +0 -70
  148. beamlit/models/model_deployment_metrics.py +0 -172
  149. beamlit/models/model_deployment_metrics_inference_per_second_per_region.py +0 -77
  150. beamlit/models/model_deployment_pod_template.py +0 -45
  151. beamlit/models/model_deployment_pod_template_type_0.py +0 -43
  152. beamlit/models/model_metrics.py +0 -96
  153. beamlit/models/model_with_deployments.py +0 -176
  154. beamlit/models/resource_deployment_log.py +0 -70
  155. beamlit/models/resource_deployment_metrics_inference_per_region_type_0.py +0 -79
  156. beamlit/models/resource_deployment_metrics_inference_per_second_per_region_type_0.py +0 -79
  157. beamlit/models/resource_deployment_metrics_query_per_region_per_code_type_0.py +0 -73
  158. beamlit/models/resource_deployment_metrics_query_per_second_per_region_per_code_type_0.py +0 -73
  159. beamlit/models/runtime_readiness_probe_type_0.py +0 -43
  160. beamlit/models/runtime_type_0.py +0 -111
  161. beamlit/models/runtime_type_0_readiness_probe.py +0 -43
  162. beamlit/models/runtime_type_0_readiness_probe_type_0.py +0 -43
  163. beamlit/models/runtime_type_0_resources.py +0 -59
  164. beamlit/models/standard_fields_dynamo_db.py +0 -88
  165. beamlit/models/store_agent_configuration.py +0 -97
  166. beamlit/models/store_agent_labels_type_0.py +0 -43
  167. beamlit/models/store_function_configuration.py +0 -97
  168. beamlit/models/store_function_labels_type_0.py +0 -43
  169. beamlit-0.0.24rc20.dist-info/RECORD +0 -303
  170. {beamlit-0.0.24rc20.dist-info → beamlit-0.0.24rc21.dist-info}/WHEEL +0 -0
@@ -1,8 +1,7 @@
1
1
  from typing import Tuple
2
2
 
3
3
  from beamlit.common.settings import Settings, get_settings
4
- from beamlit.models.agent_deployment import AgentDeployment
5
- from beamlit.models.function_deployment import FunctionDeployment
4
+ from beamlit.models import Agent, Function, FunctionMetadata, FunctionSpec
6
5
  from beamlit.models.function_kit import FunctionKit
7
6
 
8
7
 
@@ -10,55 +9,67 @@ def get_titles_name(name: str) -> str:
10
9
  return name.title().replace("-", "").replace("_", "")
11
10
 
12
11
 
13
- def generate_kit_function_code(settings: Settings, function: FunctionDeployment, kit: FunctionKit) -> Tuple[str, str]:
12
+ def generate_kit_function_code(
13
+ settings: Settings, function: Function, kit: FunctionKit
14
+ ) -> Tuple[str, str]:
14
15
  export_code = ""
15
16
  code = ""
16
17
  for kit in kit:
17
- fn = FunctionDeployment(
18
- function=kit.name,
19
- workspace=settings.workspace,
20
- parameters=kit.parameters,
21
- description=kit.description,
18
+ fn = Function(
19
+ metadata=FunctionMetadata(
20
+ name=kit.name,
21
+ workspace=settings.workspace,
22
+ environment=settings.environment,
23
+ ),
24
+ spec=FunctionSpec(
25
+ parameters=kit.parameters,
26
+ description=kit.description,
27
+ ),
28
+ )
29
+ new_code, export = generate_function_code(
30
+ settings, fn, force_name_in_endpoint=function.metadata.name, kit=True
22
31
  )
23
- new_code, export = generate_function_code(settings, fn, force_name_in_endpoint=function.function, kit=True)
24
32
  code += new_code
25
33
  export_code += export
26
34
  return code, export_code
27
35
 
28
36
 
29
37
  def generate_function_code(
30
- settings: Settings, function: FunctionDeployment, force_name_in_endpoint: str = "", kit: bool = False
38
+ settings: Settings,
39
+ function: Function,
40
+ force_name_in_endpoint: str = "",
41
+ kit: bool = False,
31
42
  ) -> Tuple[str, str]:
32
- name = get_titles_name(function.function)
33
- if function.parameters and len(function.parameters) > 0:
34
- args_list = ", ".join(f"{param.name}: str" for param in function.parameters)
43
+ name = get_titles_name(function.metadata.name)
44
+ if function.spec.parameters and len(function.spec.parameters) > 0:
45
+ args_list = ", ".join(f"{param.name}: str" for param in function.spec.parameters)
35
46
  args_list += ", "
36
47
  else:
37
48
  args_list = ""
38
49
  args_schema = ""
39
- if function.parameters:
40
- for param in function.parameters:
50
+ if function.spec.parameters:
51
+ for param in function.spec.parameters:
41
52
  args_schema += f'{param.name}: str = Field(description="""{param.description}""")\n '
42
53
  if len(args_schema) == 0:
43
54
  args_schema = "pass"
44
55
 
45
56
  # TODO: add return direct in function configuration
46
57
  return_direct = False
47
- endpoint_name = force_name_in_endpoint or function.function
58
+ endpoint_name = force_name_in_endpoint or function.metadata.name
48
59
  body = "{}"
49
- if function.parameters:
50
- body = f'{", ".join(f'"{param.name}": {param.name}' for param in function.parameters)}'
60
+ if function.spec.parameters:
61
+ body = f'{", ".join(f'"{param.name}": {param.name}' for param in function.spec.parameters)}'
51
62
  if kit is True:
52
63
  has_name = False
53
- if function.parameters:
54
- for param in function.parameters:
64
+ if function.spec.parameters:
65
+ for param in function.spec.parameters:
55
66
  if param.name == "name":
56
67
  has_name = True
57
68
  break
58
69
  if not has_name:
59
70
  if len(body) > 0:
60
71
  body += ", "
61
- body += f'"name": "{function.function}"'
72
+ body += f'"name": "{function.metadata.name}"'
62
73
  return (
63
74
  f'''
64
75
 
@@ -66,8 +77,8 @@ class Beamlit{name}Input(BaseModel):
66
77
  {args_schema}
67
78
 
68
79
  class Beamlit{name}(BaseTool):
69
- name: str = "beamlit_{function.function.replace("-", "_")}"
70
- description: str = """{function.description}"""
80
+ name: str = "beamlit_{function.metadata.name.replace("-", "_")}"
81
+ description: str = """{function.spec.description}"""
71
82
  args_schema: Type[BaseModel] = Beamlit{name}Input
72
83
 
73
84
  response_format: Literal["content_and_artifact"] = "content_and_artifact"
@@ -84,22 +95,22 @@ class Beamlit{name}(BaseTool):
84
95
  except Exception as e:
85
96
  return repr(e), {{}}
86
97
  ''',
87
- f"Beamlit{get_titles_name(function.function)},",
98
+ f"Beamlit{get_titles_name(function.metadata.name)},",
88
99
  )
89
100
 
90
101
 
91
- def generate_chain_code(settings: Settings, agent: AgentDeployment) -> Tuple[str, str]:
92
- name = get_titles_name(agent.agent)
102
+ def generate_chain_code(settings: Settings, agent: Agent) -> Tuple[str, str]:
103
+ name = get_titles_name(agent.metadata.name)
93
104
  # TODO: add return direct in agent configuration
94
105
  return_direct = False
95
106
  return (
96
107
  f'''
97
108
  class BeamlitChain{name}Input(BaseModel):
98
- input: str = Field(description='{agent.description}')
109
+ input: str = Field(description='{agent.spec.description}')
99
110
 
100
111
  class BeamlitChain{name}(BaseTool):
101
- name: str = "beamlit_chain_{agent.agent.replace("-", "_")}"
102
- description: str = """{agent.description}"""
112
+ name: str = "beamlit_chain_{agent.metadata.name.replace("-", "_")}"
113
+ description: str = """{agent.spec.description}"""
103
114
  args_schema: Type[BaseModel] = BeamlitChain{name}Input
104
115
 
105
116
  response_format: Literal["content_and_artifact"] = "content_and_artifact"
@@ -112,10 +123,10 @@ class BeamlitChain{name}(BaseTool):
112
123
  ) -> Tuple[Union[List[Dict[str, str]], str], Dict]:
113
124
  try:
114
125
  params = self.metadata.get("params", {{}})
115
- response = run_client.run("agent", "{agent.agent}", settings.environment, "POST", json={{"input": input}})
126
+ response = run_client.run("agent", "{agent.metadata.name}", settings.environment, "POST", json={{"input": input}})
116
127
  if response.status_code >= 400:
117
- logger.error(f"Failed to run tool {agent.agent}, {{response.status_code}}::{{response.text}}")
118
- raise Exception(f"Failed to run tool {agent.agent}, {{response.status_code}}::{{response.text}}")
128
+ logger.error(f"Failed to run tool {agent.metadata.name}, {{response.status_code}}::{{response.text}}")
129
+ raise Exception(f"Failed to run tool {agent.metadata.name}, {{response.status_code}}::{{response.text}}")
119
130
  if response.headers.get("Content-Type") == "application/json":
120
131
  return response.json(), {{}}
121
132
  else:
@@ -157,8 +168,10 @@ run_client = RunClient(client=client)
157
168
  code = imports
158
169
  if settings.agent.functions and len(settings.agent.functions) > 0:
159
170
  for function_config in settings.agent.functions:
160
- if function_config.kit and len(function_config.kit) > 0:
161
- new_code, export = generate_kit_function_code(settings, function_config, function_config.kit)
171
+ if function_config.spec.kit and len(function_config.spec.kit) > 0:
172
+ new_code, export = generate_kit_function_code(
173
+ settings, function_config, function_config.spec.kit
174
+ )
162
175
  code += new_code
163
176
  export_code += export
164
177
  else:
@@ -1,14 +1,13 @@
1
1
  import os
2
2
  from logging import getLogger
3
- from typing import List, Tuple, Type, Union
3
+ from typing import Tuple, Type, Union
4
4
 
5
- from beamlit.api.functions import get_function_deployment
6
- from beamlit.api.models import get_model_deployment
5
+ from beamlit.api.agents import get_agent
6
+ from beamlit.api.functions import get_function
7
+ from beamlit.api.models import get_model
7
8
  from beamlit.client import AuthenticatedClient
8
9
  from beamlit.common.logger import init as init_logger
9
- from beamlit.models.agent_deployment import AgentDeployment
10
- from beamlit.models.function_deployment import FunctionDeployment
11
- from beamlit.models.model_deployment import ModelDeployment
10
+ from beamlit.models import Agent, Function, Model
12
11
  from beamlit.types import UNSET, Unset
13
12
  from langchain_core.language_models.chat_models import BaseChatModel
14
13
  from langgraph.graph.graph import CompiledGraph
@@ -26,9 +25,9 @@ def get_settings():
26
25
 
27
26
  class SettingsAgent(BaseSettings):
28
27
  agent: Union[None, CompiledGraph, BaseChatModel] = None
29
- chain: Union[Unset, List[AgentDeployment]] = UNSET
30
- model: Union[Unset, ModelDeployment] = UNSET
31
- functions: Union[Unset, List[FunctionDeployment]] = UNSET
28
+ chain: Union[Unset, list[Agent]] = UNSET
29
+ model: Union[Unset, Model] = UNSET
30
+ functions: Union[Unset, list[Function]] = UNSET
32
31
  functions_directory: str = Field(default="src/functions")
33
32
  chat_model: Union[None, BaseChatModel] = None
34
33
  module: str = Field(default="main.main")
@@ -106,26 +105,29 @@ def init_agent(
106
105
  name = settings.name
107
106
  env = settings.environment
108
107
 
109
- agent_deployment = get_agent_deployment.sync(name, env, client=client)
110
- function_deployments = []
111
- agent_chain_deployments = []
112
- if agent_deployment.functions:
113
- for function in agent_deployment.functions:
114
- function_deployment = get_function_deployment.sync(function, env, client=client)
115
- function_deployments.append(function_deployment)
116
- settings.agent.functions = function_deployments
117
-
118
- if agent_deployment.agent_chain:
119
- for chain in agent_deployment.agent_chain:
108
+ agent = get_agent.sync(name, environment=env, client=client)
109
+ if not agent:
110
+ raise ValueError(f"Agent {name} not found")
111
+ functions: list[Function] = []
112
+ agents_chain: list[Agent] = []
113
+ if agent.spec.functions:
114
+ for function in agent.spec.functions:
115
+ function = get_function.sync(function, environment=env, client=client)
116
+ if function:
117
+ functions.append(function)
118
+ settings.agent.functions = functions
119
+
120
+ if agent.spec.agent_chain:
121
+ for chain in agent.spec.agent_chain:
120
122
  if chain.enabled:
121
- agent_deployment = get_agent_deployment.sync(chain.name, env, client=client)
123
+ agent_chain = get_agent.sync(chain.name, environment=env, client=client)
122
124
  if chain.description:
123
- agent_deployment.description = chain.description
124
- agent_chain_deployments.append(agent_deployment)
125
- settings.agent.chain = agent_chain_deployments
126
- if agent_deployment.model:
127
- model_deployment = get_model_deployment.sync(agent_deployment.model, env, client=client)
128
- settings.agent.model = model_deployment
125
+ agent_chain.spec.description = chain.description
126
+ agents_chain.append(agent_chain)
127
+ settings.agent.chain = agents_chain
128
+ if agent.spec.model:
129
+ model = get_model.sync(agent.spec.model, environment=env, client=client)
130
+ settings.agent.model = model
129
131
 
130
132
  content_generate = generate(destination, dry_run=True)
131
133
  compared_content = None