fix system prompt
This commit is contained in:
@@ -5,7 +5,6 @@ import { MemorySaver } from '@langchain/langgraph';
|
||||
import gigachat from './gigachat';
|
||||
|
||||
export interface SupportAgentConfig {
|
||||
systemPrompt?: string;
|
||||
temperature?: number;
|
||||
threadId?: string;
|
||||
}
|
||||
@@ -22,11 +21,13 @@ export class SupportAgent {
|
||||
private agent: any;
|
||||
private systemPrompt: string;
|
||||
private threadId: string;
|
||||
private isFirstMessage: boolean;
|
||||
|
||||
constructor(config: SupportAgentConfig = {}) {
|
||||
this.systemPrompt = config.systemPrompt || this.getDefaultSystemPrompt();
|
||||
this.systemPrompt = this.getDefaultSystemPrompt();
|
||||
this.threadId = config.threadId || 'default';
|
||||
this.memorySaver = new MemorySaver();
|
||||
this.isFirstMessage = true;
|
||||
|
||||
// Настраиваем модель с заданной температурой
|
||||
this.llm = gigachat;
|
||||
@@ -58,30 +59,24 @@ export class SupportAgent {
|
||||
Всегда отвечай на русском языке и старайся быть максимально полезным.`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Обновить системный промпт
|
||||
*/
|
||||
public updateSystemPrompt(newPrompt: string): void {
|
||||
this.systemPrompt = newPrompt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить текущий системный промпт
|
||||
*/
|
||||
public getSystemPrompt(): string {
|
||||
return this.systemPrompt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Обработать сообщение пользователя и получить ответ
|
||||
*/
|
||||
public async processMessage(userMessage: string): Promise<SupportResponse> {
|
||||
try {
|
||||
// Создаем сообщения с системным промптом
|
||||
const messages = [
|
||||
new SystemMessage(this.systemPrompt),
|
||||
new HumanMessage(userMessage)
|
||||
];
|
||||
// Создаем массив сообщений
|
||||
const messages: BaseMessage[] = [];
|
||||
|
||||
// Добавляем системный промпт только в первом сообщении
|
||||
if (this.isFirstMessage) {
|
||||
messages.push(new SystemMessage(this.systemPrompt));
|
||||
this.isFirstMessage = false;
|
||||
}
|
||||
|
||||
// Добавляем сообщение пользователя
|
||||
messages.push(new HumanMessage(userMessage));
|
||||
|
||||
// Получаем ответ от агента
|
||||
const response = await this.agent.invoke({
|
||||
@@ -120,12 +115,9 @@ export class SupportAgent {
|
||||
tools: [],
|
||||
checkpointSaver: this.memorySaver
|
||||
});
|
||||
// Сбрасываем флаг первого сообщения
|
||||
this.isFirstMessage = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Изменить ID потока (для работы с разными пользователями)
|
||||
*/
|
||||
public setThreadId(threadId: string): void {
|
||||
this.threadId = threadId;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user