Skip to content

Commit

Permalink
Merge branch 'main' into 6214-fix-github-ignorePaths-subfolders
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul authored Jul 29, 2024
2 parents e503f86 + 11d6627 commit 0a97108
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ Answer:`
const route = ({ topic }: { input: string; topic: string }) => {
if (topic.toLowerCase().includes("anthropic")) {
return anthropicChain;
} else if (topic.toLowerCase().includes("langchain")) {
}
if (topic.toLowerCase().includes("langchain")) {
return langChainChain;
} else {
return generalChain;
}
return generalChain;
};

const fullChain = RunnableSequence.from([
Expand Down
23 changes: 22 additions & 1 deletion langchain-core/src/messages/tests/message_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import {
trimMessages,
} from "../transformers.js";
import { AIMessage } from "../ai.js";
import { ChatMessage } from "../chat.js";
import { HumanMessage } from "../human.js";
import { SystemMessage } from "../system.js";
import { BaseMessage } from "../base.js";
import { getBufferString } from "../utils.js";
import {
getBufferString,
mapChatMessagesToStoredMessages,
mapStoredMessagesToChatMessages,
} from "../utils.js";

describe("filterMessage", () => {
const getMessages = () => [
Expand Down Expand Up @@ -499,3 +504,19 @@ test("getBufferString can handle complex messages", () => {
)}`
);
});

describe("chat message conversions", () => {
it("can convert a chat message to a stored message and back", () => {
const originalMessages = [
new ChatMessage("I'm a generic message!", "human"),
new HumanMessage("I'm a human message!"),
];

const storedMessages = mapChatMessagesToStoredMessages(originalMessages);

const convertedBackMessages =
mapStoredMessagesToChatMessages(storedMessages);

expect(convertedBackMessages).toEqual(originalMessages);
});
});
2 changes: 1 addition & 1 deletion langchain-core/src/messages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function mapStoredMessageToChatMessage(message: StoredMessage) {
return new ToolMessage(
storedMessage.data as ToolMessageFieldsWithToolCallId
);
case "chat": {
case "generic": {
if (storedMessage.data.role === undefined) {
throw new Error("Role must be defined for chat messages");
}
Expand Down
1 change: 1 addition & 0 deletions langchain-core/src/output_parsers/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class StringOutputParser extends BaseTransformOutputParser<string> {
): string {
switch (content.type) {
case "text":
case "text_delta":
if ("text" in content) {
// Type guard for MessageContentText
return this._textContentToString(content as MessageContentText);
Expand Down
2 changes: 1 addition & 1 deletion langchain-core/src/runnables/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function revive(obj: any): any {
content: obj.content,
});
}
if (obj.type === "ChatMessage" || obj.type === "chat") {
if (obj.type === "ChatMessage" || obj.type === "generic") {
return new ChatMessage({
content: obj.content,
role: obj.role,
Expand Down
26 changes: 20 additions & 6 deletions libs/langchain-community/src/chat_models/iflytek_xinghuo/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ function messageToXinghuoRole(message: BaseMessage): XinghuoMessageRole {
}

declare interface IflytekXinghuoChatInput {
/** Model version to use. Available options are: v1.1, v2.1, v3.1
* @default "v2.1"
/** Model version to use. Available options are: v1.1, v2.1, v3.1, v3.5, v4.0
* @default "v3.1"
*/
version: string;

Expand Down Expand Up @@ -200,7 +200,7 @@ export abstract class BaseChatIflytekXinghuo

lc_serializable = true;

version = "v2.1";
version = "v3.1";

iflytekAppid: string;

Expand Down Expand Up @@ -256,7 +256,12 @@ export abstract class BaseChatIflytekXinghuo
this.top_k = fields?.top_k ?? this.top_k;

this.version = fields?.version ?? this.version;
if (["v1.1", "v2.1", "v3.1"].includes(this.version)) {
if (
["v1.1", "v2.1", "v3.1", "v3.5", "v4.0", "pro-128k"].includes(
this.version
)
) {
this.apiUrl = `wss://spark-api.xf-yun.com/${this.version}/chat`;
switch (this.version) {
case "v1.1":
this.domain = "general";
Expand All @@ -267,10 +272,19 @@ export abstract class BaseChatIflytekXinghuo
case "v3.1":
this.domain = "generalv3";
break;
case "v3.5":
this.domain = "generalv3.5";
break;
case "v4.0":
this.domain = "4.0Ultra";
break;
case "pro-128k":
this.domain = "pro-128k";
this.apiUrl = `wss://spark-api.xf-yun.com/chat/${this.version}`;
break;
default:
this.domain = "generalv2";
this.domain = "generalv3";
}
this.apiUrl = `wss://spark-api.xf-yun.com/${this.version}/chat`;
} else {
throw new Error(`Invalid model version: ${this.version}`);
}
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-community/src/vectorstores/xata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class XataVectorSearch<
)
),
}),
record.xata.score,
record.xata ? record.xata.score : record.xata_score,
]) ?? []
);
}
Expand Down

0 comments on commit 0a97108

Please sign in to comment.