Skip to content

Commit

Permalink
Merge pull request #13 from Kiln-AI/uv
Browse files Browse the repository at this point in the history
UV docs
  • Loading branch information
scosman authored Oct 30, 2024
2 parents ede24d2 + da02551 commit abcc646
Show file tree
Hide file tree
Showing 50 changed files with 7,138 additions and 237 deletions.
32 changes: 19 additions & 13 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,41 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: 3.12
cache: "pip"
enable-cache: true

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- run: pip install -r requirements.txt
- run: pip install -r dev-requirements.txt
- name: Install the project
run: uv sync --all-extras --dev

# Remove this later: needed as server expects this dir to exist
- name: Mock Studio Web UI
run: mkdir -p ./app/web_ui/build && echo "test" > ./app/web_ui/build/index.html

- name: Test All Python
run: python3 -m pytest .
run: uv run python3 -m pytest .

- name: Check Python Types
run: pyright .

- name: Install Core
run: poetry install
working-directory: ./libs/core
run: uv run pyright .

- name: Build Core
run: poetry build
run: uv build
working-directory: ./libs/core

- name: Build Server
run: poetry build
run: uv build
working-directory: ./libs/server
18 changes: 11 additions & 7 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,27 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: 3.12
cache: "pip"
enable-cache: true

- name: Set up Python
run: uv python install

- run: pip install -r requirements.txt
- run: pip install -r dev-requirements.txt
- name: Install the project
run: uv sync --all-extras --dev

- name: Build Python Core Docs
working-directory: ./libs/core
run: pdoc -o ./docs/kiln_core_docs kiln_ai --logo https://github.com/user-attachments/assets/046f44ae-28cf-4c78-85c3-c3e5ad744fd7 --logo-link https://kiln-ai.com
run: uv run pdoc -o ./docs/kiln_core_docs kiln_ai --logo https://github.com/user-attachments/assets/046f44ae-28cf-4c78-85c3-c3e5ad744fd7 --logo-link https://getkiln.ai

- name: Install Redoc CLI
run: npm install -g @redocly/cli

- name: Build OpenAPI Docs
run: python -m libs.server.kiln_server.generate_openapi && mkdir ./libs/core/docs/kiln_server_openapi_docs && npx @redocly/cli build-docs openapi.json -o ./libs/core/docs/kiln_server_openapi_docs/index.html
run: uv run python -m libs.server.kiln_server.generate_openapi && mkdir ./libs/core/docs/kiln_server_openapi_docs && npx @redocly/cli build-docs openapi.json -o ./libs/core/docs/kiln_server_openapi_docs/index.html

- name: Setup Pages
id: pages
Expand Down
30 changes: 17 additions & 13 deletions .github/workflows/format_and_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.9
go-version: "^1.22"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
- name: Lint with ruff
run: |
ruff check --select I .
- name: Format with ruff
run: |
ruff format --check .
- name: Download go misspell
run: go install github.com/client9/misspell/cmd/misspell@latest
- name: Run misspell
run: misspell -error .

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Set up Python
run: uv python install

- name: Install the project
run: uv tool install ruff

- name: Lint with ruff
run: |
uvx ruff check --select I .
- name: Format with ruff
run: |
uvx ruff format --check .
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ __pycache__/
*.py[cod]
*$py.class
.coverage
**/.venv

libs/core/docs
libs/core/build
libs/server/build

