Compare commits
No commits in common. "9803512c0b07a3c503bd0dff40250fc70ba6145a" and "f5479690f9b03df7997959d7e6be77c6e1263d67" have entirely different histories.
9803512c0b
...
f5479690f9
|
|
@ -78,8 +78,6 @@
|
|||
|
||||
.hr {
|
||||
border: none;
|
||||
border-bottom: 1px solid var(--hrColor, #555);
|
||||
border-top: 1px solid var(--hrColor, #555);
|
||||
margin: 0.5em 0;
|
||||
display: block;
|
||||
text-align: center;
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ export const parseTable = (table: string): string => {
|
|||
|
||||
export const highlight = (message: string, keepMarkup = true): string => {
|
||||
let resultHTML = '';
|
||||
const tokenRegex = /(\*{1,3}|"|```|`|(?:^|\n)#{1,3} |(?:^|\n)> |\n)|---/g;
|
||||
const tokenRegex = /(\*\*?|"|```|`|(?:^|\n)#{1,3} |(?:^|\n)> |\n)/g;
|
||||
const headerRegex = /#{1,3} $/;
|
||||
const blockquoteRegex = /> $/;
|
||||
const stack: string[] = [];
|
||||
|
|
@ -116,9 +116,7 @@ export const highlight = (message: string, keepMarkup = true): string => {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (token === '***' || token === '---') {
|
||||
resultHTML += `<span class="${styles.hr}">${keepToken ? token : ''}</span>`;
|
||||
} else if (isClose) {
|
||||
if (isClose) {
|
||||
stack.pop();
|
||||
resultHTML += `${keepToken ? token : ''}</span>`;
|
||||
} else if (token === '*') {
|
||||
|
|
@ -149,6 +147,7 @@ export const highlight = (message: string, keepMarkup = true): string => {
|
|||
|
||||
if (!keepMarkup) {
|
||||
resultHTML = resultHTML.replace(/((?:(?:^|\n)\|.+)+)/g, match => parseTable(match));
|
||||
resultHTML = resultHTML.replace(/(^|\n)---(\n|$)/g, (_, pre, post) => `${pre}<hr class="${styles.hr}">${post}`);
|
||||
resultHTML = resultHTML.replace(/((?:(?:^|\n)[-+] .+)+)/g, match => parseList(match, false));
|
||||
resultHTML = resultHTML.replace(/((?:(?:^|\n)\d+\. .+)+)/g, match => parseList(match, true));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import { Sparkles, ChevronsRight } from "lucide-preact";
|
|||
import clsx from "clsx";
|
||||
import { ContentEditable } from "@common/components/ContentEditable";
|
||||
|
||||
const CONTINUE_PROMPT = "Continue the story forward.\nUse `edit_text` tool in append mode to add new text to the story.\nWait for the approval after adding.";
|
||||
const CONTINUE_PROMPT = "Continue the story forward.\nUse `edit_text` tool in append mode to add new text to the story.";
|
||||
|
||||
interface RoleHeaderProps {
|
||||
message: ChatMessage;
|
||||
|
|
@ -92,14 +92,10 @@ export const ChatSidebar = () => {
|
|||
|
||||
const countTokens = async () => {
|
||||
try {
|
||||
const messages: ChatMessage[] = [];
|
||||
const messages: LLM.ChatMessage[] = [];
|
||||
|
||||
if (input.trim()) {
|
||||
messages.push({
|
||||
id: crypto.randomUUID(),
|
||||
role: 'user',
|
||||
content: input.trim(),
|
||||
});
|
||||
messages.push({ role: 'user', content: input.trim() });
|
||||
}
|
||||
|
||||
const chatRequest = Prompt.compilePrompt(appStateRef.current, messages);
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ export enum LocationScale {
|
|||
Room = 'room',
|
||||
House = 'house',
|
||||
Street = 'street',
|
||||
Village = 'village',
|
||||
City = 'city',
|
||||
Region = 'region',
|
||||
Country = 'country',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import LLM from "./llm";
|
||||
import Chapters from "./chapters";
|
||||
import { type AppState, CharacterRole, type ChatMessage } from "../contexts/state";
|
||||
import { type AppState, CharacterRole } from "../contexts/state";
|
||||
import { Tools } from "./tools";
|
||||
|
||||
namespace Prompt {
|
||||
|
|
@ -313,7 +313,7 @@ namespace Prompt {
|
|||
return parts.join('\n\n');
|
||||
}
|
||||
|
||||
export function compilePrompt(state: AppState, newMessages: ChatMessage[] = []): LLM.ChatCompletionRequest | null {
|
||||
export function compilePrompt(state: AppState, newMessages: LLM.ChatMessage[] = []): LLM.ChatCompletionRequest | null {
|
||||
const { currentStory, model, enableThinking } = state;
|
||||
|
||||
if (!currentStory || !model) {
|
||||
|
|
@ -332,21 +332,12 @@ namespace Prompt {
|
|||
storyTokenBudget = model.max_context - otherTokens;
|
||||
}
|
||||
|
||||
const messages: ChatMessage[] = [
|
||||
{
|
||||
id: crypto.randomUUID(),
|
||||
role: 'system',
|
||||
content: formatSystemPrompt(state, storyTokenBudget),
|
||||
},
|
||||
const messages: LLM.ChatMessage[] = [
|
||||
{ role: 'system', content: formatSystemPrompt(state, storyTokenBudget) },
|
||||
...currentStory.chatMessages,
|
||||
];
|
||||
|
||||
const presentMessages = new Set(messages.map(m => m.id));
|
||||
for (const newMessage of newMessages) {
|
||||
if (!presentMessages.has(newMessage.id)) {
|
||||
messages.push(newMessage);
|
||||
}
|
||||
}
|
||||
messages.push(...newMessages);
|
||||
|
||||
return {
|
||||
model: model.id,
|
||||
|
|
|
|||
|
|
@ -399,10 +399,10 @@ export namespace Tools {
|
|||
dispatchEdit(currentText + '\n' + args.new_text);
|
||||
appState.dispatch({ type: 'SET_CURRENT_TAB', id: appState.currentStory.id, tab });
|
||||
let message = cropped
|
||||
? `Added text:\n${args.new_text.split('\n').filter(l => l.trim()).map(l => '> ' + l).join('\n')}\n\nNote: The rest was cropped due to ${LINES_LIMIT} lines limit!`
|
||||
? `Added text:\n${args.new_text.split('\n').filter(l => l.trim()).map(l => '> ' + l).join('\n')}\n\nWarning: The rest was cropped due to ${LINES_LIMIT} lines limit! Write less next time.`
|
||||
: `Text appended to ${target} successfully.`;
|
||||
|
||||
message += `\nNote: you can't continue nor add more text until user's approval. Stop any attempts and wait.`
|
||||
message += `\nNote: you can't continue until user's approval, stop.`
|
||||
|
||||
return message;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue