Skip to content

Commit 104dbe7

Browse files
authored
Merge branch 'main' into fixes
2 parents e0a42c6 + 12a8b41 commit 104dbe7

File tree

16 files changed

+250
-275
lines changed

16 files changed

+250
-275
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -77,77 +77,3 @@ jobs:
7777
- name: Test frontend
7878
working-directory: ./frontend
7979
run: npm test
80-
81-
update-schemas:
82-
name: Update generated schemas
83-
84-
runs-on: ubuntu-latest
85-
86-
# Only run on push to main/master, not on PRs
87-
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
88-
89-
permissions:
90-
contents: write
91-
pull-requests: write
92-
93-
steps:
94-
- uses: actions/checkout@v4
95-
with:
96-
token: ${{ secrets.GITHUB_TOKEN }}
97-
98-
- name: Use Node.js 22.x
99-
uses: actions/setup-node@v4
100-
with:
101-
node-version: 22.x
102-
103-
- name: Set up Python
104-
uses: actions/setup-python@v5
105-
with:
106-
python-version: '3.12'
107-
108-
- name: Install uv
109-
uses: astral-sh/setup-uv@v4
110-
111-
- name: Install dependencies
112-
run: |
113-
npm install
114-
cd scripts && uv sync
115-
116-
- name: Build utils
117-
working-directory: ./utils
118-
run: npm run build
119-
120-
- name: Regenerate schemas
121-
run: |
122-
cd utils && npx tsx src/export-schemas.ts
123-
npx prettier --write ../docs/assets/api/schemas.json
124-
cd ../scripts && uv run datamodel-codegen \
125-
--input ../docs/assets/api/schemas.json \
126-
--output deliberate_lab/types.py \
127-
--input-file-type jsonschema \
128-
--reuse-model \
129-
--collapse-root-models \
130-
--use-union-operator \
131-
--use-title-as-name \
132-
--output-model-type pydantic_v2.BaseModel \
133-
--custom-file-header $'# pyright: reportInvalidTypeForm=false\n# pylint: disable=missing-module-docstring,missing-class-docstring,invalid-name,too-few-public-methods'
134-
135-
- name: Format Python files
136-
run: |
137-
cd scripts && uvx black deliberate_lab/
138-
139-
- name: Validate generated Python
140-
run: |
141-
cd scripts && uv run pyright deliberate_lab/
142-
143-
- name: Create PR if schemas changed
144-
uses: peter-evans/create-pull-request@v8
145-
with:
146-
token: ${{ secrets.GITHUB_TOKEN }}
147-
commit-message: "chore: update generated schemas and Python types"
148-
title: "chore: update generated schemas and Python types"
149-
body: "🤖 Auto-generated by GitHub Actions"
150-
branch: auto-update-schemas
151-
add-paths: |
152-
docs/assets/api/schemas.json
153-
scripts/deliberate_lab/

docs/assets/api/schemas.json

