Skip to content

Commit

Permalink
Revert a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Dec 18, 2024
1 parent 0b4ed0f commit c4fa105
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 125 deletions.
62 changes: 0 additions & 62 deletions langchain-core/src/messages/developer.ts

This file was deleted.

1 change: 0 additions & 1 deletion langchain-core/src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
11 changes: 11 additions & 0 deletions langchain-core/src/messages/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
9 changes: 4 additions & 5 deletions langchain-core/src/messages/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
ChatMessageChunk,
ChatMessageFieldsWithRole,
} from "./chat.js";
import { DeveloperMessage, DeveloperMessageChunk } from "./developer.js";
import {
FunctionMessage,
FunctionMessageChunk,
Expand Down Expand Up @@ -908,8 +907,8 @@ const _MSG_CHUNK_MAP: Record<
messageChunk: SystemMessageChunk,
},
developer: {
message: DeveloperMessage,
messageChunk: DeveloperMessageChunk,
message: SystemMessage,
messageChunk: SystemMessageChunk,
},
tool: {
message: ToolMessage,
Expand Down Expand Up @@ -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":
Expand Down
17 changes: 2 additions & 15 deletions langchain-core/src/messages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
ChatMessageFieldsWithRole,
ChatMessageChunk,
} from "./chat.js";
import { DeveloperMessage, DeveloperMessageChunk } from "./developer.js";
import {
FunctionMessage,
FunctionMessageFieldsWithName,
Expand Down Expand Up @@ -88,11 +87,6 @@ function _constructMessageFromParams(
className === "SystemMessageChunk"
) {
type = "system";
} else if (
className === "DeveloperMessage" ||
className === "DeveloperMessageChunk"
) {
type = "developer";
} else {
type = "unknown";
}
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 });
Expand Down
30 changes: 0 additions & 30 deletions langchain-core/src/prompts/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
isBaseMessage,
MessageContent,
MessageContentComplex,
DeveloperMessage,
} from "../messages/index.js";
import {
type ChatPromptValueInterface,
Expand Down Expand Up @@ -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<RunInput> {
static _messageClass(): typeof SystemMessage {
return DeveloperMessage;
}

static lc_name() {
return "DeveloperMessagePromptTemplate";
}
}

/**
* Interface for the input of a ChatPromptTemplate.
*/
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 0 additions & 12 deletions langchain-core/src/runnables/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {
AIMessageChunk,
ChatMessage,
ChatMessageChunk,
DeveloperMessage,
DeveloperMessageChunk,
FunctionMessage,
FunctionMessageChunk,
HumanMessage,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c4fa105

Please sign in to comment.