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 documentation to server file
elijahbenizzy7a74a3319ff2
diff --git a/examples/email-assistant/server.py b/examples/email-assistant/server.pyindex 1a8ada65..f540c5a5 100644--- a/examples/email-assistant/server.py+++ b/examples/email-assistant/server.py@@ -64,6 +64,7 @@ def _get_application(project_id: str, app_id: str) -> Application:def _run_through(project_id: str, app_id: [str], inputs: Dict[str, Any]) -> EmailAssistantState:+ """This advances the state machine, moving through to the next 'halting' point"""if app_id == "create_new": # quick hack to allow for nullapp_id = Noneemail_assistant_app = _get_application(project_id, app_id)@@ -88,6 +89,13 @@ def create_new_application(project_id: str, app_id: str) -> str:@router.post("/create/{project_id}/{app_id}")def initialize_draft(project_id: str, app_id: str, draft_data: DraftInit) -> EmailAssistantState:+ """Endpoint to initialize the draft with the email and instructions++ :param project_id: ID of the project (used by telemetry tracking/storage)+ :param app_id: ID of the application (used to reference the app)+ :param draft_data: Data to initialize the draft+ :return: The state of the application after initialization+ """return _run_through(project_id,app_id,@@ -106,6 +114,13 @@ class QuestionAnswers(pydantic.BaseModel):def answer_questions(project_id: str, app_id: str, question_answers: QuestionAnswers) -> EmailAssistantState:+ """Endpoint to answer questions the LLM provides++ :param project_id: ID of the project (used by telemetry tracking/storage)+ :param app_id: ID of the application (used to reference the app)+ :param question_answers: Answers to the questions+ :return: The state of the application after answering the questions+ """return _run_through(project_id, app_id, dict(clarification_inputs=question_answers.answers))@@ -115,11 +130,24 @@ class Feedback(pydantic.BaseModel):@router.post("/provide_feedback/{project_id}/{app_id}")def provide_feedback(project_id: str, app_id: str, feedback: Feedback) -> EmailAssistantState:+ """Endpoint to provide feedback to the LLM++ :param project_id: ID of the project (used by telemetry tracking/storage)+ :param app_id: ID of the application (used to reference the app)+ :param feedback: Feedback to provide to the LLM+ :return: The state of the application after providing feedback+ """return _run_through(project_id, app_id, dict(feedback=feedback.feedback))@router.get("/state/{project_id}/{app_id}")def get_state(project_id: str, app_id: str) -> EmailAssistantState:+ """Get the current state of the application++ :param project_id: ID of the project (used by telemetry tracking/storage)+ :param app_id: ID of the application (used to reference the app)+ :return: The state of the application+ """email_assistant_app = _get_application(project_id, app_id)return EmailAssistantState.from_app(email_assistant_app)diff --git a/telemetry/ui/src/components/common/input.tsx b/telemetry/ui/src/components/common/input.tsxindex 2568dbd2..166a6c2d 100644--- a/telemetry/ui/src/components/common/input.tsx+++ b/telemetry/ui/src/components/common/input.tsx@@ -1,13 +1,15 @@-import { Input as HeadlessInput, type InputProps as HeadlessInputProps } from '@headlessui/react'-import { clsx } from 'clsx'-import { forwardRef } from 'react'+import { Input as HeadlessInput, type InputProps as HeadlessInputProps } from '@headlessui/react';+import { clsx } from 'clsx';+import { forwardRef } from 'react';-const dateTypes = ['date', 'datetime-local', 'month', 'time', 'week']-type DateType = (typeof dateTypes)[number]+const dateTypes = ['date', 'datetime-local', 'month', 'time', 'week'];+type DateType = (typeof dateTypes)[number];export const Input = forwardRef<HTMLInputElement,- { type?: 'email' | 'number' | 'password' | 'search' | 'tel' | 'text' | 'url' | DateType } & HeadlessInputProps+ {+ type?: 'email' | 'number' | 'password' | 'search' | 'tel' | 'text' | 'url' | DateType;+ } & HeadlessInputProps>(function Input({ className, ...props }, ref) {return (<span@@ -31,7 +33,7 @@ export const Input = forwardRef<'has-[[data-disabled]]:opacity-50 before:has-[[data-disabled]]:bg-zinc-950/5 before:has-[[data-disabled]]:shadow-none',// Invalid state- 'before:has-[[data-invalid]]:shadow-red-500/10',+ 'before:has-[[data-invalid]]:shadow-red-500/10'])}><HeadlessInput@@ -51,7 +53,7 @@ export const Input = forwardRef<'[&::-webkit-datetime-edit-minute-field]:p-0','[&::-webkit-datetime-edit-second-field]:p-0','[&::-webkit-datetime-edit-millisecond-field]:p-0',- '[&::-webkit-datetime-edit-meridiem-field]:p-0',+ '[&::-webkit-datetime-edit-meridiem-field]:p-0'],// Basic layout@@ -73,10 +75,10 @@ export const Input = forwardRef<'data-[invalid]:border-red-500 data-[invalid]:data-[hover]:border-red-500 data-[invalid]:dark:border-red-500 data-[invalid]:data-[hover]:dark:border-red-500',// Disabled state- 'data-[disabled]:border-zinc-950/20 dark:data-[hover]:data-[disabled]:border-white/15 data-[disabled]:dark:border-white/15 data-[disabled]:dark:bg-white/[2.5%]',+ 'data-[disabled]:border-zinc-950/20 dark:data-[hover]:data-[disabled]:border-white/15 data-[disabled]:dark:border-white/15 data-[disabled]:dark:bg-white/[2.5%]'])}{...props}/></span>- )-})+ );+});diff --git a/telemetry/ui/src/components/common/text.tsx b/telemetry/ui/src/components/common/text.tsxindex 099919c3..c2bfc7cf 100644--- a/telemetry/ui/src/components/common/text.tsx+++ b/telemetry/ui/src/components/common/text.tsx@@ -1,5 +1,5 @@-import { clsx } from 'clsx'-import { Link } from './link'+import { clsx } from 'clsx';+import { Link } from './link';export function Text({ className, ...props }: React.ComponentPropsWithoutRef<'p'>) {return (@@ -8,7 +8,7 @@ export function Text({ className, ...props }: React.ComponentPropsWithoutRef<'p'data-slot="text"className={clsx(className, 'text-base/6 text-zinc-500 sm:text-sm/6 dark:text-zinc-400')}/>- )+ );}export function TextLink({ className, ...props }: React.ComponentPropsWithoutRef<typeof Link>) {@@ -20,11 +20,13 @@ export function TextLink({ className, ...props }: React.ComponentPropsWithoutRef'text-zinc-950 underline decoration-zinc-950/50 data-[hover]:decoration-zinc-950 dark:text-white dark:decoration-white/50 dark:data-[hover]:decoration-white')}/>- )+ );}export function Strong({ className, ...props }: React.ComponentPropsWithoutRef<'strong'>) {- return <strong {...props} className={clsx(className, 'font-medium text-zinc-950 dark:text-white')} />+ return (+ <strong {...props} className={clsx(className, 'font-medium text-zinc-950 dark:text-white')} />+ );}export function Code({ className, ...props }: React.ComponentPropsWithoutRef<'code'>) {@@ -36,5 +38,5 @@ export function Code({ className, ...props }: React.ComponentPropsWithoutRef<'co'rounded border border-zinc-950/10 bg-zinc-950/[2.5%] px-0.5 text-sm font-medium text-zinc-950 sm:text-[0.8125rem] dark:border-white/20 dark:bg-white/5 dark:text-white')}/>- )+ );}diff --git a/telemetry/ui/src/components/common/textarea.tsx b/telemetry/ui/src/components/common/textarea.tsxindex df05b4a6..de341d5f 100644--- a/telemetry/ui/src/components/common/textarea.tsx+++ b/telemetry/ui/src/components/common/textarea.tsx@@ -1,61 +1,65 @@-import { Textarea as HeadlessTextarea, type TextareaProps as HeadlessTextareaProps } from '@headlessui/react'-import { clsx } from 'clsx'-import { forwardRef } from 'react'--export const Textarea = forwardRef<HTMLTextAreaElement, { resizable?: boolean } & HeadlessTextareaProps>(- function Textarea({ className, resizable = true, ...props }, ref) {- return (- <span- data-slot="control"- className={clsx([- className,+import {+ Textarea as HeadlessTextarea,+ type TextareaProps as HeadlessTextareaProps+} from '@headlessui/react';+import { clsx } from 'clsx';+import { forwardRef } from 'react';++export const Textarea = forwardRef<+ HTMLTextAreaElement,+ { resizable?: boolean } & HeadlessTextareaProps+>(function Textarea({ className, resizable = true, ...props }, ref) {+ return (+ <span+ data-slot="control"+ className={clsx([+ className,++ // Basic layout+ 'relative block w-full',++ // Background color + shadow applied to inset pseudo element, so shadow blends with border in light mode+ 'before:absolute before:inset-px before:rounded-[calc(theme(borderRadius.lg)-1px)] before:bg-white before:shadow',++ // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo+ 'dark:before:hidden',+ // Focus ring+ 'after:pointer-events-none after:absolute after:inset-0 after:rounded-lg after:ring-inset after:ring-transparent sm:after:focus-within:ring-2 sm:after:focus-within:ring-blue-500',++ // Disabled state+ 'has-[[data-disabled]]:opacity-50 before:has-[[data-disabled]]:bg-zinc-950/5 before:has-[[data-disabled]]:shadow-none'+ ])}+ >+ <HeadlessTextarea+ ref={ref}+ className={clsx([// Basic layout- 'relative block w-full',+ 'relative block h-full w-full appearance-none rounded-lg px-[calc(theme(spacing[3.5])-1px)] py-[calc(theme(spacing[2.5])-1px)] sm:px-[calc(theme(spacing.3)-1px)] sm:py-[calc(theme(spacing[1.5])-1px)]',++ // Typography+ 'text-base/6 text-zinc-950 placeholder:text-zinc-500 sm:text-sm/6 dark:text-white',- // Background color + shadow applied to inset pseudo element, so shadow blends with border in light mode- 'before:absolute before:inset-px before:rounded-[calc(theme(borderRadius.lg)-1px)] before:bg-white before:shadow',+ // Border+ 'border border-zinc-950/10 data-[hover]:border-zinc-950/20 dark:border-white/10 dark:data-[hover]:border-white/20',- // Background color is moved to control and shadow is removed in dark mode so hide `before` pseudo- 'dark:before:hidden',+ // Background color+ 'bg-transparent dark:bg-white/5',- // Focus ring- 'after:pointer-events-none after:absolute after:inset-0 after:rounded-lg after:ring-inset after:ring-transparent sm:after:focus-within:ring-2 sm:after:focus-within:ring-blue-500',+ // Hide default focus styles+ 'focus:outline-none',++ // Invalid state+ 'data-[invalid]:border-red-500 data-[invalid]:data-[hover]:border-red-500 data-[invalid]:dark:border-red-600 data-[invalid]:data-[hover]:dark:border-red-600',// Disabled state- 'has-[[data-disabled]]:opacity-50 before:has-[[data-disabled]]:bg-zinc-950/5 before:has-[[data-disabled]]:shadow-none',+ 'disabled:border-zinc-950/20 disabled:dark:border-white/15 disabled:dark:bg-white/[2.5%] dark:data-[hover]:disabled:border-white/15',++ // Resizable+ resizable ? 'resize-y' : 'resize-none'])}- >- <HeadlessTextarea- ref={ref}- className={clsx([- // Basic layout- 'relative block h-full w-full appearance-none rounded-lg px-[calc(theme(spacing[3.5])-1px)] py-[calc(theme(spacing[2.5])-1px)] sm:px-[calc(theme(spacing.3)-1px)] sm:py-[calc(theme(spacing[1.5])-1px)]',-- // Typography- 'text-base/6 text-zinc-950 placeholder:text-zinc-500 sm:text-sm/6 dark:text-white',-- // Border- 'border border-zinc-950/10 data-[hover]:border-zinc-950/20 dark:border-white/10 dark:data-[hover]:border-white/20',-- // Background color- 'bg-transparent dark:bg-white/5',-- // Hide default focus styles- 'focus:outline-none',-- // Invalid state- 'data-[invalid]:border-red-500 data-[invalid]:data-[hover]:border-red-500 data-[invalid]:dark:border-red-600 data-[invalid]:data-[hover]:dark:border-red-600',-- // Disabled state- 'disabled:border-zinc-950/20 disabled:dark:border-white/15 disabled:dark:bg-white/[2.5%] dark:data-[hover]:disabled:border-white/15',-- // Resizable- resizable ? 'resize-y' : 'resize-none',- ])}- {...props}- />- </span>- )- }-)+ {...props}+ />+ </span>+ );+});