dao-ai 0.1.8__py3-none-any.whl → 0.1.10__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.
@@ -0,0 +1,24 @@
1
+ """
2
+ Databricks Apps deployment module for dao-ai.
3
+
4
+ This subpackage contains all modules related to deploying dao-ai agents
5
+ as Databricks Apps or Model Serving endpoints.
6
+
7
+ Modules:
8
+ handlers: MLflow AgentServer request handlers (@invoke, @stream)
9
+ server: Entry point for Databricks Apps deployment
10
+ resources: Databricks App resource configuration generation
11
+ model_serving: Entry point for Databricks Model Serving deployment
12
+ """
13
+
14
+ from dao_ai.apps.resources import (
15
+ generate_app_resources,
16
+ generate_app_yaml,
17
+ generate_sdk_resources,
18
+ )
19
+
20
+ __all__ = [
21
+ "generate_app_resources",
22
+ "generate_app_yaml",
23
+ "generate_sdk_resources",
24
+ ]
@@ -0,0 +1,84 @@
1
+ """
2
+ Agent request handlers for MLflow AgentServer.
3
+
4
+ This module defines the invoke and stream handlers that are registered
5
+ with the MLflow AgentServer. These handlers delegate to the ResponsesAgent
6
+ created from the dao-ai configuration.
7
+
8
+ The handlers use async methods (apredict, apredict_stream) to be compatible
9
+ with both Databricks Model Serving and Databricks Apps environments.
10
+ """
11
+
12
+ import os
13
+ from typing import AsyncGenerator
14
+
15
+ import mlflow
16
+ from dotenv import load_dotenv
17
+ from mlflow.genai.agent_server import invoke, stream
18
+ from mlflow.types.responses import (
19
+ ResponsesAgentRequest,
20
+ ResponsesAgentResponse,
21
+ ResponsesAgentStreamEvent,
22
+ )
23
+
24
+ from dao_ai.config import AppConfig
25
+ from dao_ai.logging import configure_logging
26
+ from dao_ai.models import LanggraphResponsesAgent
27
+
28
+ # Load environment variables from .env.local if it exists
29
+ load_dotenv(dotenv_path=".env.local", override=True)
30
+
31
+ # Configure MLflow
32
+ mlflow.set_registry_uri("databricks-uc")
33
+ mlflow.set_tracking_uri("databricks")
34
+ mlflow.langchain.autolog()
35
+
36
+ # Get config path from environment or use default
37
+ config_path: str = os.environ.get("DAO_AI_CONFIG_PATH", "model_config.yaml")
38
+
39
+ # Load configuration using AppConfig.from_file (consistent with CLI, notebook, builder)
40
+ config: AppConfig = AppConfig.from_file(config_path)
41
+
42
+ # Configure logging
43
+ if config.app and config.app.log_level:
44
+ configure_logging(level=config.app.log_level)
45
+
46
+ # Create the ResponsesAgent - cast to LanggraphResponsesAgent to access async methods
47
+ _responses_agent: LanggraphResponsesAgent = config.as_responses_agent() # type: ignore[assignment]
48
+
49
+
50
+ @invoke()
51
+ async def non_streaming(request: ResponsesAgentRequest) -> ResponsesAgentResponse:
52
+ """
53
+ Handle non-streaming requests by delegating to the ResponsesAgent.
54
+
55
+ Uses the async apredict() method for compatibility with both
56
+ Model Serving and Apps environments.
57
+
58
+ Args:
59
+ request: The incoming ResponsesAgentRequest
60
+
61
+ Returns:
62
+ ResponsesAgentResponse with the complete output
63
+ """
64
+ return await _responses_agent.apredict(request)
65
+
66
+
67
+ @stream()
68
+ async def streaming(
69
+ request: ResponsesAgentRequest,
70
+ ) -> AsyncGenerator[ResponsesAgentStreamEvent, None]:
71
+ """
72
+ Handle streaming requests by delegating to the ResponsesAgent.
73
+
74
+ Uses the async apredict_stream() method for compatibility with both
75
+ Model Serving and Apps environments.
76
+
77
+ Args:
78
+ request: The incoming ResponsesAgentRequest
79
+
80
+ Yields:
81
+ ResponsesAgentStreamEvent objects as they are generated
82
+ """
83
+ async for event in _responses_agent.apredict_stream(request):
84
+ yield event
@@ -0,0 +1,29 @@
1
+ # Apply nest_asyncio FIRST before any other imports
2
+ # This allows dao-ai's async/sync patterns to work in Model Serving
3
+ # where there may already be an event loop running (e.g., notebook context)
4
+ import nest_asyncio
5
+
6
+ nest_asyncio.apply()
7
+
8
+ import mlflow # noqa: E402
9
+ from mlflow.models import ModelConfig # noqa: E402
10
+ from mlflow.pyfunc import ResponsesAgent # noqa: E402
11
+
12
+ from dao_ai.config import AppConfig # noqa: E402
13
+ from dao_ai.logging import configure_logging # noqa: E402
14
+
15
+ mlflow.set_registry_uri("databricks-uc")
16
+ mlflow.set_tracking_uri("databricks")
17
+
18
+ mlflow.langchain.autolog()
19
+
20
+ model_config: ModelConfig = ModelConfig()
21
+ config: AppConfig = AppConfig(**model_config.to_dict())
22
+
23
+ log_level: str = config.app.log_level
24
+
25
+ configure_logging(level=log_level)
26
+
27
+ app: ResponsesAgent = config.as_responses_agent()
28
+
29
+ mlflow.models.set_model(app)