Skip to content

Commit

Permalink
Allow creating tasks E2E!
Browse files Browse the repository at this point in the history
  • Loading branch information
scosman committed Oct 8, 2024
1 parent cc54c0e commit 10b2053
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { KilnError } from "../error_handlers"

export type JsonSchema = {
type: "object"
properties: Record<string, JsonSchemaProperty>
Expand Down Expand Up @@ -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(
Expand All @@ -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)),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -43,6 +46,22 @@
)
return
}
let body: Record<string, unknown> = {
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}`,
Expand All @@ -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()
Expand Down
1 change: 0 additions & 1 deletion libs/studio/kiln_studio/test_task_management.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from pathlib import Path
from unittest.mock import patch

Expand Down

0 comments on commit 10b2053

Please sign in to comment.