Skip to content

Commit

Permalink
feature: support glm-4v
Browse files Browse the repository at this point in the history
  • Loading branch information
Dogtiti committed Dec 28, 2024
1 parent 5f96804 commit 8a22c9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/client/platforms/glm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import {
SpeechOptions,
} from "../api";
import { getClientConfig } from "@/app/config/client";
import { getMessageTextContent } from "@/app/utils";
import { getMessageTextContent, isVisionModel } from "@/app/utils";
import { RequestPayload } from "./openai";
import { fetch } from "@/app/utils/stream";
import { preProcessImageContent } from "@/app/utils/chat";

interface BasePayload {
model: string;
Expand Down Expand Up @@ -154,9 +155,12 @@ export class ChatGLMApi implements LLMApi {
}

async chat(options: ChatOptions) {
const visionModel = isVisionModel(options.config.model);
const messages: ChatOptions["messages"] = [];
for (const v of options.messages) {
const content = getMessageTextContent(v);
const content = visionModel
? await preProcessImageContent(v.content)
: getMessageTextContent(v);
messages.push({ role: v.role, content });
}

Expand All @@ -168,7 +172,6 @@ export class ChatGLMApi implements LLMApi {
providerName: options.config.providerName,
},
};

const modelType = this.getModelType(modelConfig.model);
const requestPayload = this.createPayload(messages, modelConfig, options);
const path = this.path(this.getModelPath(modelType));
Expand Down
3 changes: 3 additions & 0 deletions app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ export const VISION_MODEL_REGEXES = [
/qwen2-vl/,
/gpt-4-turbo(?!.*preview)/, // Matches "gpt-4-turbo" but not "gpt-4-turbo-preview"
/^dall-e-3$/, // Matches exactly "dall-e-3"
/glm-4v-plus/,
/glm-4v/,
/glm-4v-flash/,
];

export const EXCLUDE_VISION_MODEL_REGEXES = [/claude-3-5-haiku-20241022/];
Expand Down

0 comments on commit 8a22c9d

Please sign in to comment.