Skip to content

Commit 358fbc3

Browse files
authored
Merge branch 'SciSharp:master' into master
2 parents 8ceb044 + bf6daa0 commit 358fbc3

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ 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 agentId = !string.IsNullOrWhiteSpace(message.CurrentAgentId) ? message.CurrentAgentId : BuiltInAgentId.UtilityAssistant;
28+
var agent = await agentService.LoadAgent(agentId);
2829
var fileAgent = new Agent
2930
{
3031
Id = agent?.Id ?? Guid.Empty.ToString(),
@@ -38,7 +39,7 @@ public async Task<bool> Execute(RoleDialogModel message)
3839
return true;
3940
}
4041

41-
private List<RoleDialogModel> AssembleFiles(string conversationId, List<RoleDialogModel> dialogs)
42+
private List<RoleDialogModel> AssembleFiles(string conversationId, IEnumerable<string>? imageUrls, List<RoleDialogModel> dialogs)
4243
{
4344
if (dialogs.IsNullOrEmpty())
4445
{
@@ -66,6 +67,18 @@ private List<RoleDialogModel> AssembleFiles(string conversationId, List<RoleDial
6667
}).ToList();
6768
}
6869

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

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)