diff --git a/app/web_ui/src/lib/utils/json_schema_editor/json_schema_templates.test.ts b/app/web_ui/src/lib/utils/json_schema_editor/json_schema_templates.test.ts index abe1bbd..ae1e73c 100644 --- a/app/web_ui/src/lib/utils/json_schema_editor/json_schema_templates.test.ts +++ b/app/web_ui/src/lib/utils/json_schema_editor/json_schema_templates.test.ts @@ -73,7 +73,7 @@ describe("schema_from_model", () => { description: "User's age in years", }, }, - required: ["User Name"], + required: ["user_name"], } expect(schema_from_model(model)).toEqual(expected) @@ -118,7 +118,7 @@ describe("schema_from_model", () => { } const result = schema_from_model(model) - expect(result.required).toEqual(["Field1", "Field3"]) + expect(result.required).toEqual(["field1", "field3"]) }) it("correctly converts property titles to names", () => { diff --git a/app/web_ui/src/lib/utils/json_schema_editor/json_schema_templates.ts b/app/web_ui/src/lib/utils/json_schema_editor/json_schema_templates.ts index d9cf7d0..9bbb880 100644 --- a/app/web_ui/src/lib/utils/json_schema_editor/json_schema_templates.ts +++ b/app/web_ui/src/lib/utils/json_schema_editor/json_schema_templates.ts @@ -1,3 +1,5 @@ +import { KilnError } from "../error_handlers" + export type JsonSchema = { type: "object" properties: Record @@ -42,6 +44,20 @@ export function title_to_name(title: string): string { } export function schema_from_model(m: SchemaModel): JsonSchema { + for (let i = 0; i < m.properties.length; i++) { + const title = m.properties[i].title + if (!title) { + throw new KilnError("Property is empty. Please provide a name.", null) + } + const safe_name = title_to_name(m.properties[i].title) + if (!safe_name) { + throw new KilnError( + "Property name only contains special characters. Must be alphanumeric. Provided name with issues: " + + m.properties[i].title, + null, + ) + } + } return { type: "object", properties: Object.fromEntries( @@ -54,7 +70,9 @@ export function schema_from_model(m: SchemaModel): JsonSchema { }, ]), ), - required: m.properties.filter((p) => p.required).map((p) => p.title), + required: m.properties + .filter((p) => p.required) + .map((p) => title_to_name(p.title)), } } diff --git a/app/web_ui/src/routes/(fullscreen)/setup/(setup)/create_task/edit_task.svelte b/app/web_ui/src/routes/(fullscreen)/setup/(setup)/create_task/edit_task.svelte index b8529fd..96a95a4 100644 --- a/app/web_ui/src/routes/(fullscreen)/setup/(setup)/create_task/edit_task.svelte +++ b/app/web_ui/src/routes/(fullscreen)/setup/(setup)/create_task/edit_task.svelte @@ -4,7 +4,10 @@ import FormList from "$lib/utils/form_list.svelte" import FormContainer from "$lib/utils/form_container.svelte" import SchemaSection from "./schema_section.svelte" - import { empty_schema_model } from "$lib/utils/json_schema_editor/json_schema_templates" + import { + empty_schema_model, + schema_from_model, + } from "$lib/utils/json_schema_editor/json_schema_templates" import type { SchemaModel } from "$lib/utils/json_schema_editor/json_schema_templates" import { current_project } from "$lib/stores" import { goto } from "$app/navigation" @@ -43,6 +46,22 @@ ) return } + let body: Record = { + name: task_name, + description: task_description, + instructions: task_instructions, + requirements: task_requirements, + } + if (!task_input_plaintext) { + body["input_json_schema"] = JSON.stringify( + schema_from_model(task_input_schema), + ) + } + if (!task_output_plaintext) { + body["output_json_schema"] = JSON.stringify( + schema_from_model(task_output_schema), + ) + } const encodedProjectPath = encodeURIComponent($current_project) const response = await fetch( `http://localhost:8757/api/task?project_path=${encodedProjectPath}`, @@ -51,12 +70,7 @@ headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ - name: task_name, - description: task_description, - instructions: task_instructions, - requirements: task_requirements, - }), + body: JSON.stringify(body), }, ) const data = await response.json() diff --git a/libs/studio/kiln_studio/test_task_management.py b/libs/studio/kiln_studio/test_task_management.py index 16b97b7..747c4ad 100644 --- a/libs/studio/kiln_studio/test_task_management.py +++ b/libs/studio/kiln_studio/test_task_management.py @@ -1,4 +1,3 @@ -import json from pathlib import Path from unittest.mock import patch