test: align google-shared expectations with pi-ai 0.40.0
This commit is contained in:
@@ -46,12 +46,12 @@ describe("google-shared convertTools", () => {
|
||||
converted?.[0]?.functionDeclarations?.[0]?.parameters,
|
||||
);
|
||||
|
||||
expect(params.type).toBe("object");
|
||||
expect(params.type).toBeUndefined();
|
||||
expect(params.properties).toBeDefined();
|
||||
expect(params.required).toEqual(["action"]);
|
||||
});
|
||||
|
||||
it("drops unsupported JSON Schema keywords", () => {
|
||||
it("keeps unsupported JSON Schema keywords intact", () => {
|
||||
const tools = [
|
||||
{
|
||||
name: "example",
|
||||
@@ -93,11 +93,11 @@ describe("google-shared convertTools", () => {
|
||||
const list = asRecord(properties.list);
|
||||
const items = asRecord(list.items);
|
||||
|
||||
expect(params).not.toHaveProperty("patternProperties");
|
||||
expect(params).not.toHaveProperty("additionalProperties");
|
||||
expect(mode).not.toHaveProperty("const");
|
||||
expect(options).not.toHaveProperty("anyOf");
|
||||
expect(items).not.toHaveProperty("const");
|
||||
expect(params).toHaveProperty("patternProperties");
|
||||
expect(params).toHaveProperty("additionalProperties");
|
||||
expect(mode).toHaveProperty("const");
|
||||
expect(options).toHaveProperty("anyOf");
|
||||
expect(items).toHaveProperty("const");
|
||||
expect(params.required).toEqual(["mode"]);
|
||||
});
|
||||
|
||||
@@ -147,7 +147,7 @@ describe("google-shared convertTools", () => {
|
||||
});
|
||||
|
||||
describe("google-shared convertMessages", () => {
|
||||
it("drops thinking blocks for Gemini", () => {
|
||||
it("keeps thinking blocks when provider/model match", () => {
|
||||
const model = makeModel("gemini-1.5-pro");
|
||||
const context = {
|
||||
messages: [
|
||||
@@ -184,7 +184,13 @@ describe("google-shared convertMessages", () => {
|
||||
} as unknown as Context;
|
||||
|
||||
const contents = convertMessages(model, context);
|
||||
expect(contents).toHaveLength(0);
|
||||
expect(contents).toHaveLength(1);
|
||||
expect(contents[0].role).toBe("model");
|
||||
expect(contents[0].parts).toHaveLength(1);
|
||||
expect(contents[0].parts?.[0]).toMatchObject({
|
||||
thought: true,
|
||||
thoughtSignature: "sig",
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps thought signatures for Claude models", () => {
|
||||
@@ -232,7 +238,7 @@ describe("google-shared convertMessages", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("merges consecutive user messages for Gemini", () => {
|
||||
it("does not merge consecutive user messages for Gemini", () => {
|
||||
const model = makeModel("gemini-1.5-pro");
|
||||
const context = {
|
||||
messages: [
|
||||
@@ -248,12 +254,12 @@ describe("google-shared convertMessages", () => {
|
||||
} as unknown as Context;
|
||||
|
||||
const contents = convertMessages(model, context);
|
||||
expect(contents).toHaveLength(1);
|
||||
expect(contents).toHaveLength(2);
|
||||
expect(contents[0].role).toBe("user");
|
||||
expect(contents[0].parts).toHaveLength(2);
|
||||
expect(contents[1].role).toBe("user");
|
||||
});
|
||||
|
||||
it("merges consecutive user messages for non-Gemini Google models", () => {
|
||||
it("does not merge consecutive user messages for non-Gemini Google models", () => {
|
||||
const model = makeModel("claude-3-opus");
|
||||
const context = {
|
||||
messages: [
|
||||
@@ -269,12 +275,12 @@ describe("google-shared convertMessages", () => {
|
||||
} as unknown as Context;
|
||||
|
||||
const contents = convertMessages(model, context);
|
||||
expect(contents).toHaveLength(1);
|
||||
expect(contents).toHaveLength(2);
|
||||
expect(contents[0].role).toBe("user");
|
||||
expect(contents[0].parts).toHaveLength(2);
|
||||
expect(contents[1].role).toBe("user");
|
||||
});
|
||||
|
||||
it("merges consecutive model messages for Gemini", () => {
|
||||
it("does not merge consecutive model messages for Gemini", () => {
|
||||
const model = makeModel("gemini-1.5-pro");
|
||||
const context = {
|
||||
messages: [
|
||||
@@ -332,10 +338,10 @@ describe("google-shared convertMessages", () => {
|
||||
} as unknown as Context;
|
||||
|
||||
const contents = convertMessages(model, context);
|
||||
expect(contents).toHaveLength(2);
|
||||
expect(contents).toHaveLength(3);
|
||||
expect(contents[0].role).toBe("user");
|
||||
expect(contents[1].role).toBe("model");
|
||||
expect(contents[1].parts).toHaveLength(2);
|
||||
expect(contents[2].role).toBe("model");
|
||||
});
|
||||
|
||||
it("handles user message after tool result without model response in between", () => {
|
||||
@@ -392,10 +398,11 @@ describe("google-shared convertMessages", () => {
|
||||
} as unknown as Context;
|
||||
|
||||
const contents = convertMessages(model, context);
|
||||
expect(contents).toHaveLength(3);
|
||||
expect(contents).toHaveLength(4);
|
||||
expect(contents[0].role).toBe("user");
|
||||
expect(contents[1].role).toBe("model");
|
||||
expect(contents[2].role).toBe("user");
|
||||
expect(contents[3].role).toBe("user");
|
||||
const toolResponsePart = contents[2].parts?.find(
|
||||
(part) =>
|
||||
typeof part === "object" && part !== null && "functionResponse" in part,
|
||||
@@ -469,10 +476,11 @@ describe("google-shared convertMessages", () => {
|
||||
} as unknown as Context;
|
||||
|
||||
const contents = convertMessages(model, context);
|
||||
expect(contents).toHaveLength(2);
|
||||
expect(contents).toHaveLength(3);
|
||||
expect(contents[0].role).toBe("user");
|
||||
expect(contents[1].role).toBe("model");
|
||||
const toolCallPart = contents[1].parts?.find(
|
||||
expect(contents[2].role).toBe("model");
|
||||
const toolCallPart = contents[2].parts?.find(
|
||||
(part) =>
|
||||
typeof part === "object" && part !== null && "functionCall" in part,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user