Lines changed: 49 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@
341341
"items": {
342342
"type": "string"
343343
}
344+
},
345+
"youtubeVideoId": {
346+
"type": "string"
344347
}
345348
},
346349
"required": [
@@ -1005,28 +1008,9 @@
10051008
"type": "string"
10061009
},
10071010
"type": {
1008-
"allOf": [
1009-
{
1010-
"anyOf": [
1011-
{
1012-
"const": "static",
1013-
"type": "string"
1014-
},
1015-
{
1016-
"const": "random_permutation",
1017-
"type": "string"
1018-
},
1019-
{
1020-
"const": "balanced_assignment",
1021-
"type": "string"
1022-
}
1023-
]
1024-
},
1025-
{
1026-
"const": "static",
1027-
"type": "string"
1028-
}
1029-
]
1011+
"default": "static",
1012+
"const": "static",
1013+
"type": "string"
10301014
},
10311015
"scope": {
10321016
"anyOf": [
@@ -1255,28 +1239,9 @@
12551239
"type": "string"
12561240
},
12571241
"type": {
1258-
"allOf": [
1259-
{
1260-
"anyOf": [
1261-
{
1262-
"const": "static",
1263-
"type": "string"
1264-
},
1265-
{
1266-
"const": "random_permutation",
1267-
"type": "string"
1268-
},
1269-
{
1270-
"const": "balanced_assignment",
1271-
"type": "string"
1272-
}
1273-
]
1274-
},
1275-
{
1276-
"const": "random_permutation",
1277-
"type": "string"
1278-
}
1279-
]
1242+
"default": "random_permutation",
1243+
"const": "random_permutation",
1244+
"type": "string"
12801245
},
12811246
"scope": {
12821247
"anyOf": [
@@ -1363,28 +1328,9 @@
13631328
"type": "string"
13641329
},
13651330
"type": {
1366-
"allOf": [
1367-
{
1368-
"anyOf": [
1369-
{
1370-
"const": "static",
1371-
"type": "string"
1372-
},
1373-
{
1374-
"const": "random_permutation",
1375-
"type": "string"
1376-
},
1377-
{
1378-
"const": "balanced_assignment",
1379-
"type": "string"
1380-
}
1381-
]
1382-
},
1383-
{
1384-
"const": "balanced_assignment",
1385-
"type": "string"
1386-
}
1387-
]
1331+
"default": "balanced_assignment",
1332+
"const": "balanced_assignment",
1333+
"type": "string"
13881334
},
13891335
"scope": {
13901336
"anyOf": [
@@ -1894,9 +1840,45 @@
18941840
},
18951841
"progress": {
18961842
"$ref": "#/$defs/StageProgressConfig"
1843+
},
1844+
"timeLimitInMinutes": {
1845+
"anyOf": [
1846+
{
1847+
"type": "number"
1848+
},
1849+
{
1850+
"type": "null"
1851+
}
1852+
]
1853+
},
1854+
"requireFullTime": {
1855+
"type": "boolean"
1856+
},
1857+
"isTurnBasedChat": {
1858+
"type": "boolean"
1859+
},
1860+
"minNumberOfTurns": {
1861+
"type": "number"
1862+
},
1863+
"maxNumberOfTurns": {
1864+
"anyOf": [
1865+
{
1866+
"type": "number"
1867+
},
1868+
{
1869+
"type": "null"
1870+
}
1871+
]
18971872
}
18981873
},
1899-
"required": ["id", "kind", "name", "descriptions", "progress"],
1874+
"required": [
1875+
"id",
1876+
"kind",
1877+
"name",
1878+
"descriptions",
1879+
"progress",
1880+
"timeLimitInMinutes"
1881+
],
19001882
"title": "PrivateChatStageConfig"
19011883
},
19021884
"ProfileStageConfig": {

frontend/src/components/experiment_builder/structured_prompt_editor.ts

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,26 @@ import {CSSResultGroup, html, nothing, TemplateResult} from 'lit';
88
import {customElement, property} from 'lit/decorators.js';
99

1010
import {core} from '../../core/core';
11-
import {AuthService} from '../../services/auth.service';
1211
import {ExperimentEditor} from '../../services/experiment.editor';
1312
import {renderConditionEditor} from '../../shared/condition_editor.utils';
1413

1514
import {
1615
Condition,
16+
ConditionOperator,
1717
ConditionTarget,
18+
createConditionGroup,
19+
createDefaultPromptItemGroup,
20+
createDefaultStageContextPromptItem,
21+
createShuffleConfig,
22+
getConditionTargetsFromStages,
1823
PromptItem,
19-
PromptItemType,
2024
PromptItemGroup,
25+
PromptItemType,
26+
SeedStrategy,
27+
ShuffleConfig,
2128
StageContextPromptItem,
2229
StageKind,
2330
TextPromptItem,
24-
createDefaultStageContextPromptItem,
25-
createDefaultPromptItemGroup,
26-
getConditionTargetsFromStages,
27-
ShuffleConfig,
28-
SeedStrategy,
29-
createShuffleConfig,
3031
} from '@deliberation-lab/utils';
3132

3233
import {styles} from './structured_prompt_editor.scss';
@@ -36,7 +37,6 @@ import {styles} from './structured_prompt_editor.scss';
3637
export class EditorComponent extends MobxLitElement {
3738
static override styles: CSSResultGroup = [styles];
3839

39-
private readonly authService = core.getService(AuthService);
4040
private readonly experimentEditor = core.getService(ExperimentEditor);
4141

4242
@property() prompt: PromptItem[] = [];
@@ -213,13 +213,32 @@ export class EditorComponent extends MobxLitElement {
213213
}
214214

215215
const conditionTargets = this.getConditionTargets();
216+
const supportsConditions =
217+
this.supportsConditions() && conditionTargets.length > 0;
218+
219+
return items.map((item, index) => {
220+
const hasCondition = item.condition !== undefined;
216221

217-
return items.map(
218-
(item, index) => html`
222+
return html`
219223
<div class="prompt-item-wrapper ${isNested ? 'nested' : ''}">
220224
<div class="prompt-item-row">
221225
<div class="prompt-item-editor">${this.renderItemEditor(item)}</div>
222226
<div class="prompt-item-actions">
227+
${supportsConditions && item.type !== PromptItemType.GROUP
228+
? html`
229+
<pr-icon-button
230+
icon="rule"
231+
color=${hasCondition ? 'primary' : 'neutral'}
232+
variant="default"
233+
size="small"
234+
title=${hasCondition
235+
? 'Remove display condition'
236+
: 'Add display condition'}
237+
@click=${() => this.toggleCondition(item)}
238+
>
239+
</pr-icon-button>
240+
`
241+
: nothing}
223242
<pr-icon-button
224243
icon="arrow_upward"
225244
color="neutral"
@@ -246,43 +265,44 @@ export class EditorComponent extends MobxLitElement {
246265
</pr-icon-button>
247266
</div>
248267
</div>
249-
${this.renderPromptItemCondition(item, conditionTargets)}
268+
${hasCondition
269+
? this.renderPromptItemCondition(item, conditionTargets)
270+
: nothing}
250271
</div>
251-
`,
252-
);
272+
`;
273+
});
274+
}
275+
276+
private toggleCondition(item: PromptItem) {
277+
if (item.condition !== undefined) {
278+
// Remove condition
279+
this.updatePromptItem(item, {condition: undefined});
280+
} else {
281+
// Add an empty condition group - user will add conditions via the editor
282+
this.updatePromptItem(item, {
283+
condition: createConditionGroup(ConditionOperator.AND, []),
284+
});
285+
}
253286
}
254287

255288
private renderPromptItemCondition(
256289
item: PromptItem,
257290
conditionTargets: ConditionTarget[],
258291
) {
259-
// Don't show condition editor for GROUP items (they contain other items that can have conditions)
260-
if (item.type === PromptItemType.GROUP) {
261-
return nothing;
262-
}
263-
264-
// Conditions are only supported for private chat stages (not group chat)
265-
if (!this.supportsConditions()) {
266-
return nothing;
267-
}
268-
269292
const onConditionChange = (condition: Condition | undefined) => {
270293
this.updatePromptItem(item, {condition});
271294
};
272295

273-
const conditionEditor = renderConditionEditor({
274-
condition: item.condition,
275-
targets: conditionTargets,
276-
showAlphaFeatures: this.authService.showAlphaFeatures,
277-
canEdit: this.experimentEditor.canEditStages,
278-
onConditionChange,
279-
});
280-
281-
if (conditionEditor === nothing) {
282-
return nothing;
283-
}
284-
285-
return html` <div class="prompt-item-condition">${conditionEditor}</div> `;
296+
return html`
297+
<div class="prompt-item-condition">
298+
${renderConditionEditor({
299+
condition: item.condition,
300+
targets: conditionTargets,
301+
canEdit: this.experimentEditor.canEditStages,
302+
onConditionChange,
303+
})}
304+
</div>
305+
`;
286306
}
287307

288308
private renderTextPromptItemEditor(item: TextPromptItem) {

0 commit comments

Comments
 (0)