From 2ddf2931435bc2a0dabebe7898977dc28860ca69 Mon Sep 17 00:00:00 2001 From: scosman Date: Sun, 29 Sep 2024 20:15:21 -0400 Subject: [PATCH 1/6] New style/layout for the app --- app/web_ui/package.json | 4 +- app/web_ui/src/app.html | 1 + app/web_ui/src/routes/(app)/+layout.svelte | 107 +++++++-------------- app/web_ui/src/routes/(app)/+page.svelte | 50 +--------- app/web_ui/src/routes/(app)/+page.ts | 1 - app/web_ui/static/logo.svg | 5 + app/web_ui/tailwind.config.js | 34 ++++--- 7 files changed, 68 insertions(+), 134 deletions(-) delete mode 100644 app/web_ui/src/routes/(app)/+page.ts create mode 100644 app/web_ui/static/logo.svg diff --git a/app/web_ui/package.json b/app/web_ui/package.json index 6caa16e..a954026 100644 --- a/app/web_ui/package.json +++ b/app/web_ui/package.json @@ -1,6 +1,6 @@ { - "name": "cmsassstarter", - "version": "0.0.1", + "name": "kiln-web-ui", + "version": "0.0.2", "private": true, "scripts": { "dev": "vite dev", diff --git a/app/web_ui/src/app.html b/app/web_ui/src/app.html index 101c87b..82cc5a9 100644 --- a/app/web_ui/src/app.html +++ b/app/web_ui/src/app.html @@ -9,6 +9,7 @@
%sveltekit.body%
diff --git a/app/web_ui/src/routes/(app)/+layout.svelte b/app/web_ui/src/routes/(app)/+layout.svelte index cb5fdd7..2542c1a 100644 --- a/app/web_ui/src/routes/(app)/+layout.svelte +++ b/app/web_ui/src/routes/(app)/+layout.svelte @@ -2,77 +2,44 @@ import "../../app.css" - diff --git a/checks.sh b/checks.sh index d49a73a..4524c76 100755 --- a/checks.sh +++ b/checks.sh @@ -22,7 +22,7 @@ echo "No misspellings found" echo "${headerStart}Web UI: format, lint, check${headerEnd}" -changed_files=$(git diff --name-only) +changed_files=$(git diff --name-only --staged) if [[ "$changed_files" == *"app/web_ui/"* ]]; then echo "${headerStart}Checking Web UI: format, lint, check${headerEnd}" cd app/web_ui From eb3ddc9c23aa9d31239991103f90fa04e39eccff Mon Sep 17 00:00:00 2001 From: scosman Date: Mon, 30 Sep 2024 10:21:17 -0400 Subject: [PATCH 4/6] Improve checks.sh to run built (quietly) Fix build issues (static adapter pre-render setting global in layout) make VSCode autoformat --- .vscode/settings.json | 16 +++++++++++----- app/web_ui/src/routes/+layout.ts | 1 + checks.sh | 2 ++ 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 app/web_ui/src/routes/+layout.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index eccad60..ebd8885 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,11 +7,6 @@ }, "editor.tabSize": 4, }, - "eslint.validate": ["javascript", "javascriptreact", "svelte"], - // Svelte, JS, TS files - "[javascript, typescript, svelte, json]": { - "editor.defaultFormatter": "svelte.svelte-vscode" - }, "python.testing.pytestArgs": [ ".", "-s", @@ -26,4 +21,15 @@ "**/dist": true, "**/node_modules": true }, + // Svelte, JS, TS files + "[svelte]": { + "editor.defaultFormatter": "svelte.svelte-vscode" + }, + "[typescript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[javascript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "eslint.validate": ["javascript", "javascriptreact", "typescript", "svelte"], } diff --git a/app/web_ui/src/routes/+layout.ts b/app/web_ui/src/routes/+layout.ts new file mode 100644 index 0000000..176ae64 --- /dev/null +++ b/app/web_ui/src/routes/+layout.ts @@ -0,0 +1 @@ +export const prerender = true diff --git a/checks.sh b/checks.sh index 4524c76..2523f23 100755 --- a/checks.sh +++ b/checks.sh @@ -29,6 +29,8 @@ if [[ "$changed_files" == *"app/web_ui/"* ]]; then npm run format_check npm run lint npm run check + echo "Running vite build" + npm run build > /dev/null cd ../.. else echo "Skipping Web UI: no files changed" From 8ee62688b210888901d21e49a0348be4e8c2ad1d Mon Sep 17 00:00:00 2001 From: scosman Date: Mon, 30 Sep 2024 10:22:55 -0400 Subject: [PATCH 5/6] Fix drawer --- app/web_ui/src/routes/(app)/+layout.svelte | 34 +++++++++++++++------- app/web_ui/src/routes/(app)/+page.svelte | 2 ++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/web_ui/src/routes/(app)/+layout.svelte b/app/web_ui/src/routes/(app)/+layout.svelte index 63facb7..857e0db 100644 --- a/app/web_ui/src/routes/(app)/+layout.svelte +++ b/app/web_ui/src/routes/(app)/+layout.svelte @@ -21,25 +21,39 @@ /> -
Home
+
-
+
- - -
diff --git a/app/web_ui/src/routes/(app)/+page.svelte b/app/web_ui/src/routes/(app)/+page.svelte index 248ce31..b1c3424 100644 --- a/app/web_ui/src/routes/(app)/+page.svelte +++ b/app/web_ui/src/routes/(app)/+page.svelte @@ -5,3 +5,5 @@ Kiln Studio + +

