mirror of
https://ghfast.top/https://github.com/discourse/discourse-ai.git
synced 2026-07-16 11:36:23 +08:00
Examples simulate previous interactions with an LLM and come right after the system prompt. This helps grounding the model and producing better responses.
67 lines
1.8 KiB
Text
67 lines
1.8 KiB
Text
import Component from "@glimmer/component";
|
|
import { tracked } from "@glimmer/tracking";
|
|
import { concat } from "@ember/helper";
|
|
import { on } from "@ember/modifier";
|
|
import { action } from "@ember/object";
|
|
import { eq } from "truth-helpers";
|
|
import icon from "discourse/helpers/d-icon";
|
|
import { i18n } from "discourse-i18n";
|
|
|
|
export default class AiPersonaCollapsableExample extends Component {
|
|
@tracked collapsed = true;
|
|
|
|
get caretIcon() {
|
|
return this.collapsed ? "angle-right" : "angle-down";
|
|
}
|
|
|
|
@action
|
|
toggleExample() {
|
|
this.collapsed = !this.collapsed;
|
|
}
|
|
|
|
@action
|
|
deletePair() {
|
|
this.collapsed = true;
|
|
this.args.examplesCollection.remove(this.args.exampleNumber);
|
|
}
|
|
|
|
get exampleTitle() {
|
|
return i18n("discourse_ai.ai_persona.examples.collapsable_title", {
|
|
number: this.args.exampleNumber + 1,
|
|
});
|
|
}
|
|
|
|
<template>
|
|
<div role="button" {{on "click" this.toggleExample}}>
|
|
<span>{{icon this.caretIcon}}</span>
|
|
{{this.exampleTitle}}
|
|
</div>
|
|
{{#unless this.collapsed}}
|
|
<@examplesCollection.Collection as |exPair pairIdx|>
|
|
<exPair.Field
|
|
@title={{i18n
|
|
(concat
|
|
"discourse_ai.ai_persona.examples."
|
|
(if (eq pairIdx 0) "user" "model")
|
|
)
|
|
}}
|
|
@validation="required|length:1,100"
|
|
@disabled={{@system}}
|
|
as |field|
|
|
>
|
|
<field.Textarea />
|
|
</exPair.Field>
|
|
</@examplesCollection.Collection>
|
|
|
|
{{#unless @system}}
|
|
<@form.Container>
|
|
<@form.Button
|
|
@action={{this.deletePair}}
|
|
@label="discourse_ai.ai_persona.examples.remove"
|
|
class="ai-persona-editor__delete_example btn-danger"
|
|
/>
|
|
</@form.Container>
|
|
{{/unless}}
|
|
{{/unless}}
|
|
</template>
|
|
}
|