remove baseChatSystemMessage from ILLM
This commit is contained in:
parent
c6fa6d78a7
commit
e5ed4d3dc2
5 changed files with 51 additions and 15 deletions
4
core/index.d.ts
vendored
4
core/index.d.ts
vendored
|
|
@ -592,9 +592,6 @@ export interface LLMOptions {
|
|||
maxEmbeddingChunkSize?: number;
|
||||
maxEmbeddingBatchSize?: number;
|
||||
|
||||
// Chat options
|
||||
baseChatSystemMessage?: string;
|
||||
|
||||
// Cloudflare options
|
||||
accountId?: string;
|
||||
|
||||
|
|
@ -1043,6 +1040,7 @@ export interface ModelDescription {
|
|||
template?: TemplateType;
|
||||
completionOptions?: BaseCompletionOptions;
|
||||
systemMessage?: string;
|
||||
baseChatSystemMessage?: string;
|
||||
requestOptions?: RequestOptions;
|
||||
promptTemplates?: { [key: string]: string };
|
||||
cacheBehavior?: CacheBehavior;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,10 @@ const DEFAULT_SYSTEM_MESSAGE = `<important_rules>
|
|||
const CANCELED_TOOL_CALL_MESSAGE =
|
||||
"This tool call was cancelled by the user. You should clarify next steps, as they don't wish for you to use this tool.";
|
||||
|
||||
export function constructMessages(history: ChatHistoryItem[]): ChatMessage[] {
|
||||
export function constructMessages(
|
||||
history: ChatHistoryItem[],
|
||||
baseChatSystemMessage: string | undefined,
|
||||
): ChatMessage[] {
|
||||
const filteredHistory = history.filter(
|
||||
(item) => item.message.role !== "system",
|
||||
);
|
||||
|
|
@ -16,7 +19,7 @@ export function constructMessages(history: ChatHistoryItem[]): ChatMessage[] {
|
|||
|
||||
msgs.push({
|
||||
role: "system",
|
||||
content: DEFAULT_SYSTEM_MESSAGE,
|
||||
content: baseChatSystemMessage ?? DEFAULT_SYSTEM_MESSAGE,
|
||||
});
|
||||
|
||||
for (let i = 0; i < filteredHistory.length; i++) {
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
|
||||
this.title = options.title;
|
||||
this.uniqueId = options.uniqueId ?? "None";
|
||||
this.baseSystemMessage = options.baseSystemMessage;
|
||||
this.systemMessage = options.systemMessage;
|
||||
this.contextLength =
|
||||
options.contextLength ?? llmInfo?.contextLength ?? DEFAULT_CONTEXT_LENGTH;
|
||||
this.maxStopWords = options.maxStopWords ?? this.maxStopWords;
|
||||
|
|
@ -305,7 +305,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
supportsImages: this.supportsImages(),
|
||||
prompt: undefined,
|
||||
functions,
|
||||
baseSystemMessage: this.baseSystemMessage,
|
||||
systemMessage: this.systemMessage,
|
||||
rules: this.rules ?? [],
|
||||
});
|
||||
}
|
||||
|
|
@ -317,14 +317,43 @@ export abstract class BaseLLM implements ILLM {
|
|||
|
||||
const msgs: ChatMessage[] = [{ role: "user", content: prompt }];
|
||||
|
||||
const baseSystemMessage = this.baseSystemMessage;
|
||||
if (baseSystemMessage) {
|
||||
msgs.unshift({ role: "system", content: baseSystemMessage });
|
||||
const systemMessage = this.systemMessage;
|
||||
if (systemMessage) {
|
||||
msgs.unshift({ role: "system", content: systemMessage });
|
||||
}
|
||||
|
||||
return this.templateMessages(msgs);
|
||||
}
|
||||
|
||||
private _compilePromptForLog(
|
||||
prompt: string,
|
||||
completionOptions: CompletionOptions,
|
||||
): string {
|
||||
const completionOptionsLog = JSON.stringify(
|
||||
{
|
||||
contextLength: this.contextLength,
|
||||
...completionOptions,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
);
|
||||
|
||||
let requestOptionsLog = "";
|
||||
if (this.requestOptions) {
|
||||
requestOptionsLog = JSON.stringify(this.requestOptions, null, 2);
|
||||
}
|
||||
|
||||
return (
|
||||
"##### Completion options #####\n" +
|
||||
completionOptionsLog +
|
||||
(requestOptionsLog
|
||||
? "\n\n##### Request options #####\n" + requestOptionsLog
|
||||
: "") +
|
||||
"\n\n##### Prompt #####\n" +
|
||||
prompt
|
||||
);
|
||||
}
|
||||
|
||||
private _logEnd(
|
||||
model: string,
|
||||
prompt: string,
|
||||
|
|
@ -1143,13 +1172,13 @@ export abstract class BaseLLM implements ILLM {
|
|||
public renderPromptTemplate(
|
||||
template: PromptTemplate,
|
||||
history: ChatMessage[],
|
||||
templateVariables: Record<string, string>,
|
||||
otherData: Record<string, string>,
|
||||
canPutWordsInModelsMouth = false,
|
||||
): string | ChatMessage[] {
|
||||
if (typeof template === "string") {
|
||||
const data: any = {
|
||||
history: history,
|
||||
...templateVariables,
|
||||
...otherData,
|
||||
};
|
||||
if (history.length > 0 && history[0].role === "system") {
|
||||
data.system_message = history.shift()!.content;
|
||||
|
|
@ -1159,7 +1188,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
return compiledTemplate(data);
|
||||
}
|
||||
const rendered = template(history, {
|
||||
...templateVariables,
|
||||
...otherData,
|
||||
supportsCompletions: this.supportsCompletions() ? "true" : "false",
|
||||
supportsPrefill: this.supportsPrefill() ? "true" : "false",
|
||||
});
|
||||
|
|
|
|||
|
|
@ -85,7 +85,10 @@ export const streamResponseThunk = createAsyncThunk<
|
|||
|
||||
// Construct messages from updated history
|
||||
const updatedHistory = getState().session.history;
|
||||
const messages = constructMessages([...updatedHistory]);
|
||||
const messages = constructMessages(
|
||||
[...updatedHistory],
|
||||
selectedChatModel?.baseChatSystemMessage,
|
||||
);
|
||||
|
||||
posthog.capture("step run", {
|
||||
step_name: "User Input",
|
||||
|
|
|
|||
|
|
@ -59,7 +59,10 @@ export const streamResponseAfterToolCall = createAsyncThunk<
|
|||
dispatch(setActive());
|
||||
|
||||
const updatedHistory = getState().session.history;
|
||||
const messages = constructMessages([...updatedHistory]);
|
||||
const messages = constructMessages(
|
||||
[...updatedHistory],
|
||||
selectedChatModel?.baseChatSystemMessage,
|
||||
);
|
||||
unwrapResult(await dispatch(streamNormalInput({ messages })));
|
||||
}),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue