mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-06 02:47:56 +00:00
fix: add general API endpoints for Z.ai provider (#9894)
Co-authored-by: Roo Code <roomote@roocode.com>
This commit is contained in:
parent
a1d3a43aa5
commit
f9cfc66803
3 changed files with 91 additions and 3 deletions
|
|
@ -385,7 +385,7 @@ const sambaNovaSchema = apiModelIdProviderModelSchema.extend({
|
|||
sambaNovaApiKey: z.string().optional(),
|
||||
})
|
||||
|
||||
export const zaiApiLineSchema = z.enum(["international_coding", "china_coding"])
|
||||
export const zaiApiLineSchema = z.enum(["international_coding", "china_coding", "international_api", "china_api"])
|
||||
|
||||
export type ZaiApiLine = z.infer<typeof zaiApiLineSchema>
|
||||
|
||||
|
|
|
|||
|
|
@ -212,13 +212,23 @@ export const ZAI_DEFAULT_TEMPERATURE = 0.6
|
|||
|
||||
export const zaiApiLineConfigs = {
|
||||
international_coding: {
|
||||
name: "International",
|
||||
name: "International Coding",
|
||||
baseUrl: "https://api.z.ai/api/coding/paas/v4",
|
||||
isChina: false,
|
||||
},
|
||||
china_coding: {
|
||||
name: "China",
|
||||
name: "China Coding",
|
||||
baseUrl: "https://open.bigmodel.cn/api/coding/paas/v4",
|
||||
isChina: true,
|
||||
},
|
||||
international_api: {
|
||||
name: "International API",
|
||||
baseUrl: "https://api.z.ai/api/paas/v4",
|
||||
isChina: false,
|
||||
},
|
||||
china_api: {
|
||||
name: "China API",
|
||||
baseUrl: "https://open.bigmodel.cn/api/paas/v4",
|
||||
isChina: true,
|
||||
},
|
||||
} satisfies Record<ZaiApiLine, { name: string; baseUrl: string; isChina: boolean }>
|
||||
|
|
|
|||
|
|
@ -163,6 +163,84 @@ describe("ZAiHandler", () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe("International API", () => {
|
||||
beforeEach(() => {
|
||||
handler = new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "international_api" })
|
||||
})
|
||||
|
||||
it("should use the correct international API base URL", () => {
|
||||
new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "international_api" })
|
||||
expect(OpenAI).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
baseURL: "https://api.z.ai/api/paas/v4",
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it("should use the provided API key for international API", () => {
|
||||
const zaiApiKey = "test-zai-api-key"
|
||||
new ZAiHandler({ zaiApiKey, zaiApiLine: "international_api" })
|
||||
expect(OpenAI).toHaveBeenCalledWith(expect.objectContaining({ apiKey: zaiApiKey }))
|
||||
})
|
||||
|
||||
it("should return international default model when no model is specified", () => {
|
||||
const model = handler.getModel()
|
||||
expect(model.id).toBe(internationalZAiDefaultModelId)
|
||||
expect(model.info).toEqual(internationalZAiModels[internationalZAiDefaultModelId])
|
||||
})
|
||||
|
||||
it("should return specified international model when valid model is provided", () => {
|
||||
const testModelId: InternationalZAiModelId = "glm-4.5-air"
|
||||
const handlerWithModel = new ZAiHandler({
|
||||
apiModelId: testModelId,
|
||||
zaiApiKey: "test-zai-api-key",
|
||||
zaiApiLine: "international_api",
|
||||
})
|
||||
const model = handlerWithModel.getModel()
|
||||
expect(model.id).toBe(testModelId)
|
||||
expect(model.info).toEqual(internationalZAiModels[testModelId])
|
||||
})
|
||||
})
|
||||
|
||||
describe("China API", () => {
|
||||
beforeEach(() => {
|
||||
handler = new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "china_api" })
|
||||
})
|
||||
|
||||
it("should use the correct China API base URL", () => {
|
||||
new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "china_api" })
|
||||
expect(OpenAI).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
baseURL: "https://open.bigmodel.cn/api/paas/v4",
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it("should use the provided API key for China API", () => {
|
||||
const zaiApiKey = "test-zai-api-key"
|
||||
new ZAiHandler({ zaiApiKey, zaiApiLine: "china_api" })
|
||||
expect(OpenAI).toHaveBeenCalledWith(expect.objectContaining({ apiKey: zaiApiKey }))
|
||||
})
|
||||
|
||||
it("should return China default model when no model is specified", () => {
|
||||
const model = handler.getModel()
|
||||
expect(model.id).toBe(mainlandZAiDefaultModelId)
|
||||
expect(model.info).toEqual(mainlandZAiModels[mainlandZAiDefaultModelId])
|
||||
})
|
||||
|
||||
it("should return specified China model when valid model is provided", () => {
|
||||
const testModelId: MainlandZAiModelId = "glm-4.5-air"
|
||||
const handlerWithModel = new ZAiHandler({
|
||||
apiModelId: testModelId,
|
||||
zaiApiKey: "test-zai-api-key",
|
||||
zaiApiLine: "china_api",
|
||||
})
|
||||
const model = handlerWithModel.getModel()
|
||||
expect(model.id).toBe(testModelId)
|
||||
expect(model.info).toEqual(mainlandZAiModels[testModelId])
|
||||
})
|
||||
})
|
||||
|
||||
describe("Default behavior", () => {
|
||||
it("should default to international when no zaiApiLine is specified", () => {
|
||||
const handlerDefault = new ZAiHandler({ zaiApiKey: "test-zai-api-key" })
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue