|
@@ -295,5 +295,143 @@ describe("ZAiHandler", () => {
|
|
|
undefined,
|
|
undefined,
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ describe("Reasoning functionality", () => {
|
|
|
|
|
+ it("should include thinking parameter when enableReasoningEffort is true and model supports reasoning in createMessage", async () => {
|
|
|
|
|
+ const handlerWithReasoning = new ZAiHandler({
|
|
|
|
|
+ apiModelId: "glm-4.6", // GLM-4.6 has supportsReasoningBinary: true
|
|
|
|
|
+ zaiApiKey: "test-zai-api-key",
|
|
|
|
|
+ zaiApiLine: "international_coding",
|
|
|
|
|
+ enableReasoningEffort: true,
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ mockCreate.mockImplementationOnce(() => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ [Symbol.asyncIterator]: () => ({
|
|
|
|
|
+ async next() {
|
|
|
|
|
+ return { done: true }
|
|
|
|
|
+ },
|
|
|
|
|
+ }),
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ const systemPrompt = "Test system prompt"
|
|
|
|
|
+ const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Test message" }]
|
|
|
|
|
+
|
|
|
|
|
+ const messageGenerator = handlerWithReasoning.createMessage(systemPrompt, messages)
|
|
|
|
|
+ await messageGenerator.next()
|
|
|
|
|
+
|
|
|
|
|
+ expect(mockCreate).toHaveBeenCalledWith(
|
|
|
|
|
+ expect.objectContaining({
|
|
|
|
|
+ thinking: { type: "enabled" },
|
|
|
|
|
+ }),
|
|
|
|
|
+ undefined,
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("should not include thinking parameter when enableReasoningEffort is false in createMessage", async () => {
|
|
|
|
|
+ const handlerWithoutReasoning = new ZAiHandler({
|
|
|
|
|
+ apiModelId: "glm-4.6", // GLM-4.6 has supportsReasoningBinary: true
|
|
|
|
|
+ zaiApiKey: "test-zai-api-key",
|
|
|
|
|
+ zaiApiLine: "international_coding",
|
|
|
|
|
+ enableReasoningEffort: false,
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ mockCreate.mockImplementationOnce(() => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ [Symbol.asyncIterator]: () => ({
|
|
|
|
|
+ async next() {
|
|
|
|
|
+ return { done: true }
|
|
|
|
|
+ },
|
|
|
|
|
+ }),
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ const systemPrompt = "Test system prompt"
|
|
|
|
|
+ const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Test message" }]
|
|
|
|
|
+
|
|
|
|
|
+ const messageGenerator = handlerWithoutReasoning.createMessage(systemPrompt, messages)
|
|
|
|
|
+ await messageGenerator.next()
|
|
|
|
|
+
|
|
|
|
|
+ expect(mockCreate).toHaveBeenCalledWith(
|
|
|
|
|
+ expect.not.objectContaining({
|
|
|
|
|
+ thinking: expect.anything(),
|
|
|
|
|
+ }),
|
|
|
|
|
+ undefined,
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("should not include thinking parameter when model does not support reasoning in createMessage", async () => {
|
|
|
|
|
+ const handlerWithNonReasoningModel = new ZAiHandler({
|
|
|
|
|
+ apiModelId: "glm-4-32b-0414-128k", // This model doesn't have supportsReasoningBinary: true
|
|
|
|
|
+ zaiApiKey: "test-zai-api-key",
|
|
|
|
|
+ zaiApiLine: "international_coding",
|
|
|
|
|
+ enableReasoningEffort: true,
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ mockCreate.mockImplementationOnce(() => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ [Symbol.asyncIterator]: () => ({
|
|
|
|
|
+ async next() {
|
|
|
|
|
+ return { done: true }
|
|
|
|
|
+ },
|
|
|
|
|
+ }),
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ const systemPrompt = "Test system prompt"
|
|
|
|
|
+ const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Test message" }]
|
|
|
|
|
+
|
|
|
|
|
+ const messageGenerator = handlerWithNonReasoningModel.createMessage(systemPrompt, messages)
|
|
|
|
|
+ await messageGenerator.next()
|
|
|
|
|
+
|
|
|
|
|
+ expect(mockCreate).toHaveBeenCalledWith(
|
|
|
|
|
+ expect.not.objectContaining({
|
|
|
|
|
+ thinking: expect.anything(),
|
|
|
|
|
+ }),
|
|
|
|
|
+ undefined,
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("should include thinking parameter when enableReasoningEffort is true and model supports reasoning in completePrompt", async () => {
|
|
|
|
|
+ const handlerWithReasoning = new ZAiHandler({
|
|
|
|
|
+ apiModelId: "glm-4.5", // GLM-4.5 has supportsReasoningBinary: true
|
|
|
|
|
+ zaiApiKey: "test-zai-api-key",
|
|
|
|
|
+ zaiApiLine: "international_coding",
|
|
|
|
|
+ enableReasoningEffort: true,
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ const expectedResponse = "This is a test response"
|
|
|
|
|
+ mockCreate.mockResolvedValueOnce({ choices: [{ message: { content: expectedResponse } }] })
|
|
|
|
|
+
|
|
|
|
|
+ await handlerWithReasoning.completePrompt("test prompt")
|
|
|
|
|
+
|
|
|
|
|
+ expect(mockCreate).toHaveBeenCalledWith(
|
|
|
|
|
+ expect.objectContaining({
|
|
|
|
|
+ thinking: { type: "enabled" },
|
|
|
|
|
+ }),
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("should not include thinking parameter when enableReasoningEffort is false in completePrompt", async () => {
|
|
|
|
|
+ const handlerWithoutReasoning = new ZAiHandler({
|
|
|
|
|
+ apiModelId: "glm-4.5", // GLM-4.5 has supportsReasoningBinary: true
|
|
|
|
|
+ zaiApiKey: "test-zai-api-key",
|
|
|
|
|
+ zaiApiLine: "international_coding",
|
|
|
|
|
+ enableReasoningEffort: false,
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ const expectedResponse = "This is a test response"
|
|
|
|
|
+ mockCreate.mockResolvedValueOnce({ choices: [{ message: { content: expectedResponse } }] })
|
|
|
|
|
+
|
|
|
|
|
+ await handlerWithoutReasoning.completePrompt("test prompt")
|
|
|
|
|
+
|
|
|
|
|
+ expect(mockCreate).toHaveBeenCalledWith(
|
|
|
|
|
+ expect.not.objectContaining({
|
|
|
|
|
+ thinking: expect.anything(),
|
|
|
|
|
+ }),
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|