From cee8c5de8611d4a35cb5423a6303ceddc6827bb6 Mon Sep 17 00:00:00 2001 From: Nate Brake <33383515+njbrake@users.noreply.github.com> Date: Tue, 12 Nov 2024 08:44:40 -0500 Subject: [PATCH 1/3] Sagemaker doesn't yet support tools https://github.com/ucbepic/docetl/issues/160 --- docetl/operations/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docetl/operations/utils.py b/docetl/operations/utils.py index 5dd60237..7d6331e1 100644 --- a/docetl/operations/utils.py +++ b/docetl/operations/utils.py @@ -765,7 +765,7 @@ def _call_llm_with_cache( len(props) == 1 and list(props.values())[0].get("type") == "string" and scratchpad is None - and ("ollama" in model or "azure/gpt-4o-mini" in model) + and ("ollama" in model or "azure/gpt-4o-mini" in model or "sagemaker" in model) ): use_tools = False From 92fd4f73b809667104ba6b6027895e4ed8d053ee Mon Sep 17 00:00:00 2001 From: Shreya Shankar Date: Tue, 12 Nov 2024 23:31:43 +0000 Subject: [PATCH 2/3] fix: save validation and gleaning --- website/src/components/OperationCard.tsx | 31 +- website/src/components/operations/args.tsx | 418 +++++++++++---------- 2 files changed, 241 insertions(+), 208 deletions(-) diff --git a/website/src/components/OperationCard.tsx b/website/src/components/OperationCard.tsx index d4095d74..e069f19d 100644 --- a/website/src/components/OperationCard.tsx +++ b/website/src/components/OperationCard.tsx @@ -401,6 +401,7 @@ function operationReducer(state: State, action: Action): State { : state; case "UPDATE_GUARDRAILS": + console.log("UPDATE_GUARDRAILS", state, action.payload); return state.operation ? { ...state, @@ -757,6 +758,22 @@ export const OperationCard: React.FC<{ index: number }> = ({ index }) => { [operation, handleOperationUpdate, toast] ); + const handleGuardrailsUpdate = useCallback( + (newGuardrails: string[]) => { + dispatch({ type: "UPDATE_GUARDRAILS", payload: newGuardrails }); + debouncedUpdate(); + }, + [debouncedUpdate] + ); + + const handleGleaningsUpdate = useCallback( + (newGleanings: { num_rounds: number; validation_prompt: string }) => { + dispatch({ type: "UPDATE_GLEANINGS", payload: newGleanings }); + debouncedUpdate(); + }, + [debouncedUpdate] + ); + if (!operation) { return ; } @@ -830,12 +847,7 @@ export const OperationCard: React.FC<{ index: number }> = ({ index }) => { <> - dispatch({ - type: "UPDATE_GUARDRAILS", - payload: newGuardrails, - }) - } + onUpdate={handleGuardrailsUpdate} isExpanded={isGuardrailsExpanded} onToggle={() => dispatch({ type: "TOGGLE_GUARDRAILS" })} /> @@ -846,12 +858,7 @@ export const OperationCard: React.FC<{ index: number }> = ({ index }) => { operation.type === "filter") && ( - dispatch({ - type: "UPDATE_GLEANINGS", - payload: newGleanings, - }) - } + onUpdate={handleGleaningsUpdate} isExpanded={isGleaningsExpanded} onToggle={() => dispatch({ type: "TOGGLE_GLEANINGS" })} /> diff --git a/website/src/components/operations/args.tsx b/website/src/components/operations/args.tsx index abb8d9dc..659e8196 100644 --- a/website/src/components/operations/args.tsx +++ b/website/src/components/operations/args.tsx @@ -58,138 +58,158 @@ export const PromptInput: React.FC = React.memo( PromptInput.displayName = "PromptInput"; -export const SchemaForm: React.FC<{ +interface SchemaFormProps { schema: SchemaItem[]; onUpdate: (newSchema: SchemaItem[]) => void; level?: number; isList?: boolean; -}> = React.memo(({ schema, onUpdate, level = 0, isList = false }) => { - const addItem = () => { - if (isList) return; - onUpdate([...schema, { key: "", type: "string" }]); - }; +} + +export const SchemaForm: React.FC = React.memo( + ({ schema, onUpdate, level = 0, isList = false }) => { + const addItem = () => { + if (isList) return; + onUpdate([...schema, { key: "", type: "string" }]); + }; - const updateItem = (index: number, item: SchemaItem) => { - const newSchema = [...schema]; - newSchema[index] = item; - onUpdate(newSchema); - }; + const updateItem = (index: number, item: SchemaItem) => { + const newSchema = [...schema]; + newSchema[index] = item; + onUpdate(newSchema); + }; - const removeItem = (index: number) => { - if (isList) return; - const newSchema = schema.filter((_, i) => i !== index); - onUpdate(newSchema); - }; + const removeItem = (index: number) => { + if (isList) return; + const newSchema = schema.filter((_, i) => i !== index); + onUpdate(newSchema); + }; - return ( -
- {schema.map((item, index) => ( -
- {!isList && ( - - updateItem(index, { ...item, key: e.target.value }) - } - placeholder="Key" - className="w-1/3 min-w-[150px]" - /> - )} - - {!isList && ( - - )} - {item.type === "list" && item.subType && ( -
- List type: - - updateItem(index, { ...item, subType: newSubSchema[0] }) - } - level={0} - isList={true} - /> -
- )} - {item.type === "dict" && item.subType && ( -
- - updateItem(index, { ...item, subType: newSubSchema }) + {!isList && ( + + updateItem(index, { ...item, key: e.target.value }) } - level={level + 1} + placeholder="Key" + className="w-1/3 min-w-[150px]" /> -
- )} -
- ))} - {!isList && ( - - )} -
- ); -}); + )} + + {!isList && ( + + )} + {item.type === "list" && item.subType && ( +
+ List type: + + updateItem(index, { ...item, subType: newSubSchema[0] }) + } + level={0} + isList={true} + /> +
+ )} + {item.type === "dict" && item.subType && ( +
+ + updateItem(index, { ...item, subType: newSubSchema }) + } + level={level + 1} + /> +
+ )} + + ))} + {!isList && ( + + )} + + ); + } +); + +SchemaForm.displayName = "SchemaForm"; -export const OutputSchema: React.FC<{ +interface OutputSchemaProps { schema: SchemaItem[]; onUpdate: (newSchema: SchemaItem[]) => void; isExpanded: boolean; onToggle: () => void; -}> = React.memo(({ schema, onUpdate, isExpanded, onToggle }) => { - return ( -
- - {isExpanded && } -
- ); -}); +} + +export const OutputSchema: React.FC = React.memo( + ({ schema, onUpdate, isExpanded, onToggle }) => { + return ( +
+ + {isExpanded && } +
+ ); + } +); + +OutputSchema.displayName = "OutputSchema"; export interface GleaningConfigProps { gleaning: { num_rounds: number; validation_prompt: string } | null; @@ -286,89 +306,95 @@ export const GleaningConfig: React.FC = React.memo( GleaningConfig.displayName = "GleaningConfig"; -export const Guardrails: React.FC<{ +interface GuardrailsProps { guardrails: string[]; onUpdate: (newGuardrails: string[]) => void; isExpanded: boolean; onToggle: () => void; -}> = React.memo(({ guardrails, onUpdate, isExpanded, onToggle }) => { - const handleGuardrailChange = (index: number, value: string) => { - const newGuardrails = [...guardrails]; - newGuardrails[index] = value; - onUpdate(newGuardrails); - }; +} - const addGuardrail = () => { - onUpdate([...guardrails, ""]); - }; +export const Guardrails: React.FC = React.memo( + ({ guardrails, onUpdate, isExpanded, onToggle }) => { + const handleGuardrailChange = (index: number, value: string) => { + const newGuardrails = [...guardrails]; + newGuardrails[index] = value; + onUpdate(newGuardrails); + }; - const removeGuardrail = (index: number) => { - const newGuardrails = guardrails.filter((_, i) => i !== index); - onUpdate(newGuardrails); - }; + const addGuardrail = () => { + onUpdate([...guardrails, ""]); + }; - return ( -
- - {isExpanded && ( -
- {guardrails.map((guardrail, index) => ( -
- handleGuardrailChange(index, e.target.value)} - placeholder="Enter guardrail" - className="flex-grow text-sm text-orange-700 font-mono" - /> - -
- ))} - -
- )} -
- ); -}); + const removeGuardrail = (index: number) => { + const newGuardrails = guardrails.filter((_, i) => i !== index); + onUpdate(newGuardrails); + }; + + return ( +
+ + {isExpanded && ( +
+ {guardrails.map((guardrail, index) => ( +
+ handleGuardrailChange(index, e.target.value)} + placeholder="Enter guardrail" + className="flex-grow text-sm text-orange-700 font-mono" + /> + +
+ ))} + +
+ )} +
+ ); + } +); + +Guardrails.displayName = "Guardrails"; From dcf87233cfb6aa027ddefc924dfc2f27520dc6a7 Mon Sep 17 00:00:00 2001 From: Shreya Shankar Date: Wed, 13 Nov 2024 01:08:26 +0000 Subject: [PATCH 3/3] Remove unnecessary console log statements --- website/src/components/OperationCard.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/website/src/components/OperationCard.tsx b/website/src/components/OperationCard.tsx index e069f19d..1d48383c 100644 --- a/website/src/components/OperationCard.tsx +++ b/website/src/components/OperationCard.tsx @@ -401,7 +401,6 @@ function operationReducer(state: State, action: Action): State { : state; case "UPDATE_GUARDRAILS": - console.log("UPDATE_GUARDRAILS", state, action.payload); return state.operation ? { ...state, @@ -619,7 +618,6 @@ export const OperationCard: React.FC<{ index: number }> = ({ index }) => { const onOptimize = useCallback(async () => { if (!operation) return; - console.log("Optimizing operation", operation.id); try { // Clear the output