Home

From b9a0fc910c4be214192fbd05ef99a4859b3f483b Mon Sep 17 00:00:00 2001 From: scosman Date: Mon, 30 Sep 2024 10:38:20 -0400 Subject: [PATCH 6/6] Improve naming of models.py -> Feels like ML models, not datamodels. Use __init__ level so it's improted as .datamodel instead --- libs/core/kiln_ai/adapters/base_adapter.py | 2 +- libs/core/kiln_ai/adapters/langchain_adapters.py | 4 ++-- .../kiln_ai/adapters/test_prompt_adaptors.py | 14 +++++++------- .../kiln_ai/adapters/test_prompt_builders.py | 2 +- .../kiln_ai/adapters/test_structured_output.py | 16 ++++++++-------- .../kiln_ai/datamodel/{models.py => __init__.py} | 2 +- .../kiln_ai/datamodel/test_example_models.py | 2 +- libs/core/kiln_ai/datamodel/test_models.py | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) rename libs/core/kiln_ai/datamodel/{models.py => __init__.py} (99%) diff --git a/libs/core/kiln_ai/adapters/base_adapter.py b/libs/core/kiln_ai/adapters/base_adapter.py index 22a8d2a..abe7931 100644 --- a/libs/core/kiln_ai/adapters/base_adapter.py +++ b/libs/core/kiln_ai/adapters/base_adapter.py @@ -2,8 +2,8 @@ from abc import ABCMeta, abstractmethod from typing import Dict +from kiln_ai.datamodel import Task from kiln_ai.datamodel.json_schema import validate_schema -from kiln_ai.datamodel.models import Task class BaseAdapter(metaclass=ABCMeta): diff --git a/libs/core/kiln_ai/adapters/langchain_adapters.py b/libs/core/kiln_ai/adapters/langchain_adapters.py index 34e636c..0fef21b 100644 --- a/libs/core/kiln_ai/adapters/langchain_adapters.py +++ b/libs/core/kiln_ai/adapters/langchain_adapters.py @@ -1,6 +1,6 @@ from typing import Dict -import kiln_ai.datamodel.models as models +import kiln_ai.datamodel as datamodel from kiln_ai.adapters.prompt_builders import SimplePromptBuilder from langchain_core.language_models.chat_models import BaseChatModel from langchain_core.messages import HumanMessage, SystemMessage @@ -13,7 +13,7 @@ class LangChainPromptAdapter(BaseAdapter): def __init__( self, - kiln_task: models.Task, + kiln_task: datamodel.Task, custom_model: BaseChatModel | None = None, model_name: str | None = None, provider: str | None = None, diff --git a/libs/core/kiln_ai/adapters/test_prompt_adaptors.py b/libs/core/kiln_ai/adapters/test_prompt_adaptors.py index 5fe04e2..c0d8a1a 100644 --- a/libs/core/kiln_ai/adapters/test_prompt_adaptors.py +++ b/libs/core/kiln_ai/adapters/test_prompt_adaptors.py @@ -1,7 +1,7 @@ import os from pathlib import Path -import kiln_ai.datamodel.models as models +import kiln_ai.datamodel as datamodel import pytest from kiln_ai.adapters.langchain_adapters import LangChainPromptAdapter from kiln_ai.adapters.ml_model_list import built_in_models, ollama_online @@ -95,30 +95,30 @@ async def test_all_built_in_models(tmp_path): def build_test_task(tmp_path: Path): - project = models.Project(name="test", path=tmp_path / "test.kiln") + project = datamodel.Project(name="test", path=tmp_path / "test.kiln") project.save_to_file() assert project.name == "test" - task = models.Task(parent=project, name="test task") + task = datamodel.Task(parent=project, name="test task") task.save_to_file() assert task.name == "test task" task.instruction = ( "You are an assistant which performs math tasks provided in plain text." ) - r1 = models.TaskRequirement( + r1 = datamodel.TaskRequirement( parent=task, name="BEDMAS", instruction="You follow order of mathematical operation (BEDMAS)", ) r1.save_to_file() - r2 = models.TaskRequirement( + r2 = datamodel.TaskRequirement( parent=task, name="only basic math", instruction="If the problem has anything other than addition, subtraction, multiplication, division, and brackets, you will not answer it. Reply instead with 'I'm just a basic calculator, I don't know how to do that'.", ) r2.save_to_file() - r3 = models.TaskRequirement( + r3 = datamodel.TaskRequirement( parent=task, name="Answer format", instruction="The answer can contain any content about your reasoning, but at the end it should include the final answer in numerals in square brackets. For example if the answer is one hundred, the end of your response should be [100].", @@ -133,7 +133,7 @@ async def run_simple_test(tmp_path: Path, model_name: str, provider: str | None return await run_simple_task(task, model_name, provider) -async def run_simple_task(task: models.Task, model_name: str, provider: str): +async def run_simple_task(task: datamodel.Task, model_name: str, provider: str): adapter = LangChainPromptAdapter(task, model_name=model_name, provider=provider) answer = await adapter.invoke( diff --git a/libs/core/kiln_ai/adapters/test_prompt_builders.py b/libs/core/kiln_ai/adapters/test_prompt_builders.py index 218c1c6..f8525b1 100644 --- a/libs/core/kiln_ai/adapters/test_prompt_builders.py +++ b/libs/core/kiln_ai/adapters/test_prompt_builders.py @@ -4,7 +4,7 @@ from kiln_ai.adapters.prompt_builders import MultiShotPromptBuilder, SimplePromptBuilder from kiln_ai.adapters.test_prompt_adaptors import build_test_task from kiln_ai.adapters.test_structured_output import build_structured_output_test_task -from kiln_ai.datamodel.models import ( +from kiln_ai.datamodel import ( Example, ExampleOutput, ExampleSource, diff --git a/libs/core/kiln_ai/adapters/test_structured_output.py b/libs/core/kiln_ai/adapters/test_structured_output.py index b66f83e..c9bf203 100644 --- a/libs/core/kiln_ai/adapters/test_structured_output.py +++ b/libs/core/kiln_ai/adapters/test_structured_output.py @@ -3,7 +3,7 @@ import jsonschema import jsonschema.exceptions -import kiln_ai.datamodel.models as models +import kiln_ai.datamodel as datamodel import pytest from kiln_ai.adapters.base_adapter import BaseAdapter from kiln_ai.adapters.langchain_adapters import LangChainPromptAdapter @@ -51,7 +51,7 @@ async def test_structured_output_ollama_llama(tmp_path): class MockAdapter(BaseAdapter): - def __init__(self, kiln_task: models.Task, response: Dict | str | None): + def __init__(self, kiln_task: datamodel.Task, response: Dict | str | None): super().__init__(kiln_task) self.response = response @@ -79,8 +79,8 @@ async def test_mock_unstructred_response(tmp_path): answer = await adapter.invoke("You are a mock, send me the response!") # Should error, expecting a string, not a dict - project = models.Project(name="test", path=tmp_path / "test.kiln") - task = models.Task(parent=project, name="test task") + project = datamodel.Project(name="test", path=tmp_path / "test.kiln") + task = datamodel.Task(parent=project, name="test task") task.instruction = ( "You are an assistant which performs math tasks provided in plain text." ) @@ -112,9 +112,9 @@ async def test_all_built_in_models_structured_output(tmp_path): def build_structured_output_test_task(tmp_path: Path): - project = models.Project(name="test", path=tmp_path / "test.kiln") + project = datamodel.Project(name="test", path=tmp_path / "test.kiln") project.save_to_file() - task = models.Task( + task = datamodel.Task( parent=project, name="test task", instruction="You are an assistant which tells a joke, given a subject.", @@ -148,9 +148,9 @@ async def run_structured_output_test(tmp_path: Path, model_name: str, provider: def build_structured_input_test_task(tmp_path: Path): - project = models.Project(name="test", path=tmp_path / "test.kiln") + project = datamodel.Project(name="test", path=tmp_path / "test.kiln") project.save_to_file() - task = models.Task( + task = datamodel.Task( parent=project, name="test task", instruction="You are an assistant which classifies a triangle given the lengths of its sides. If all sides are of equal length, the triangle is equilateral. If two sides are equal, the triangle is isosceles. Otherwise, it is scalene.\n\nAt the end of your response return the result in double square brackets. It should be plain text. It should be exactly one of the three following strings: '[[equilateral]]', or '[[isosceles]]', or '[[scalene]]'.", diff --git a/libs/core/kiln_ai/datamodel/models.py b/libs/core/kiln_ai/datamodel/__init__.py similarity index 99% rename from libs/core/kiln_ai/datamodel/models.py rename to libs/core/kiln_ai/datamodel/__init__.py index c8279a6..048250b 100644 --- a/libs/core/kiln_ai/datamodel/models.py +++ b/libs/core/kiln_ai/datamodel/__init__.py @@ -13,7 +13,7 @@ from .json_schema import validate_schema if TYPE_CHECKING: - from .models import Task + from . import Task # Conventions: # 1) Names are filename safe as they may be used as file names. They are informational and not to be used in prompts/training/validation. diff --git a/libs/core/kiln_ai/datamodel/test_example_models.py b/libs/core/kiln_ai/datamodel/test_example_models.py index 16d5ddd..74a70eb 100644 --- a/libs/core/kiln_ai/datamodel/test_example_models.py +++ b/libs/core/kiln_ai/datamodel/test_example_models.py @@ -1,7 +1,7 @@ import json import pytest -from kiln_ai.datamodel.models import ( +from kiln_ai.datamodel import ( Example, ExampleOutput, ExampleOutputSource, diff --git a/libs/core/kiln_ai/datamodel/test_models.py b/libs/core/kiln_ai/datamodel/test_models.py index 0b7ffd0..7bd828e 100644 --- a/libs/core/kiln_ai/datamodel/test_models.py +++ b/libs/core/kiln_ai/datamodel/test_models.py @@ -1,7 +1,7 @@ import json import pytest -from kiln_ai.datamodel.models import Priority, Project, Task, TaskDeterminism +from kiln_ai.datamodel import Priority, Project, Task, TaskDeterminism from kiln_ai.datamodel.test_json_schema import json_joke_schema from pydantic import ValidationError