Add GLM 5.3 Flash support
This commit is contained in:
1 parent
9a33c61ea6
commit
46d6a976a5
31 files changed
+7806
-447
No files matched your search
+37
-2
@@ -365,6 +365,7 @@ pub(super) fn render_messages(
|
||||
|
||||
let mut turns = Vec::<ChatTurn>::new();
|
||||
for message in messages {
|
||||
validate_inline_images(&message.content)?;
|
||||
let content = content_text(&message.content);
|
||||
match message.role.as_str() {
|
||||
"system" | "developer" => {
|
||||
@@ -426,6 +427,30 @@ pub(super) fn render_messages(
|
||||
Ok((system, turns))
|
||||
}
|
||||
|
||||
fn validate_inline_images(value: &Value) -> Result<(), (u16, String)> {
|
||||
let Some(parts) = value.as_array() else {
|
||||
return Ok(());
|
||||
};
|
||||
for part in parts {
|
||||
let Some(image) = part.get("image_url") else {
|
||||
continue;
|
||||
};
|
||||
let url = image
|
||||
.get("url")
|
||||
.or(Some(image))
|
||||
.and_then(Value::as_str)
|
||||
.ok_or_else(|| (400, "invalid image input".into()))?;
|
||||
if !url.starts_with("data:image/png;base64,") && !url.starts_with("data:image/jpeg;base64,")
|
||||
{
|
||||
return Err((
|
||||
400,
|
||||
"image input must be an inline PNG or JPEG data URI".into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn validate_tool_results(
|
||||
state: &State,
|
||||
messages: &[ApiMessage],
|
||||
@@ -779,8 +804,18 @@ pub(super) fn content_text(value: &Value) -> String {
|
||||
Value::Array(parts) => parts
|
||||
.iter()
|
||||
.filter_map(|part| match part {
|
||||
Value::String(text) => Some(text.as_str()),
|
||||
Value::Object(object) => object.get("text").and_then(Value::as_str),
|
||||
Value::String(text) => Some(text.clone()),
|
||||
Value::Object(object) => object
|
||||
.get("text")
|
||||
.and_then(Value::as_str)
|
||||
.map(str::to_owned)
|
||||
.or_else(|| {
|
||||
let url = object
|
||||
.get("image_url")
|
||||
.and_then(|value| value.get("url").or(Some(value)))
|
||||
.and_then(Value::as_str)?;
|
||||
Some(crate::engine::vision_data_marker(url))
|
||||
}),
|
||||
_ => None,
|
||||
})
|
||||
.collect(),
|
||||
|
||||
Reference in new issue
Block a user