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 diff --git a/website/src/components/OperationCard.tsx b/website/src/components/OperationCard.tsx index d4095d74..1d48383c 100644 --- a/website/src/components/OperationCard.tsx +++ b/website/src/components/OperationCard.tsx @@ -618,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 @@ -757,6 +756,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 +845,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 +856,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";