Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Dec 18, 2024
2 parents ae9ba38 + c89e315 commit 752a253
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
8 changes: 8 additions & 0 deletions langchain-core/src/messages/tests/base_message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ describe("Message like coercion", () => {
role: "system",
content: "6",
},
{ role: "developer", content: "6.1" },
{
role: "user",
content: [{ type: "image_url", image_url: { url: "7.1" } }],
Expand Down Expand Up @@ -374,6 +375,13 @@ describe("Message like coercion", () => {
new SystemMessage({
id: "foobar",
content: "6",
additional_kwargs: {},
}),
new SystemMessage({
content: "6.1",
additional_kwargs: {
__openai_role__: "developer",
},
}),
new HumanMessage({
content: [{ type: "image_url", image_url: { url: "7.1" } }],
Expand Down
16 changes: 14 additions & 2 deletions langchain-core/src/messages/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -983,9 +983,21 @@ function _switchTypeToMessage(
break;
case "developer":
if (returnChunk) {
chunk = new SystemMessageChunk(fields);
chunk = new SystemMessageChunk({
...fields,
additional_kwargs: {
...fields.additional_kwargs,
__openai_role__: "developer",
},
});
} else {
msg = new SystemMessage(fields);
msg = new SystemMessage({
...fields,
additional_kwargs: {
...fields.additional_kwargs,
__openai_role__: "developer",
},
});
}
break;
case "tool":
Expand Down
8 changes: 7 additions & 1 deletion langchain-core/src/messages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ function _constructMessageFromParams(
} else if (type === "system") {
return new SystemMessage(rest);
} else if (type === "developer") {
return new SystemMessage(rest);
return new SystemMessage({
...rest,
additional_kwargs: {
...rest.additional_kwargs,
__openai_role__: "developer",
},
});
} else if (type === "tool" && "tool_call_id" in rest) {
return new ToolMessage({
...rest,
Expand Down
2 changes: 1 addition & 1 deletion langchain-core/src/prompts/tests/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ test("Test MessagesPlaceholder not optional with invalid input should throw", as
badInput,
null,
2
)}\n\nAdditional message: Unable to coerce message from array: only human, AI, system, or tool message coercion is currently supported.`
)}\n\nAdditional message: Unable to coerce message from array: only human, AI, system, developer, or tool message coercion is currently supported.`
);
});

Expand Down

0 comments on commit 752a253

Please sign in to comment.