Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stop to regex #81

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions apps/gui/src/editor/extensions/LmGenerator/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
GenerationNodeTypeLabels,
ALL_GENERATION_NODE_TYPES,
} from "@lmscript/editor-tools/types";
import { assertIsNever } from "../../../lib/utils";
import { assertIsNever, cn } from "../../../lib/utils";

type ChoicesOption = {
label: string;
Expand Down Expand Up @@ -121,20 +121,22 @@ const STOP_AT_OPTIONS: ReactSelectOption[] = [
const StopEditor: FC<{
stop: string[];
onChange: (choices: readonly string[]) => void;
}> = ({ stop, onChange }) => {
leftMargin: boolean;
placeholder: string;
}> = ({ leftMargin, placeholder, stop, onChange }) => {
return (
<StyledCreatableReactSelect
classNames={{
container: () => "inline-block",
control: () => "rounded-none",
control: () => cn("rounded-none", !leftMargin && "border-0 border-y border-r"),
}}
isMulti={true}
value={stop.map((it) => ({
label: STOP_AT_OPTIONS.find((option) => option.value === it)?.label ?? it,
value: it,
}))}
options={STOP_AT_OPTIONS}
placeholder="Type to create. Always includes end of message."
placeholder={placeholder}
noOptionsMessage={() => "Type to create..."}
isClearable={false}
onChange={(newOptions) => {
Expand Down Expand Up @@ -201,7 +203,12 @@ const InnerGenerator: FC<{
switch (attrs.type) {
case "generation":
return (
<StopEditor stop={attrs.stop} onChange={(stop) => updateAttributes({ ...attrs, stop })} />
<StopEditor
leftMargin={true}
stop={attrs.stop}
onChange={(stop) => updateAttributes({ ...attrs, stop })}
placeholder="Select stop sequence..."
/>
);
case "selection":
return (
Expand All @@ -217,10 +224,18 @@ const InnerGenerator: FC<{
);
case "regex":
return (
<RegexEditor
regex={attrs.regex}
onChange={(regex) => updateAttributes({ ...attrs, regex })}
/>
<>
<RegexEditor
regex={attrs.regex}
onChange={(regex) => updateAttributes({ ...attrs, regex })}
/>
<StopEditor
leftMargin={false}
stop={attrs.stop}
placeholder="Stop?"
onChange={(stop) => updateAttributes({ ...attrs, stop })}
/>
</>
);
default: {
throw new Error("Invalid type" + attrs.type);
Expand Down
4 changes: 1 addition & 3 deletions packages/editor-tools/src/messages-of-author.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,10 @@ export class MessageOfAuthorGetter {
};
}
case "regex": {
// TODO: remove removeLastSpace when backends support token healing
this.removeLastSpace();
return {
tag: "GenerateTask",
name: this.useGenerationUuids ? nodeAttrs.id : nodeAttrs.name,
stop: [],
stop: nodeAttrs.stop,
max_tokens: nodeAttrs.max_tokens,
regex: nodeAttrs.regex,
};
Expand Down
Loading