-
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.
* improvements to editor tools * improvements * fix bugs * fix bugs * more improvements * fix ci?
- Loading branch information
1 parent
052b03e
commit 1896892
Showing
24 changed files
with
603 additions
and
225 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
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
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
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
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# @lmscript/client | ||
|
||
## 0.0.32 | ||
|
||
### Patch Changes | ||
|
||
- Improve editor-tools | ||
|
||
## 0.0.31 | ||
|
||
### Patch Changes | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { type Task } from "@lmscript/client/backends/abstract"; | ||
import { getRoleEnd, getRoleStart, ChatTemplate } from "@lmscript/client/chat-template"; | ||
import { MessageOfAuthor } from "./messages-of-author"; | ||
import { Author } from "./types"; | ||
|
||
export const applyChatTemplate = (messages: MessageOfAuthor[], template: ChatTemplate): Task[] => { | ||
const countOfRoles: Record<Author, number> = { | ||
system: 0, | ||
user: 0, | ||
assistant: 0, | ||
}; | ||
return messages.flatMap((message): Task[] => { | ||
const item: Task[] = [ | ||
{ | ||
tag: "AddTextTask", | ||
text: getRoleStart(template, message.author, countOfRoles), | ||
}, | ||
...message.tasks, | ||
{ | ||
tag: "AddTextTask", | ||
text: getRoleEnd(template, message.author, countOfRoles), | ||
}, | ||
]; | ||
countOfRoles[message.author] += 1; | ||
return item; | ||
}); | ||
}; |
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 |
---|---|---|
@@ -1,18 +1,41 @@ | ||
import { type Task } from "@lmscript/client/backends/abstract"; | ||
import { LmEditorState } from "./types"; | ||
import { MessageOfAuthorGetter } from "./messages-of-author"; | ||
import { messagesToTasks } from "./message-to-tasks"; | ||
import { MessageOfAuthorGetter, printCustomError } from "./messages-of-author"; | ||
import { applyChatTemplate } from "./apply-chat-template"; | ||
import { ChatTemplate } from "@lmscript/client/chat-template"; | ||
|
||
export const compileEditorState = (editorState: LmEditorState, template: ChatTemplate): Task[] => { | ||
const state = new MessageOfAuthorGetter(editorState); | ||
export const compileEditorState = ( | ||
editorState: LmEditorState, | ||
options: { | ||
template: ChatTemplate; | ||
variableOverrides?: Record<string, string>; | ||
useGenerationUuids?: boolean; | ||
}, | ||
): Task[] => { | ||
const overrides = options.variableOverrides ?? {}; | ||
|
||
const useGenerationUuids = options.useGenerationUuids ?? false; | ||
|
||
const newVariables = editorState.variables.map((variable) => { | ||
if (variable.name in overrides) { | ||
return { | ||
...variable, | ||
value: overrides[variable.name], | ||
}; | ||
} | ||
return variable; | ||
}); | ||
|
||
const state = new MessageOfAuthorGetter( | ||
{ ...editorState, variables: newVariables }, | ||
useGenerationUuids, | ||
); | ||
|
||
const errors = state.getErrors(); | ||
if (errors.length > 0) { | ||
// TODO: serialize errors | ||
throw new Error(JSON.stringify(errors)); | ||
throw new Error(errors.map(printCustomError).join("\n")); | ||
} | ||
const messages = state.getAcc(); | ||
|
||
return messagesToTasks(messages, template, editorState.variables); | ||
return applyChatTemplate(messages, options.template); | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.