dist/
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| CI | [![Build and Test](https://github.com/Kiln-AI/kiln/actions/workflows/build_and_test.yml/badge.svg)](https://github.com/Kiln-AI/kiln/actions/workflows/build_and_test.yml) [![Format and Lint](https://github.com/Kiln-AI/kiln/actions/workflows/format_and_lint.yml/badge.svg)](https://github.com/Kiln-AI/kiln/actions/workflows/format_and_lint.yml) [![Desktop Apps Build](https://github.com/Kiln-AI/kiln/actions/workflows/build_desktop.yml/badge.svg)](https://github.com/Kiln-AI/kiln/actions/workflows/build_desktop.yml) [![Web UI Build](https://github.com/Kiln-AI/kiln/actions/workflows/web_format_lint_build.yml/badge.svg)](https://github.com/Kiln-AI/kiln/actions/workflows/web_format_lint_build.yml) [![Test Count Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/scosman/57742c1b1b60d597a6aba5d5148d728e/raw/test_count_kiln.json)](https://github.com/Kiln-AI/kiln/actions/workflows/test_count.yml) [![Test Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/scosman/57742c1b1b60d597a6aba5d5148d728e/raw/library_coverage_kiln.json)](https://github.com/Kiln-AI/kiln/actions/workflows/test_count.yml) [![Docs](https://github.com/Kiln-AI/Kiln/actions/workflows/build_docs.yml/badge.svg)](https://github.com/Kiln-AI/Kiln/actions/workflows/build_docs.yml) |
| Package | [![PyPI - Version](https://img.shields.io/pypi/v/kiln-ai.svg?logo=pypi&label=PyPI&logoColor=gold)](https://pypi.org/project/kiln-ai/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/kiln-ai.svg?logo=python&label=Python&logoColor=gold)](https://pypi.org/project/kiln-ai/) |
| Meta | [![linting - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/) [![types - Mypy](https://img.shields.io/badge/types-pyright-blue.svg)](https://github.com/microsoft/pyright) [![Docs](https://img.shields.io/badge/docs-pdoc-blue)](https://kiln-ai.github.io/Kiln/kiln_core_docs/index.html) |
| Meta | [![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv) [![linting - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch) [![types - Pyright](https://img.shields.io/badge/types-pyright-blue.svg)](https://github.com/microsoft/pyright) [![Docs](https://img.shields.io/badge/docs-pdoc-blue)](https://kiln-ai.github.io/Kiln/kiln_core_docs/index.html) |

# Kiln AI

Expand Down Expand Up @@ -69,7 +69,7 @@ Currently, we support about a dozen models and a variety of prompting solutions

If you have a data science team and want to go deeper, our Python library has everything you need. Ingest the Kiln data format into your pipeline. Create custom evaluations. Use Kiln data in notebooks. Build fine-tunes. Extend or replace any part of the pipeline.

We also offer a REST API for integrating Kiln into your own tools and workflows.
We also offer [a REST API package](https://pypi.org/project/kiln-server/) for integrating Kiln into your own tools and workflows.

## Status

Expand All @@ -90,9 +90,9 @@ cd app/web_ui
npm install
```

Run the API server and Web UI with auto-reload for development:
Run the API server, Studio server, and Studio Web UI with auto-reload for development:

- Run the Python server: `AUTO_RELOAD=true python -m libs.server.kiln_server.server`
- Run the Python server: `python -m app.desktop.dev_server`
- Run the Web UI from the `app/web_ui` directory: `npm run dev --`
- Open the app: http://localhost:5173/run

Expand Down
1 change: 1 addition & 0 deletions app/desktop/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
39 changes: 39 additions & 0 deletions app/desktop/custom_tray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import io
import sys

import pystray


class KilnTray(pystray.Icon):
# Special handling for Mac to support dark/light mode and retina icons
# lots of type ignores because we're accessing private attributes of pystray
def X_assert_image(self):
if sys.platform != "darwin":
super()._assert_image() # type: ignore
return

import AppKit
import Foundation

thickness = self._status_bar.thickness() # type: ignore
logical_size = (int(thickness), int(thickness))
if self._icon_image and self._icon_image.size() == logical_size:
return

source = self._icon

# Convert the PIL image to an NSImage
b = io.BytesIO()
source.save(b, "png") # type: ignore
data = Foundation.NSData(b.getvalue()) # type: ignore

self._icon_image = AppKit.NSImage.alloc().initWithData_(data) # type: ignore
try:
# template image will respect dark/light mode
self._icon_image.setTemplate_(True)
# set the logical size of the image, which will be scaled for retina
self._icon_image.setSize_(logical_size)
except Exception as e:
# Continue, this shouldn't be fatal
print("Mac Tray Error", e)
self._status_item.button().setImage_(self._icon_image) # type: ignore
4 changes: 2 additions & 2 deletions app/desktop/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pystray
from PIL import Image

from app.desktop.custom_tray import KilnTray
from app.desktop.desktop_server import ThreadedServer, server_config

# TODO: remove this and all other globals in this file
Expand Down Expand Up @@ -59,7 +60,6 @@ def on_quit():


def run_taskbar():
# TODO: resolution
image = Image.open(resource_path("taskbar.png"))
# Use default on Windows to get "left click to open" behaviour. But it looks ugle on MacOS, so don't use it there
make_open_studio_default = sys.platform == "Windows"
Expand All @@ -70,7 +70,7 @@ def run_taskbar():
pystray.MenuItem("Quit", on_quit),
)
global tray
tray = pystray.Icon("kiln", image, "kiln", menu)
tray = KilnTray("kiln", image, "Kiln", menu)
# running detached since we use tk mainloop to get events from dock icon
tray.run_detached()
return tray
Expand Down
14 changes: 14 additions & 0 deletions app/desktop/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "kiln-studio-desktop"
version = "0.1.0"
description = "The Kiln Desktop App. Download from https://getkiln.ai"
requires-python = ">=3.10"
dependencies = [
"kiln-server",
"pillow>=11.0.0",
"pyinstaller>=6.11.0",
"pystray>=0.19.5",
]

[tool.uv.sources]
kiln-server = { workspace = true }
54 changes: 34 additions & 20 deletions app/desktop/studio_server/test_provider_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,23 @@ async def test_get_available_models(app, client):
message="Connected", models=["ollama_model1", "ollama_model2"]
)

with patch(
"app.desktop.studio_server.provider_api.Config.shared", return_value=mock_config
), patch(
"app.desktop.studio_server.provider_api.provider_warnings",
mock_provider_warnings,
), patch(
"app.desktop.studio_server.provider_api.built_in_models", mock_built_in_models
), patch(
"app.desktop.studio_server.provider_api.connect_ollama",
return_value=mock_ollama_connection,
with (
patch(
"app.desktop.studio_server.provider_api.Config.shared",
return_value=mock_config,
),
patch(
"app.desktop.studio_server.provider_api.provider_warnings",
mock_provider_warnings,
),
patch(
"app.desktop.studio_server.provider_api.built_in_models",
mock_built_in_models,
),
patch(
"app.desktop.studio_server.provider_api.connect_ollama",
return_value=mock_ollama_connection,
),
):
response = client.get("/api/available_models")

Expand Down Expand Up @@ -405,16 +412,23 @@ async def test_get_available_models_ollama_exception(app, client):
]

# Mock connect_ollama to raise an HTTPException
with patch(
"app.desktop.studio_server.provider_api.Config.shared", return_value=mock_config
), patch(
"app.desktop.studio_server.provider_api.provider_warnings",
mock_provider_warnings,
), patch(
"app.desktop.studio_server.provider_api.built_in_models", mock_built_in_models
), patch(
"app.desktop.studio_server.provider_api.connect_ollama",
side_effect=HTTPException(status_code=500),
with (
patch(
"app.desktop.studio_server.provider_api.Config.shared",
return_value=mock_config,
),
patch(
"app.desktop.studio_server.provider_api.provider_warnings",
mock_provider_warnings,
),
patch(
"app.desktop.studio_server.provider_api.built_in_models",
mock_built_in_models,
),
patch(
"app.desktop.studio_server.provider_api.connect_ollama",
side_effect=HTTPException(status_code=500),
),
):
response = client.get("/api/available_models")

Expand Down
2 changes: 1 addition & 1 deletion app/desktop/studio_server/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_cors_allowed_origins(client, origin):
"origin",
[
"http://example.com",
"https://kiln-ai.com",
"https://getkiln.ai",
"http://192.168.1.100",
"http://localhost.com",
"http://127.0.0.2",
Expand Down
2 changes: 1 addition & 1 deletion app/web_ui/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const WebsiteName: string = "Kiln Studio"
export const WebsiteBaseUrl: string = "https://kiln-ai.com"
export const WebsiteBaseUrl: string = "https://getkiln.ai"
export const WebsiteDescription: string = "Build ML Products with Kiln Studio"
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
["basic", "Basic Prompt (Zero Shot)"],
["few_shot", "Few Shot"],
["many_shot", "Many Shot"],
["repairs", "Repair Multi Shot"],
]}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
{project.description}
</div>
{/if}
<div class="text-xs text-gray-500 mt-1">
<div class="text-xs text-gray-500 mt-1 break-all">
{project.path}
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Check our project: formatting, linting, testing, building, etc.
# Good to call this from .git/hooks/pre-commit

# Important: run with `uv run` to setup the environment

set -e

# work from the root of the repo
Expand Down
15 changes: 0 additions & 15 deletions dev-requirements.txt

This file was deleted.

11 changes: 0 additions & 11 deletions environment.yml

This file was deleted.

1 change: 1 addition & 0 deletions libs/core/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
Loading

0 comments on commit abcc646

Please sign in to comment.