Skip to content

Commit f8b10ad

Browse files
authored
Merge pull request ChatGPTNextWeb#5997 from ChatGPTNextWeb/feature/glm-4v
feature: support glm-4v
2 parents 5f96804 + 8a22c9d commit f8b10ad

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

app/client/platforms/glm.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ import {
2121
SpeechOptions,
2222
} from "../api";
2323
import { getClientConfig } from "@/app/config/client";
24-
import { getMessageTextContent } from "@/app/utils";
24+
import { getMessageTextContent, isVisionModel } from "@/app/utils";
2525
import { RequestPayload } from "./openai";
2626
import { fetch } from "@/app/utils/stream";
27+
import { preProcessImageContent } from "@/app/utils/chat";
2728

2829
interface BasePayload {
2930
model: string;
@@ -154,9 +155,12 @@ export class ChatGLMApi implements LLMApi {
154155
}
155156

156157
async chat(options: ChatOptions) {
158+
const visionModel = isVisionModel(options.config.model);
157159
const messages: ChatOptions["messages"] = [];
158160
for (const v of options.messages) {
159-
const content = getMessageTextContent(v);
161+
const content = visionModel
162+
? await preProcessImageContent(v.content)
163+
: getMessageTextContent(v);
160164
messages.push({ role: v.role, content });
161165
}
162166

@@ -168,7 +172,6 @@ export class ChatGLMApi implements LLMApi {
168172
providerName: options.config.providerName,
169173
},
170174
};
171-
172175
const modelType = this.getModelType(modelConfig.model);
173176
const requestPayload = this.createPayload(messages, modelConfig, options);
174177
const path = this.path(this.getModelPath(modelType));

app/constant.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ export const VISION_MODEL_REGEXES = [
305305
/qwen2-vl/,
306306
/gpt-4-turbo(?!.*preview)/, // Matches "gpt-4-turbo" but not "gpt-4-turbo-preview"
307307
/^dall-e-3$/, // Matches exactly "dall-e-3"
308+
/glm-4v-plus/,
309+
/glm-4v/,
310+
/glm-4v-flash/,
308311
];
309312

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

0 commit comments

Comments
 (0)