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 validation for OpenAI API key
elijahbenizzy805846456def
diff --git a/examples/email-assistant/application.py b/examples/email-assistant/application.pyindex 024f0021..2726699f 100644--- a/examples/email-assistant/application.py+++ b/examples/email-assistant/application.py@@ -1,4 +1,5 @@import functools+import osfrom typing import Tupleimport openai@@ -22,6 +23,12 @@ def process_input(return result, state.update(**result)+@action(reads=[], writes=["has_openai_key"])+def check_openai_key(state: State) -> Tuple[dict, State]:+ result = {"has_openai_key": "OPENAI_API_KEY" in os.environ}+ return result, state.update(**result)++@action(reads=["response_instructions", "incoming_email"], writes=["clarification_questions"])def determine_clarifications(state: State) -> Tuple[dict, State]:"""Determines if the response instructions require clarification."""diff --git a/examples/email-assistant/server.py b/examples/email-assistant/server.pyindex f540c5a5..a4c03d50 100644--- a/examples/email-assistant/server.py+++ b/examples/email-assistant/server.py@@ -1,5 +1,6 @@import functoolsimport importlib+import osfrom typing import Any, Dict, List, Literal, Optionalimport pydantic@@ -152,6 +153,19 @@ def get_state(project_id: str, app_id: str) -> EmailAssistantState:return EmailAssistantState.from_app(email_assistant_app)[email protected]("/validate/{project_id}/{app_id}")+def validate_environment() -> Optional[str]:+ """Validate the environment"""+ if "OPENAI_API_KEY" in os.environ:+ return+ return (+ "You have not set an API key for [OpenAI](https://www.openai.com). Do this "+ "by setting the environment variable `OPENAI_API_KEY` to your key. "+ "You can get a key at https://platform.openai.com. "+ "You can still look at chat history/examples."+ )++if __name__ == "__main__":import uvicorndiff --git a/telemetry/ui/src/api/services/DefaultService.ts b/telemetry/ui/src/api/services/DefaultService.tsindex 9b931000..447da977 100644--- a/telemetry/ui/src/api/services/DefaultService.ts+++ b/telemetry/ui/src/api/services/DefaultService.ts@@ -186,8 +186,37 @@ export class DefaultService {}});}+ /**+ * Create New Application+ * @param projectId+ * @param appId+ * @returns string Successful Response+ * @throws ApiError+ */+ public static createNewApplicationApiV0EmailAssistantCreateNewProjectIdAppIdPost(+ projectId: string,+ appId: string+ ): CancelablePromise<string> {+ return __request(OpenAPI, {+ method: 'POST',+ url: '/api/v0/email_assistant/create_new/{project_id}/{app_id}',+ path: {+ project_id: projectId,+ app_id: appId+ },+ errors: {+ 422: `Validation Error`+ }+ });+ }/*** Initialize Draft+ * 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* @param projectId* @param appId* @param requestBody@@ -215,6 +244,12 @@ export class DefaultService {}/*** Answer Questions+ * 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* @param projectId* @param appId* @param requestBody@@ -242,6 +277,12 @@ export class DefaultService {}/*** Provide Feedback+ * 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* @param projectId* @param appId* @param requestBody@@ -269,6 +310,11 @@ export class DefaultService {}/*** Get State+ * 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* @param projectId* @param appId* @returns EmailAssistantState Successful Response@@ -290,6 +336,20 @@ export class DefaultService {}});}+ /**+ * Validate Environment+ * Validate the environment+ * @returns any Successful Response+ * @throws ApiError+ */+ public static validateEnvironmentApiV0EmailAssistantValidateProjectIdAppIdGet(): CancelablePromise<+ string | null+ > {+ return __request(OpenAPI, {+ method: 'GET',+ url: '/api/v0/email_assistant/validate/{project_id}/{app_id}'+ });+ }/*** React App* Quick trick to server the react appdiff --git a/telemetry/ui/src/examples/EmailAssistant.tsx b/telemetry/ui/src/examples/EmailAssistant.tsxindex ea04928e..8385d7e7 100644--- a/telemetry/ui/src/examples/EmailAssistant.tsx+++ b/telemetry/ui/src/examples/EmailAssistant.tsx@@ -186,6 +186,10 @@ export const SubmitFeedbackView = (props: {export const EmailAssistant = (props: { projectId: string; appId: string | undefined }) => {// starts off as nullconst [emailAssistantState, setEmailAssistantState] = useState<EmailAssistantState | null>(null);+ const { data: validationData, isLoading: isValidationLoading } = useQuery(+ ['valid', props.projectId, props.appId],+ DefaultService.validateEnvironmentApiV0EmailAssistantValidateProjectIdAppIdGet+ );useEffect(() => {if (props.appId !== undefined) {@@ -265,10 +269,11 @@ export const EmailAssistant = (props: { projectId: string; appId: string | undefsubmitAnswersMutation.isLoading ||submitFeedbackMutation.isLoading;- if (isLoading) {+ if (isLoading || isValidationLoading) {return <Loading />;}- const displayInstructions = emailAssistantState === null;+ const displayValidationError = validationData !== null;+ const displayInstructions = emailAssistantState === null && !displayValidationError;const displayInitialDraft = emailAssistantState !== null;const displaySubmitAnswers =displayInitialDraft && emailAssistantState.next_step !== 'process_input';@@ -289,6 +294,9 @@ export const EmailAssistant = (props: { projectId: string; appId: string | undefPlease click 'create new' on the right to get started!</p>)}+ {displayValidationError && (+ <p className="text-lg font-normal text-dwred">{validationData}</p>+ )}{displayInitialDraft && (<InitialDraftViewisLoading={anyMutationLoading}