Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.
Python aiburrchatbot-frameworkdagsgenerative-aigraphshacktoberfestllmopsllmsmlopspersistent-data-structurestate-machinestate-managementvisibility
Adds partition key to Burr URL
elijahbenizzy641e2d7e0bb4
diff --git a/burr/tracking/server/backend.py b/burr/tracking/server/backend.pyindex e017b43e..4beccdc0 100644--- a/burr/tracking/server/backend.py+++ b/burr/tracking/server/backend.py@@ -106,20 +106,21 @@ class BackendBase(abc.ABC):@abc.abstractmethodasync def list_apps(- self, request: fastapi.Request, project_id: str+ self, request: fastapi.Request, project_id: str, partition_key: Optional[str]) -> Sequence[schema.ApplicationSummary]:"""Lists out all apps (continual state machine runs with shared state) for a given project.:param request: The request object, used for authentication/authorization if needed- :param project_id:- :return:+ :param project_id: filter by project id+ :param partition_key: filter by partition key+ :return: A list of apps"""pass@abc.abstractmethodasync def get_application_logs(- self, request: fastapi.Request, project_id: str, app_id: str- ) -> Sequence[schema.Step]:+ self, request: fastapi.Request, project_id: str, app_id: str, partition_key: Optional[str]+ ) -> ApplicationLogs:"""Lists out all steps for a given app.:param request: The request object, used for authentication/authorization if needed@@ -228,7 +229,7 @@ class LocalBackend(BackendBase):return models.ApplicationMetadataModel()async def list_apps(- self, request: fastapi.Request, project_id: str+ self, request: fastapi.Request, project_id: str, partition_key: Optional[str]) -> Sequence[ApplicationSummary]:project_filepath = os.path.join(self.path, project_id)if not os.path.exists(project_filepath):@@ -244,6 +245,13 @@ class LocalBackend(BackendBase):log_path = os.path.join(full_path, "log.jsonl")if os.path.isdir(full_path):metadata = await self._load_metadata(metadata_path)+ app_partition_key = metadata.partition_key+ # quick, hacky way to do it -- we should really have this be part of the path+ # But we load it up anyway. TODO -- add partition key to the path+ # If this is slow you'll want to use the s3-based storage system+ # Which has an actual index+ if partition_key is not None and partition_key != app_partition_key:+ continueout.append(schema.ApplicationSummary(app_id=entry,@@ -259,8 +267,10 @@ class LocalBackend(BackendBase):return outasync def get_application_logs(- self, request: fastapi.Request, project_id: str, app_id: str+ self, request: fastapi.Request, project_id: str, app_id: str, partition_key: Optional[str]) -> ApplicationLogs:+ # TODO -- handle partition key here+ # This currently assumes uniquenessapp_filepath = os.path.join(self.path, project_id, app_id)if not os.path.exists(app_filepath):raise fastapi.HTTPException(diff --git a/burr/tracking/server/run.py b/burr/tracking/server/run.pyindex bde037a5..3020dbf9 100644--- a/burr/tracking/server/run.py+++ b/burr/tracking/server/run.py@@ -52,6 +52,8 @@ except ImportError as e:SERVE_STATIC = os.getenv("BURR_SERVE_STATIC", "true").lower() == "true"+SENTINEL_PARTITION_KEY = "__none__"+backend = BackendBase.create_from_env()@@ -156,19 +158,27 @@ async def get_projects(request: Request) -> Sequence[schema.Project]:return await backend.list_projects(request)[email protected]("/api/v0/{project_id}/apps", response_model=Sequence[schema.ApplicationSummary])-async def get_apps(request: Request, project_id: str) -> Sequence[schema.ApplicationSummary]:+ "/api/v0/{project_id}/{partition_key}/apps", response_model=Sequence[schema.ApplicationSummary]+)+async def get_apps(+ request: Request, project_id: str, partition_key: str+) -> Sequence[schema.ApplicationSummary]:"""Gets all apps visible by the user:param request: FastAPI request:param project_id: project name:return: a list of projects visible by the user"""- return await backend.list_apps(request, project_id)+ if partition_key == SENTINEL_PARTITION_KEY:+ partition_key = None+ return await backend.list_apps(request, project_id, partition_key=partition_key)[email protected]("/api/v0/{project_id}/{app_id}/apps")-async def get_application_logs(request: Request, project_id: str, app_id: str) -> ApplicationLogs:[email protected]("/api/v0/{project_id}/{app_id}/{partition_key}/apps")+async def get_application_logs(+ request: Request, project_id: str, app_id: str, partition_key: str+) -> ApplicationLogs:"""Lists steps for a given App.TODO: add streaming capabilities for bi-directional communicationTODO: add pagination for quicker loading@@ -178,7 +188,11 @@ async def get_application_logs(request: Request, project_id: str, app_id: str) -:param app_id: ID of the assIndociated application:return: A list of steps with all associated step data"""- return await backend.get_application_logs(request, project_id=project_id, app_id=app_id)+ if partition_key == SENTINEL_PARTITION_KEY:+ partition_key = None+ return await backend.get_application_logs(+ request, project_id=project_id, app_id=app_id, partition_key=partition_key+ )@app.get("/api/v0/ready")diff --git a/burr/tracking/server/s3/backend.py b/burr/tracking/server/s3/backend.pyindex 7f21a57a..41fe847e 100644--- a/burr/tracking/server/s3/backend.py+++ b/burr/tracking/server/s3/backend.py@@ -542,13 +542,24 @@ class SQLiteS3Backend(BackendBase, IndexingBackendMixin, SnapshottingBackendMixireturn outasync def list_apps(- self, request: fastapi.Request, project_id: str, limit: int = 100, offset: int = 0+ self,+ request: fastapi.Request,+ project_id: str,+ partition_key: Optional[str],+ limit: int = 100,+ offset: int = 0,) -> Sequence[schema.ApplicationSummary]:# TODO -- distinctify between project name and project ID# Currently they're the same in the UI but we'll want to have them decoupled+ app_query = (+ Application.filter(project__name=project_id)+ if partition_key is None+ else Application.filter(project__name=project_id, partition_key=partition_key)+ )+applications = (- await Application.filter(project__name=project_id)- .annotate(+ # Sentinel value for partition_key is __none__ -- passing it in required makes querying easier+ await app_query.annotate(latest_logfile_created_at=functions.Max("log_files__created_at"),logfile_count=functions.Max("log_files__max_sequence_id"),)@@ -577,10 +588,17 @@ class SQLiteS3Backend(BackendBase, IndexingBackendMixin, SnapshottingBackendMixireturn outasync def get_application_logs(- self, request: fastapi.Request, project_id: str, app_id: str+ self, request: fastapi.Request, project_id: str, app_id: str, partition_key: str) -> ApplicationLogs:# TODO -- handle partition keys- applications = await Application.filter(name=app_id, project__name=project_id).all()+ query = (+ Application.filter(name=app_id, project__name=project_id)+ if partition_key is None+ else Application.filter(+ name=app_id, project__name=project_id, partition_key=partition_key+ )+ )+ applications = await query.all()application = applications[0]application_logs = await LogFile.filter(application__id=application.id).order_by("-created_at"diff --git a/telemetry/ui/src/App.tsx b/telemetry/ui/src/App.tsxindex 3f08361e..905b0f18 100644--- a/telemetry/ui/src/App.tsx+++ b/telemetry/ui/src/App.tsx@@ -35,7 +35,8 @@ const App = () => {<Route path="/" element={<Navigate to="/projects" />} /><Route path="/projects" element={<ProjectList />} /><Route path="/project/:projectId" element={<AppList />} />- <Route path="/project/:projectId/:appId" element={<AppViewContainer />} />+ <Route path="/project/:projectId/:partitionKey" element={<AppList />} />+ <Route path="/project/:projectId/:partitionKey/:appId" element={<AppViewContainer />} /><Route path="/demos/counter" element={<Counter />} /><Route path="/demos/chatbot" element={<ChatbotWithTelemetry />} /><Route path="/demos/streaming-chatbot" element={<StreamingChatbotWithTelemetry />} />diff --git a/telemetry/ui/src/api/models/BackendSpec.ts b/telemetry/ui/src/api/models/BackendSpec.tsindex ff240c5d..6f1a1058 100644--- a/telemetry/ui/src/api/models/BackendSpec.ts+++ b/telemetry/ui/src/api/models/BackendSpec.ts@@ -7,4 +7,5 @@*/export type BackendSpec = {indexing: boolean;+ snapshotting: boolean;};diff --git a/telemetry/ui/src/api/services/DefaultService.ts b/telemetry/ui/src/api/services/DefaultService.tsindex 26dd2507..a3129212 100644--- a/telemetry/ui/src/api/services/DefaultService.ts+++ b/telemetry/ui/src/api/services/DefaultService.ts@@ -17,6 +17,17 @@ import type { CancelablePromise } from '../core/CancelablePromise';import { OpenAPI } from '../core/OpenAPI';import { request as __request } from '../core/request';export class DefaultService {+ /**+ * Get App Spec+ * @returns BackendSpec Successful Response+ * @throws ApiError+ */+ public static getAppSpecApiV0MetadataAppSpecGet(): CancelablePromise<BackendSpec> {+ return __request(OpenAPI, {+ method: 'GET',+ url: '/api/v0/metadata/app_spec'+ });+ }/*** Get Projects* Gets all projects visible by the user.@@ -40,17 +51,20 @@ export class DefaultService {* :param project_id: project name* :return: a list of projects visible by the user* @param projectId+ * @param partitionKey* @returns ApplicationSummary Successful Response* @throws ApiError*/- public static getAppsApiV0ProjectIdAppsGet(- projectId: string+ public static getAppsApiV0ProjectIdPartitionKeyAppsGet(+ projectId: string,+ partitionKey: string): CancelablePromise<Array<ApplicationSummary>> {return __request(OpenAPI, {method: 'GET',- url: '/api/v0/{project_id}/apps',+ url: '/api/v0/{project_id}/{partition_key}/apps',path: {- project_id: projectId+ project_id: projectId,+ partition_key: partitionKey},errors: {422: `Validation Error`@@ -65,23 +79,26 @@ export class DefaultService {** :param request: FastAPI* :param project_id: ID of the project- * :param app_id: ID of the associated application+ * :param app_id: ID of the assIndociated application* :return: A list of steps with all associated step data* @param projectId* @param appId+ * @param partitionKey* @returns ApplicationLogs Successful Response* @throws ApiError*/- public static getApplicationLogsApiV0ProjectIdAppIdAppsGet(+ public static getApplicationLogsApiV0ProjectIdAppIdPartitionKeyAppsGet(projectId: string,- appId: string+ appId: string,+ partitionKey: string): CancelablePromise<ApplicationLogs> {return __request(OpenAPI, {method: 'GET',- url: '/api/v0/{project_id}/{app_id}/apps',+ url: '/api/v0/{project_id}/{app_id}/{partition_key}/apps',path: {project_id: projectId,- app_id: appId+ app_id: appId,+ partition_key: partitionKey},errors: {422: `Validation Error`@@ -99,17 +116,6 @@ export class DefaultService {url: '/api/v0/ready'});}- /**- * Get App Spec- * @returns BackendSpec Successful Response- * @throws ApiError- */- public static getAppSpecApiV0MetadataAppSpecGet(): CancelablePromise<BackendSpec> {- return __request(OpenAPI, {- method: 'GET',- url: '/api/v0/metadata/app_spec'- });- }/*** Get Indexing Jobs* @param offsetdiff --git a/telemetry/ui/src/components/routes/AppList.tsx b/telemetry/ui/src/components/routes/AppList.tsxindex a87e522a..ae16ef3d 100644--- a/telemetry/ui/src/components/routes/AppList.tsx+++ b/telemetry/ui/src/components/routes/AppList.tsx@@ -6,7 +6,7 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '.import { DateTimeDisplay } from '../common/dates';import { useState } from 'react';import { FunnelIcon, MinusIcon, PlusIcon } from '@heroicons/react/24/outline';-import { useNavigate } from 'react-router-dom';+import { Link, useNavigate } from 'react-router-dom';import { MdForkRight } from 'react-icons/md';import { RiCornerDownRightLine } from 'react-icons/ri';@@ -77,12 +77,25 @@ const AppSubList = (props: {key={props.app.app_id}className={`cursor-pointer ${isHighlighted ? 'bg-gray-50' : ''}`}onClick={() => {- props.navigate(`/project/${props.projectId}/${app.app_id}`);+ props.navigate(`/project/${props.projectId}/${app.partition_key}/${app.app_id}`);}}>{props.displayPartitionKey && (<TableCell className="text-gray-600 font-sans">- {isNullPartitionKey(app.partition_key) ? '' : app.partition_key}+ {isNullPartitionKey(app.partition_key) ? (+ <></>+ ) : (+ <Link+ to={`/project/${props.projectId}/${app.partition_key}`}+ className="hover:underline"+ onClick={(e) => {+ props.navigate(`/project/${props.projectId}/${app.partition_key}`);+ e.stopPropagation();+ }}+ >+ {app.partition_key}+ </Link>+ )}</TableCell>)}<TableCell className="font-semibold text-gray-700">@@ -223,10 +236,14 @@ export const AppListTable = (props: { apps: ApplicationSummary[]; projectId: str* List of applications. This fetches data from the BE and passes it to the table*/export const AppList = () => {- const { projectId } = useParams();+ const { projectId, partitionKey } = useParams();const { data, error } = useQuery(- ['apps', projectId],- () => DefaultService.getAppsApiV0ProjectIdAppsGet(projectId as string),+ ['apps', projectId, partitionKey],+ () =>+ DefaultService.getAppsApiV0ProjectIdPartitionKeyAppsGet(+ projectId as string,+ partitionKey ? partitionKey : '__none__'+ ),{ enabled: projectId !== undefined });if (projectId === undefined) {diff --git a/telemetry/ui/src/components/routes/app/AppView.tsx b/telemetry/ui/src/components/routes/app/AppView.tsxindex fb37883e..c7ed7620 100644--- a/telemetry/ui/src/components/routes/app/AppView.tsx+++ b/telemetry/ui/src/components/routes/app/AppView.tsx@@ -90,6 +90,7 @@ const NUM_PREVIOUS_ACTIONS = 6;export const AppView = (props: {projectId: string;appId: string;+ partitionKey?: string;orientation: 'stacked_vertical' | 'stacked_horizontal';defaultAutoRefresh?: boolean;}) => {@@ -102,9 +103,10 @@ export const AppView = (props: {const { data, error } = useQuery(['steps', appId],() =>- DefaultService.getApplicationLogsApiV0ProjectIdAppIdAppsGet(+ DefaultService.getApplicationLogsApiV0ProjectIdAppIdPartitionKeyAppsGet(projectId as string,- appId as string+ appId as string,+ props.partitionKey !== undefined ? props.partitionKey : '__none__'),{refetchInterval: autoRefresh ? REFRESH_INTERVAL : false,@@ -250,9 +252,16 @@ export const AppView = (props: {};export const AppViewContainer = () => {- const { projectId, appId } = useParams();+ const { projectId, appId, partitionKey } = useParams();if (projectId === undefined || appId === undefined) {return <div>Invalid URL</div>;}- return <AppView projectId={projectId} appId={appId} orientation={'stacked_horizontal'} />;+ return (+ <AppView+ projectId={projectId}+ appId={appId}+ partitionKey={partitionKey}+ orientation={'stacked_horizontal'}+ />+ );};diff --git a/telemetry/ui/src/examples/Common.tsx b/telemetry/ui/src/examples/Common.tsxindex de5f5874..dc3f4cd1 100644--- a/telemetry/ui/src/examples/Common.tsx+++ b/telemetry/ui/src/examples/Common.tsx@@ -51,7 +51,8 @@ export const ChatbotAppSelector = (props: {const { projectId, setApp } = props;const { data, refetch } = useQuery(['apps', projectId],- () => DefaultService.getAppsApiV0ProjectIdAppsGet(projectId as string),+ // TODO - use the right partition key+ () => DefaultService.getAppsApiV0ProjectIdPartitionKeyAppsGet(projectId as string, '__none__'),{ enabled: projectId !== undefined });const createAndUpdateMutation = useMutation(diff --git a/telemetry/ui/src/examples/EmailAssistant.tsx b/telemetry/ui/src/examples/EmailAssistant.tsxindex e9c4a325..22a4e787 100644--- a/telemetry/ui/src/examples/EmailAssistant.tsx+++ b/telemetry/ui/src/examples/EmailAssistant.tsx@@ -385,7 +385,7 @@ export const EmailAssistantAppSelector = (props: {const { projectId, setApp } = props;const { data, refetch } = useQuery(['apps', projectId],- () => DefaultService.getAppsApiV0ProjectIdAppsGet(projectId as string),+ () => DefaultService.getAppsApiV0ProjectIdPartitionKeyAppsGet(projectId as string, '__none__'),{ enabled: projectId !== undefined });const createAndUpdateMutation = useMutation(