Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf49775c

Browse files
committed
feat: support url image in /v1/messages
1 parent686b3ab commitf49775c

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

‎api/sdk/src/main/java/com/ke/bella/openapi/protocol/message/MessageRequest.java‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ public String getType() {
175175
include =JsonTypeInfo.As.PROPERTY,
176176
property ="type")
177177
@JsonSubTypes({
178-
@JsonSubTypes.Type(value =Base64ImageSource.class,name ="base64")
178+
@JsonSubTypes.Type(value =Base64ImageSource.class,name ="base64"),
179+
@JsonSubTypes.Type(value =URLImageSource.class,name ="url")
179180
})
180181
@JsonInclude(JsonInclude.Include.NON_NULL)
181182
@Data
@@ -191,6 +192,20 @@ public static class Base64ImageSource extends ImageSource {
191192
@JsonProperty("media_type")
192193
privateStringmediaType;
193194
privateStringdata;
195+
publicStringgetType() {
196+
return"base64";
197+
}
198+
}
199+
200+
@Data
201+
@NoArgsConstructor
202+
@EqualsAndHashCode(callSuper =true)
203+
@JsonInclude(JsonInclude.Include.NON_NULL)
204+
publicstaticclassURLImageSourceextendsImageSource {
205+
privateStringurl;
206+
publicStringgetType() {
207+
return"url";
208+
}
194209
}
195210

196211
@JsonTypeInfo(

‎api/sdk/src/main/java/com/ke/bella/openapi/protocol/message/TransferFromCompletionsUtils.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private static void processTextContentBlock(MessageRequest.TextContentBlock bloc
207207
context.getContentParts().add(JacksonUtils.toMap(contentPart));
208208
}
209209

210-
privatestaticvoidprocessImageContentBlock(MessageRequest.ImageContentBlockblock,
210+
privatestaticvoidprocessImageContentBlock(MessageRequest.ImageContentBlockblock,
211211
MessageProcessingContextcontext,booleannativeSupport) {
212212
if (block.getSource()instanceofMessageRequest.Base64ImageSource) {
213213
MessageRequest.Base64ImageSourceimageSource = (MessageRequest.Base64ImageSource)block.getSource();
@@ -217,6 +217,13 @@ private static void processImageContentBlock(MessageRequest.ImageContentBlock bl
217217
contentPart.setCache_control(block.getCache_control());
218218
}
219219
context.getContentParts().add(JacksonUtils.toMap(contentPart));
220+
}elseif (block.getSource()instanceofMessageRequest.URLImageSource) {
221+
MessageRequest.URLImageSourceimageSource = (MessageRequest.URLImageSource)block.getSource();
222+
ContentPartcontentPart =ContentPart.ofImageUrl(newImageUrl(imageSource.getUrl(),"auto"));
223+
if (nativeSupport) {
224+
contentPart.setCache_control(block.getCache_control());
225+
}
226+
context.getContentParts().add(JacksonUtils.toMap(contentPart));
220227
}
221228
}
222229

‎api/sdk/src/main/java/com/ke/bella/openapi/protocol/message/TransferToCompletionsUtils.java‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ private static Object convertContentToMessageFormat(Object content) {
675675

676676
privatestaticMessageRequest.ContentBlockconvertContentPartToBlock(Mappart) {
677677
if (part ==null)returnnull;
678-
678+
679679
Stringtype = (String)part.get("type");
680680
if ("text".equals(type)) {
681681
MessageRequest.TextContentBlocktextBlock =newMessageRequest.TextContentBlock();
@@ -691,7 +691,7 @@ private static MessageRequest.ContentBlock convertContentPartToBlock(Map part) {
691691
if (dataParts.length ==2) {
692692
String[]headerParts =dataParts[0].split(";");
693693
StringmediaType =headerParts[0].substring(5);// Remove "data:"
694-
694+
695695
MessageRequest.ImageContentBlockimageBlock =newMessageRequest.ImageContentBlock();
696696
MessageRequest.Base64ImageSourceimageSource =newMessageRequest.Base64ImageSource();
697697
imageSource.setType("base64");
@@ -701,8 +701,15 @@ private static MessageRequest.ContentBlock convertContentPartToBlock(Map part) {
701701
imageBlock.setCache_control(part.get("cache_control"));
702702
returnimageBlock;
703703
}
704-
}else {
705-
thrownewBizParamCheckException("Only support base64String image data.");
704+
}elseif (url !=null) {
705+
// Handle URL image source
706+
MessageRequest.ImageContentBlockimageBlock =newMessageRequest.ImageContentBlock();
707+
MessageRequest.URLImageSourceimageSource =newMessageRequest.URLImageSource();
708+
imageSource.setType("url");
709+
imageSource.setUrl(url);
710+
imageBlock.setSource(imageSource);
711+
imageBlock.setCache_control(part.get("cache_control"));
712+
returnimageBlock;
706713
}
707714
}
708715
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp