Skip to content

Commit 6efe291

Browse files
author
Jicheng Lu
committed
allow image urls in image-reader
1 parent dc87153 commit 6efe291

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/Plugins/BotSharp.Plugin.FileHandler/Functions/ReadImageFn.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public async Task<bool> Execute(RoleDialogModel message)
2323
var agentService = _services.GetRequiredService<IAgentService>();
2424

2525
var wholeDialogs = conv.GetDialogHistory();
26-
var dialogs = AssembleFiles(conv.ConversationId, wholeDialogs);
27-
var agent = await agentService.LoadAgent(BuiltInAgentId.UtilityAssistant);
26+
var dialogs = AssembleFiles(conv.ConversationId, args?.ImageUrls, wholeDialogs);
27+
var agent = await agentService.LoadAgent(message.CurrentAgentId ?? BuiltInAgentId.UtilityAssistant);
2828
var fileAgent = new Agent
2929
{
3030
Id = agent?.Id ?? Guid.Empty.ToString(),
@@ -38,7 +38,7 @@ public async Task<bool> Execute(RoleDialogModel message)
3838
return true;
3939
}
4040

41-
private List<RoleDialogModel> AssembleFiles(string conversationId, List<RoleDialogModel> dialogs)
41+
private List<RoleDialogModel> AssembleFiles(string conversationId, IEnumerable<string>? imageUrls, List<RoleDialogModel> dialogs)
4242
{
4343
if (dialogs.IsNullOrEmpty())
4444
{
@@ -66,6 +66,18 @@ private List<RoleDialogModel> AssembleFiles(string conversationId, List<RoleDial
6666
}).ToList();
6767
}
6868

69+
if (!imageUrls.IsNullOrEmpty())
70+
{
71+
var lastDialog = dialogs.Last();
72+
var files = lastDialog.Files ?? [];
73+
var addnFiles = imageUrls.Select(x => x?.Trim())
74+
.Where(x => !string.IsNullOrWhiteSpace(x))
75+
.Select(x => new BotSharpFile { FileUrl = x }).ToList();
76+
77+
files.AddRange(addnFiles);
78+
lastDialog.Files = files;
79+
}
80+
6981
return dialogs;
7082
}
7183

src/Plugins/BotSharp.Plugin.FileHandler/LlmContexts/LlmContextIn.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,12 @@ public class LlmContextIn
1111
[JsonPropertyName("image_description")]
1212
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
1313
public string? ImageDescription { get; set; }
14+
15+
//[JsonPropertyName("image_url")]
16+
//[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
17+
//public string? ImageUrl { get; set; }
18+
19+
[JsonPropertyName("image_urls")]
20+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
21+
public IEnumerable<string>? ImageUrls { get; set; }
1422
}

src/Plugins/BotSharp.Plugin.FileHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-file-read_image.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
"user_request": {
88
"type": "string",
99
"description": "The request posted by user, which is related to analyzing requested images. User can request for multiple images to process at one time."
10+
},
11+
"image_urls": {
12+
"type": "array",
13+
"description": "The image, photo or picture urls that user requests for analysis. They typically start with 'http' or 'https'. If user doesn't include any url, then leave this array empty. Please remove any duplicated urls",
14+
"items": {
15+
"type": "string",
16+
"description": "The image, photo or picture url that user requests for analysis. It typically starts with http or https."
17+
}
1018
}
1119
},
1220
"required": [ "user_request" ]

0 commit comments

Comments
 (0)