Skip to content

Commit

Permalink
Better prompt model: description instead of weird "long_name"
Browse files Browse the repository at this point in the history
  • Loading branch information
scosman committed Feb 28, 2025
1 parent e514d63 commit 13b51a0
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 25 deletions.
5 changes: 1 addition & 4 deletions app/desktop/studio_server/eval_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,7 @@ async def create_task_run_config(
prompt_name = generate_memorable_name()
frozen_prompt = BasePrompt(
name=prompt_name,
long_name=prompt_name
+ " (frozen prompt from '"
+ request.prompt_id
+ "')",
description=f"Frozen copy of prompt '{request.prompt_id}'",
generator_id=request.prompt_id,
prompt=prompt_builder.build_base_prompt(),
chain_of_thought_instructions=prompt_builder.chain_of_thought_prompt(),
Expand Down
8 changes: 4 additions & 4 deletions app/desktop/studio_server/test_eval_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ async def test_create_task_run_config_with_freezing(
)
assert result["prompt"]["name"] == "Custom Name"
assert (
result["prompt"]["long_name"]
== "Custom Name (frozen prompt from 'simple_chain_of_thought_prompt_builder')"
result["prompt"]["description"]
== "Frozen copy of prompt 'simple_chain_of_thought_prompt_builder'"
)
# Fetch it from API
fetch_response = client.get("/api/projects/project1/tasks/task1/task_run_configs")
Expand All @@ -279,8 +279,8 @@ async def test_create_task_run_config_with_freezing(
assert configs[0]["id"] == result["id"]
assert configs[0]["name"] == result["name"]
assert configs[0]["prompt"]["name"] == "Custom Name"
assert configs[0]["prompt"]["long_name"] == (
"Custom Name (frozen prompt from 'simple_chain_of_thought_prompt_builder')"
assert configs[0]["prompt"]["description"] == (
"Frozen copy of prompt 'simple_chain_of_thought_prompt_builder'"
)
assert configs[0]["run_config_properties"]["prompt_id"] == (
"task_run_config::project1::task1::" + result["id"]
Expand Down
20 changes: 11 additions & 9 deletions app/web_ui/src/lib/api_schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -907,10 +907,10 @@ export interface components {
*/
name: string;
/**
* Long Name
* @description A more detailed name for the prompt, usually incorporating the source of the prompt.
* Description
* @description A more detailed description of the prompt.
*/
long_name?: string | null;
description?: string | null;
/**
* Generator Id
* @description The id of the generator that created this prompt.
Expand Down Expand Up @@ -955,10 +955,10 @@ export interface components {
*/
name: string;
/**
* Long Name
* @description A more detailed name for the prompt, usually incorporating the source of the prompt.
* Description
* @description A more detailed description of the prompt.
*/
long_name?: string | null;
description?: string | null;
/**
* Generator Id
* @description The id of the generator that created this prompt.
Expand Down Expand Up @@ -1925,10 +1925,10 @@ export interface components {
*/
name: string;
/**
* Long Name
* @description A more detailed name for the prompt, usually incorporating the source of the prompt.
* Description
* @description A more detailed description of the prompt.
*/
long_name?: string | null;
description?: string | null;
/**
* Generator Id
* @description The id of the generator that created this prompt.
Expand Down Expand Up @@ -1974,6 +1974,8 @@ export interface components {
PromptCreateRequest: {
/** Name */
name: string;
/** Description */
description?: string | null;
/** Prompt */
prompt: string;
/** Chain Of Thought Instructions */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,7 @@
</div>
<div class="text-sm text-gray-500">
Prompt:
{task_run_config.prompt?.long_name ||
task_run_config.prompt?.name ||
{task_run_config.prompt?.name ||
prompt_name_from_id(
task_run_config?.run_config_properties?.prompt_id,
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
$: task_name = $current_task?.id == task_id ? $current_task?.name : "unknown"
let prompt_name = ""
let prompt_description = ""
let prompt = ""
let is_chain_of_thought = false
let chain_of_thought_instructions =
Expand All @@ -35,6 +36,7 @@
},
body: {
name: prompt_name,
description: prompt_description,
prompt: prompt,
chain_of_thought_instructions: is_chain_of_thought
? chain_of_thought_instructions
Expand All @@ -51,7 +53,7 @@
// Success! Reload then navigate to the new prompt
await load_available_prompts()
goto(`/prompts/${project_id}/${task_id}/saved/${data.id}`)
goto(`/prompts/${project_id}/${task_id}/saved/id::${data.id}`)
} catch (e) {
create_error = createKilnError(e)
} finally {
Expand All @@ -77,6 +79,13 @@
max_length={60}
/>

<FormElement
label="Prompt Description"
id="prompt_description"
bind:value={prompt_description}
description="A description of the prompt for your reference."
/>

<FormElement
label="Prompt"
id="prompt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Object.entries({
ID: prompt_model?.id,
Name: prompt_model?.name,
"Long Name": prompt_model?.long_name,
Description: prompt_model?.description,
"Created By": prompt_model?.created_by,
"Created At": formatDate(prompt_model?.created_at || undefined),
"Chain of Thought": prompt_model?.chain_of_thought_instructions
Expand All @@ -38,7 +38,8 @@
<div class="max-w-[1400px]">
<AppPage
title="Saved Prompt"
subtitle={prompt_model?.long_name || prompt_model?.name}
subtitle={prompt_model?.name}
sub_subtitle={prompt_model?.description || undefined}
>
{#if !$current_task_prompts}
<div class="w-full min-h-[50vh] flex justify-center items-center">
Expand Down
4 changes: 2 additions & 2 deletions libs/core/kiln_ai/datamodel/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class BasePrompt(BaseModel):
"""

name: str = NAME_FIELD
long_name: str | None = Field(
description: str | None = Field(
default=None,
description="A more detailed name for the prompt, usually incorporating the source of the prompt.",
description="A more detailed description of the prompt.",
)
generator_id: str | None = Field(
default=None,
Expand Down
2 changes: 1 addition & 1 deletion libs/core/kiln_ai/datamodel/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from kiln_ai.datamodel.eval import Eval
from kiln_ai.datamodel.json_schema import JsonObjectSchema, schema_from_json_str
from kiln_ai.datamodel.prompt import BasePrompt, Prompt
from kiln_ai.datamodel.prompt_id import PromptGenerators, PromptId
from kiln_ai.datamodel.prompt_id import PromptId
from kiln_ai.datamodel.task_run import TaskRun

if TYPE_CHECKING:
Expand Down
2 changes: 2 additions & 0 deletions libs/server/kiln_server/prompt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ApiPrompt(BasePrompt):

class PromptCreateRequest(BaseModel):
name: str
description: str | None = None
prompt: str
chain_of_thought_instructions: str | None = None

Expand All @@ -42,6 +43,7 @@ async def create_prompt(
prompt = Prompt(
parent=parent_task,
name=prompt_data.name,
description=prompt_data.description,
prompt=prompt_data.prompt,
chain_of_thought_instructions=prompt_data.chain_of_thought_instructions,
)
Expand Down
2 changes: 2 additions & 0 deletions libs/server/kiln_server/test_prompt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_create_prompt_success(client, project_and_task):
prompt_data = {
"name": "Test Prompt",
"prompt": "This is a test prompt",
"description": "This is a test prompt description",
"chain_of_thought_instructions": "Think step by step, explaining your reasoning.",
}

Expand All @@ -58,6 +59,7 @@ def test_create_prompt_success(client, project_and_task):
assert response.status_code == 200
res = response.json()
assert res["name"] == "Test Prompt"
assert res["description"] == "This is a test prompt description"
assert res["prompt"] == "This is a test prompt"

# Check that the prompt was saved to the task/file
Expand Down

0 comments on commit 13b51a0

Please sign in to comment.