From c4fa105ce20eb0f5274f7fd4b5c59f0c4ecf86a2 Mon Sep 17 00:00:00 2001 From: jacoblee93 Date: Tue, 17 Dec 2024 23:41:40 -0800 Subject: [PATCH] Revert a bit --- langchain-core/src/messages/developer.ts | 62 --------------------- langchain-core/src/messages/index.ts | 1 - langchain-core/src/messages/system.ts | 11 ++++ langchain-core/src/messages/transformers.ts | 9 ++- langchain-core/src/messages/utils.ts | 17 +----- langchain-core/src/prompts/chat.ts | 30 ---------- langchain-core/src/runnables/remote.ts | 12 ---- 7 files changed, 17 insertions(+), 125 deletions(-) delete mode 100644 langchain-core/src/messages/developer.ts diff --git a/langchain-core/src/messages/developer.ts b/langchain-core/src/messages/developer.ts deleted file mode 100644 index 6abe392b792b..000000000000 --- a/langchain-core/src/messages/developer.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { - BaseMessage, - BaseMessageChunk, - mergeContent, - _mergeDicts, - type MessageType, -} from "./base.js"; - -/** - * Represents a developer message in a conversation. - * - * Currently, all models other than OpenAI's o1 should treat this the same - * as a system message. - */ -export class DeveloperMessage extends BaseMessage { - static lc_name() { - return "DeveloperMessage"; - } - - _getType(): MessageType { - return "developer"; - } -} - -/** - * Represents a chunk of a developer message, which can be concatenated with - * other developer message chunks. - */ -export class DeveloperMessageChunk extends BaseMessageChunk { - static lc_name() { - return "DeveloperMessageChunk"; - } - - _getType(): MessageType { - return "developer"; - } - - concat(chunk: DeveloperMessageChunk) { - return new DeveloperMessageChunk({ - content: mergeContent(this.content, chunk.content), - additional_kwargs: _mergeDicts( - this.additional_kwargs, - chunk.additional_kwargs - ), - response_metadata: _mergeDicts( - this.response_metadata, - chunk.response_metadata - ), - id: this.id ?? chunk.id, - }); - } -} - -export function isDeveloperMessage(x: BaseMessage): x is DeveloperMessage { - return x._getType() === "developer"; -} - -export function isDeveloperMessageChunk( - x: BaseMessageChunk -): x is DeveloperMessageChunk { - return x._getType() === "developer"; -} diff --git a/langchain-core/src/messages/index.ts b/langchain-core/src/messages/index.ts index 1863711a3d32..d60fb4268ba3 100644 --- a/langchain-core/src/messages/index.ts +++ b/langchain-core/src/messages/index.ts @@ -4,7 +4,6 @@ export * from "./chat.js"; export * from "./function.js"; export * from "./human.js"; export * from "./system.js"; -export * from "./developer.js"; export * from "./utils.js"; export * from "./transformers.js"; export * from "./modifier.js"; diff --git a/langchain-core/src/messages/system.ts b/langchain-core/src/messages/system.ts index ae91a240e83f..cd9ec1132de4 100644 --- a/langchain-core/src/messages/system.ts +++ b/langchain-core/src/messages/system.ts @@ -57,3 +57,14 @@ export function isSystemMessageChunk( ): x is SystemMessageChunk { return x._getType() === "system"; } + +/** + * Represents a developer message in a conversation. + */ +export class DeveloperMessage extends SystemMessage {} + +/** + * Represents a chunk of a developer message, which can be concatenated with + * other developer message chunks. + */ +export class DeveloperMessageChunk extends SystemMessageChunk {} diff --git a/langchain-core/src/messages/transformers.ts b/langchain-core/src/messages/transformers.ts index 0d0115556861..d5fc2510c730 100644 --- a/langchain-core/src/messages/transformers.ts +++ b/langchain-core/src/messages/transformers.ts @@ -13,7 +13,6 @@ import { ChatMessageChunk, ChatMessageFieldsWithRole, } from "./chat.js"; -import { DeveloperMessage, DeveloperMessageChunk } from "./developer.js"; import { FunctionMessage, FunctionMessageChunk, @@ -908,8 +907,8 @@ const _MSG_CHUNK_MAP: Record< messageChunk: SystemMessageChunk, }, developer: { - message: DeveloperMessage, - messageChunk: DeveloperMessageChunk, + message: SystemMessage, + messageChunk: SystemMessageChunk, }, tool: { message: ToolMessage, @@ -984,9 +983,9 @@ function _switchTypeToMessage( break; case "developer": if (returnChunk) { - chunk = new DeveloperMessageChunk(fields); + chunk = new SystemMessageChunk(fields); } else { - msg = new DeveloperMessage(fields); + msg = new SystemMessage(fields); } break; case "tool": diff --git a/langchain-core/src/messages/utils.ts b/langchain-core/src/messages/utils.ts index 915e2cfe0733..a57a034147ff 100644 --- a/langchain-core/src/messages/utils.ts +++ b/langchain-core/src/messages/utils.ts @@ -16,7 +16,6 @@ import { ChatMessageFieldsWithRole, ChatMessageChunk, } from "./chat.js"; -import { DeveloperMessage, DeveloperMessageChunk } from "./developer.js"; import { FunctionMessage, FunctionMessageFieldsWithName, @@ -88,11 +87,6 @@ function _constructMessageFromParams( className === "SystemMessageChunk" ) { type = "system"; - } else if ( - className === "DeveloperMessage" || - className === "DeveloperMessageChunk" - ) { - type = "developer"; } else { type = "unknown"; } @@ -114,7 +108,7 @@ function _constructMessageFromParams( } else if (type === "system") { return new SystemMessage(rest); } else if (type === "developer") { - return new DeveloperMessage(rest); + return new SystemMessage(rest); } else if (type === "tool" && "tool_call_id" in rest) { return new ToolMessage({ ...rest, @@ -125,7 +119,7 @@ function _constructMessageFromParams( } else { const error = addLangChainErrorFields( new Error( - `Unable to coerce message from array: only human, AI, system, or tool message coercion is currently supported.\n\nReceived: ${JSON.stringify( + `Unable to coerce message from array: only human, AI, system, developer, or tool message coercion is currently supported.\n\nReceived: ${JSON.stringify( params, null, 2 @@ -174,8 +168,6 @@ export function getBufferString( role = aiPrefix; } else if (m._getType() === "system") { role = "System"; - } else if (m._getType() === "developer") { - role = "Developer"; } else if (m._getType() === "function") { role = "Function"; } else if (m._getType() === "tool") { @@ -231,8 +223,6 @@ export function mapStoredMessageToChatMessage(message: StoredMessage) { return new AIMessage(storedMessage.data); case "system": return new SystemMessage(storedMessage.data); - case "developer": - return new DeveloperMessage(storedMessage.data); case "function": if (storedMessage.data.name === undefined) { throw new Error("Name must be defined for function messages"); @@ -309,9 +299,6 @@ export function convertToChunk(message: BaseMessage) { } else if (type === "system") { // eslint-disable-next-line @typescript-eslint/no-use-before-define return new SystemMessageChunk({ ...message }); - } else if (type === "developer") { - // eslint-disable-next-line @typescript-eslint/no-use-before-define - return new DeveloperMessageChunk({ ...message }); } else if (type === "function") { // eslint-disable-next-line @typescript-eslint/no-use-before-define return new FunctionMessageChunk({ ...message }); diff --git a/langchain-core/src/prompts/chat.ts b/langchain-core/src/prompts/chat.ts index 6162968b3666..406d9f6b6f17 100644 --- a/langchain-core/src/prompts/chat.ts +++ b/langchain-core/src/prompts/chat.ts @@ -13,7 +13,6 @@ import { isBaseMessage, MessageContent, MessageContentComplex, - DeveloperMessage, } from "../messages/index.js"; import { type ChatPromptValueInterface, @@ -705,33 +704,6 @@ export class SystemMessagePromptTemplate< } } -/** - * Class that represents a developer message prompt template. It extends the - * BaseMessageStringPromptTemplate. - * @example - * ```typescript - * const message = DeveloperMessagePromptTemplate.fromTemplate("{text}"); - * const formatted = await message.format({ text: "Hello world!" }); - * - * const chatPrompt = ChatPromptTemplate.fromMessages([message]); - * const formattedChatPrompt = await chatPrompt.invoke({ - * text: "Hello world!", - * }); - * ``` - */ -export class DeveloperMessagePromptTemplate< - // eslint-disable-next-line @typescript-eslint/no-explicit-any - RunInput extends InputValues = any -> extends _StringImageMessagePromptTemplate { - static _messageClass(): typeof SystemMessage { - return DeveloperMessage; - } - - static lc_name() { - return "DeveloperMessagePromptTemplate"; - } -} - /** * Interface for the input of a ChatPromptTemplate. */ @@ -842,8 +814,6 @@ function _coerceMessagePromptTemplateLike< return AIMessagePromptTemplate.fromTemplate(templateData, extra); } else if (message._getType() === "system") { return SystemMessagePromptTemplate.fromTemplate(templateData, extra); - } else if (message._getType() === "developer") { - return DeveloperMessagePromptTemplate.fromTemplate(templateData, extra); } else if (ChatMessage.isInstance(message)) { return ChatMessagePromptTemplate.fromTemplate( message.content as string, diff --git a/langchain-core/src/runnables/remote.ts b/langchain-core/src/runnables/remote.ts index a219c4b75e70..4cae2f63d783 100644 --- a/langchain-core/src/runnables/remote.ts +++ b/langchain-core/src/runnables/remote.ts @@ -14,8 +14,6 @@ import { AIMessageChunk, ChatMessage, ChatMessageChunk, - DeveloperMessage, - DeveloperMessageChunk, FunctionMessage, FunctionMessageChunk, HumanMessage, @@ -72,11 +70,6 @@ function revive(obj: any): any { content: obj.content, }); } - if (obj.type === "DeveloperMessage" || obj.type === "developer") { - return new DeveloperMessage({ - content: obj.content, - }); - } if (obj.type === "ChatMessage" || obj.type === "generic") { return new ChatMessage({ content: obj.content, @@ -111,11 +104,6 @@ function revive(obj: any): any { content: obj.content, }); } - if (obj.type === "DeveloperMessageChunk") { - return new DeveloperMessageChunk({ - content: obj.content, - }); - } if (obj.type === "ChatMessageChunk") { return new ChatMessageChunk({ content: obj.content,