-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
185 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ class TrialCreateBase(TrialBase): | |
|
||
|
||
class TrialCreate(TrialCreateBase): | ||
experiment_id: UUID | ||
name: str | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,8 +69,4 @@ | |
{/if} | ||
|
||
<style lang="scss"> | ||
.table-header { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
studio/src/routes/(app)/experiments/[id]/trials/new/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<script lang="ts"> | ||
import type { PageData } from './$types'; | ||
import { goto } from '$app/navigation'; | ||
import { PUBLIC_API_BASE_URL } from '$env/static/public'; | ||
import Block from '$lib/UI/Block.svelte'; | ||
import Select from '$lib/UI/Select.svelte'; | ||
import { superForm, setMessage, setError } from 'sveltekit-superforms'; | ||
import { _newTrialSchema } from './+page'; | ||
import { zod } from 'sveltekit-superforms/adapters'; | ||
export let data: PageData; | ||
$: ({experiment, params, registryOptions} = data) | ||
const { form, errors, message, constraints, enhance, isTainted } = superForm(data.form, { | ||
SPA: true, | ||
dataType: 'json', | ||
validators: zod(_newTrialSchema), | ||
onUpdate({ form }) { | ||
if (form.valid) { | ||
handleSubmit(form.data) | ||
} | ||
} | ||
}); | ||
let handleSubmit = async (formData: any) => { | ||
let url = `${PUBLIC_API_BASE_URL}experiments/${experiment.id}/trials`; | ||
await fetch(url, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(formData) | ||
}) | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
goto(`/playground/${data.id}`); | ||
}) | ||
.catch((error) => { | ||
console.error('Error:', error); | ||
}); | ||
}; | ||
</script> | ||
|
||
<h2>New Trial</h2> | ||
<Block> | ||
{#if $message}<div>{$message}</div>{/if} | ||
<form use:enhance> | ||
<div> | ||
|
||
Create a new Trial for experiment <b>#{experiment.index} {experiment.name}</b>. | ||
</div> | ||
|
||
<p>Choose from the following:</p> | ||
|
||
<label> | ||
Name | ||
<input | ||
aria-invalid={$errors.name ? 'true' : undefined} | ||
bind:value={$form.name} | ||
{...$constraints.name} | ||
/> | ||
</label> | ||
{#if $errors.name}<span class="invalid">{$errors.name}</span>{/if} | ||
<Select | ||
ariaInvalid={$errors.fqn ? 'true' : undefined} | ||
bind:value={$form.fqn} | ||
{...$constraints.fqn} | ||
options={data.registryOptions} | ||
label="LTM" | ||
emptyLabel="Select LTM" | ||
/> | ||
{#if $errors.fqn && isTainted('fqn')}<span class="invalid">{$errors.fqn}</span>{/if} | ||
<label> | ||
Inputs (JSON) | ||
<textarea | ||
aria-invalid={$errors.inputs ? 'true' : undefined} | ||
bind:value={$form.inputs} | ||
{...$constraints.inputs} | ||
/> | ||
</label> | ||
{#if $errors.inputs}<span class="invalid">{$errors.inputs}</span>{/if} | ||
|
||
<div class="buttons full-width"> | ||
<a class="button secondary large" href="/experiments">Cancel</a> | ||
<button type="submit" class="primary large">Create Trial</button> | ||
</div> | ||
</form> | ||
</Block> |
41 changes: 41 additions & 0 deletions
41
studio/src/routes/(app)/experiments/[id]/trials/new/+page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { PageLoad } from './$types'; | ||
import { error } from '@sveltejs/kit'; | ||
import { superValidate } from 'sveltekit-superforms'; | ||
import { zod } from 'sveltekit-superforms/adapters'; | ||
import { z } from 'zod'; | ||
import { PUBLIC_API_BASE_URL } from '$env/static/public'; | ||
import { getRegistry } from '$lib/registry'; | ||
|
||
let registryOptions: any = []; | ||
|
||
const newTrialInitial = { | ||
name: 'Trial', | ||
fqn: undefined, | ||
}; | ||
|
||
export const _newTrialSchema = z.object({ | ||
name: z.string().default('Trial'), | ||
fqn: z.string() | ||
.refine((data: any) => { | ||
const validFQNs = registryOptions.map((option: any) => option[0]); | ||
return validFQNs.includes(data); | ||
}, { | ||
message: 'Invalid LTM', | ||
}), | ||
inputs: z.string().optional() | ||
}); | ||
|
||
export const load: PageLoad = async ({ params, fetch }) => { | ||
|
||
const experiment = fetch(`${PUBLIC_API_BASE_URL}experiments/${params.id}`) | ||
.then((response) => response.json()) | ||
.catch((error) => { | ||
console.log(error); | ||
return []; | ||
}); | ||
registryOptions = await getRegistry(fetch); | ||
|
||
const form = await superValidate(newTrialInitial, zod(_newTrialSchema)); | ||
|
||
return { form, registryOptions, params, experiment: await experiment }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters