Skip to content

Commit 89b662a

Browse files
authored
Merge pull request #1205 from iceljc/features/refine-agent-rule
Features/refine agent rule
2 parents 627e94b + 0078d97 commit 89b662a

File tree

9 files changed

+54
-134
lines changed

9 files changed

+54
-134
lines changed

src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,11 @@ public class AgentLlmConfig
4343
public string? ReasoningEffortLevel { get; set; }
4444

4545
/// <summary>
46-
/// Image generation config
46+
/// Image composition config
4747
/// </summary>
48-
[JsonPropertyName("image_generation")]
48+
[JsonPropertyName("image_composition")]
4949
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
50-
public LlmImageGenerationConfig? ImageGeneration { get; set; }
51-
52-
/// <summary>
53-
/// Image edit config
54-
/// </summary>
55-
[JsonPropertyName("image_edit")]
56-
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
57-
public LlmImageEditConfig? ImageEdit { get; set; }
50+
public LlmImageCompositionConfig? ImageComposition { get; set; }
5851

5952
/// <summary>
6053
/// Audio transcription config
@@ -71,12 +64,7 @@ public class AgentLlmConfig
7164
public LlmRealtimeConfig? Realtime { get; set; }
7265
}
7366

74-
75-
public class LlmImageGenerationConfig : LlmProviderModel
76-
{
77-
}
78-
79-
public class LlmImageEditConfig : LlmProviderModel
67+
public class LlmImageCompositionConfig : LlmProviderModel
8068
{
8169
}
8270

src/Infrastructure/BotSharp.Abstraction/MLTasks/Settings/LlmModelSetting.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,11 @@ public enum LlmModelCapability
188188
ImageGeneration = 4,
189189
ImageEdit = 5,
190190
ImageVariation = 6,
191-
Embedding = 7,
192-
AudioTranscription = 8,
193-
AudioGeneration = 9,
194-
Realtime = 10,
195-
WebSearch = 11,
196-
PdfReading = 12
191+
ImageComposition = 7,
192+
Embedding = 8,
193+
AudioTranscription = 9,
194+
AudioGeneration = 10,
195+
Realtime = 11,
196+
WebSearch = 12,
197+
PdfReading = 13
197198
}

src/Infrastructure/BotSharp.OpenAPI/Controllers/Agent/AgentController.Coding.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public async Task<bool> DeleteAgentCodeScripts([FromRoute] string agentId, [From
4848
return updated;
4949
}
5050

51+
/// <summary>
52+
/// Generate agent code script
53+
/// </summary>
54+
/// <param name="agentId"></param>
55+
/// <param name="request"></param>
56+
/// <returns></returns>
5157
[HttpPost("/agent/{agentId}/code-script/generate")]
5258
public async Task<CodeGenerationResult> GenerateAgentCodeScript([FromRoute] string agentId, [FromBody] AgentCodeScriptGenerationRequest request)
5359
{

src/Plugins/BotSharp.Plugin.ImageHandler/Functions/ComposeImageFn.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,16 @@ private async Task<string> GetImageEditGeneration(Agent agent, RoleDialogModel m
117117

118118
private (string, string) GetLlmProviderModel(Agent agent)
119119
{
120-
var provider = agent?.LlmConfig?.ImageEdit?.Provider;
121-
var model = agent?.LlmConfig?.ImageEdit?.Model;
120+
var provider = agent?.LlmConfig?.ImageComposition?.Provider;
121+
var model = agent?.LlmConfig?.ImageComposition?.Model;
122122

123123
if (!string.IsNullOrEmpty(provider) && !string.IsNullOrEmpty(model))
124124
{
125125
return (provider, model);
126126
}
127127

128-
provider = _settings?.Edit?.Provider;
129-
model = _settings?.Edit?.Model;
128+
provider = _settings?.Composition?.Provider;
129+
model = _settings?.Composition?.Model;
130130

131131
if (!string.IsNullOrEmpty(provider) && !string.IsNullOrEmpty(model))
132132
{
@@ -162,7 +162,7 @@ private IEnumerable<string> SaveGeneratedImage(ImageGeneration? image)
162162

163163
private async Task<BinaryData> ConvertImageToPngWithRgba(BinaryData binaryFile)
164164
{
165-
var provider = _settings?.Edit?.ImageConverter?.Provider;
165+
var provider = _settings?.Composition?.ImageConverter?.Provider;
166166
var converter = _services.GetServices<IImageConverter>().FirstOrDefault(x => x.Provider == provider);
167167
if (converter == null)
168168
{

src/Plugins/BotSharp.Plugin.ImageHandler/Functions/EditImageFn.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,16 @@ private async Task<string> GetImageEdit(Agent agent, RoleDialogModel message, st
119119

120120
private (string, string) GetLlmProviderModel(Agent agent)
121121
{
122-
var provider = agent?.LlmConfig?.ImageEdit?.Provider;
123-
var model = agent?.LlmConfig?.ImageEdit?.Model;
122+
var provider = agent?.LlmConfig?.ImageComposition?.Provider;
123+
var model = agent?.LlmConfig?.ImageComposition?.Model;
124124

125125
if (!string.IsNullOrEmpty(provider) && !string.IsNullOrEmpty(model))
126126
{
127127
return (provider, model);
128128
}
129129

130-
provider = _settings?.Edit?.Provider;
131-
model = _settings?.Edit?.Model;
130+
provider = _settings?.Composition?.Provider;
131+
model = _settings?.Composition?.Model;
132132

133133
if (!string.IsNullOrEmpty(provider) && !string.IsNullOrEmpty(model))
134134
{
@@ -164,7 +164,7 @@ private IEnumerable<string> SaveGeneratedImage(ImageGeneration? image)
164164

165165
private async Task<BinaryData> ConvertImageToPngWithRgba(BinaryData binaryFile)
166166
{
167-
var provider = _settings?.Edit?.ImageConverter?.Provider;
167+
var provider = _settings?.Composition?.ImageConverter?.Provider;
168168
var converter = _services.GetServices<IImageConverter>().FirstOrDefault(x => x.Provider == provider);
169169
if (converter == null)
170170
{

src/Plugins/BotSharp.Plugin.ImageHandler/Functions/GenerateImageFn.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ private async Task<string> GetImageGeneration(Agent agent, RoleDialogModel messa
8080

8181
private (string, string) GetLlmProviderModel(Agent agent)
8282
{
83-
var provider = agent?.LlmConfig?.ImageGeneration?.Provider;
84-
var model = agent?.LlmConfig?.ImageGeneration?.Model;
83+
var provider = agent?.LlmConfig?.ImageComposition?.Provider;
84+
var model = agent?.LlmConfig?.ImageComposition?.Model;
8585

8686
if (!string.IsNullOrEmpty(provider) && !string.IsNullOrEmpty(model))
8787
{
8888
return (provider, model);
8989
}
9090

91-
provider = _settings?.Generation?.Provider;
92-
model = _settings?.Generation?.Model;
91+
provider = _settings?.Composition?.Provider;
92+
model = _settings?.Composition?.Model;
9393

9494
if (!string.IsNullOrEmpty(provider) && !string.IsNullOrEmpty(model))
9595
{

src/Plugins/BotSharp.Plugin.ImageHandler/Settings/ImageHandlerSettings.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,15 @@ namespace BotSharp.Plugin.ImageHandler.Settings;
55
public class ImageHandlerSettings
66
{
77
public ImageReadSettings? Reading { get; set; }
8-
public ImageGenerationSettings? Generation { get; set; }
9-
public ImageEditSettings? Edit { get; set; }
8+
public ImageCompositionSettings? Composition { get; set; }
109
}
1110

1211
public class ImageReadSettings : LlmProviderModel
1312
{
1413
public string? ImageDetailLevel { get; set; }
1514
}
1615

17-
public class ImageGenerationSettings : LlmProviderModel
18-
{
19-
20-
}
21-
22-
public class ImageEditSettings : LlmProviderModel
16+
public class ImageCompositionSettings : LlmProviderModel
2317
{
2418
public SettingBase? ImageConverter { get; set; }
25-
}
19+
}

src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoModel.cs

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ public class AgentLlmConfigMongoModel
1212
public int? MaxOutputTokens { get; set; }
1313
public string? ReasoningEffortLevel { get; set; }
1414

15-
public LlmImageGenerationConfigMongoModel? ImageGeneration { get; set; }
16-
public LlmImageEditConfigMongoModel? ImageEdit { get; set; }
15+
public LlmImageCompositionConfigMongoModel? ImageComposition { get; set; }
1716
public LlmAudioTranscriptionConfigMongoModel? AudioTranscription { get; set; }
1817
public LlmRealtimeConfigMongoModel? Realtime { get; set; }
1918

@@ -34,8 +33,7 @@ public class AgentLlmConfigMongoModel
3433
MaxRecursionDepth = config.MaxRecursionDepth,
3534
MaxOutputTokens = config.MaxOutputTokens,
3635
ReasoningEffortLevel = config.ReasoningEffortLevel,
37-
ImageGeneration = LlmImageGenerationConfigMongoModel.ToMongoModel(config.ImageGeneration),
38-
ImageEdit = LlmImageEditConfigMongoModel.ToMongoModel(config.ImageEdit),
36+
ImageComposition = LlmImageCompositionConfigMongoModel.ToMongoModel(config.ImageComposition),
3937
AudioTranscription = LlmAudioTranscriptionConfigMongoModel.ToMongoModel(config.AudioTranscription),
4038
Realtime = LlmRealtimeConfigMongoModel.ToMongoModel(config.Realtime)
4139
};
@@ -56,74 +54,41 @@ public class AgentLlmConfigMongoModel
5654
MaxRecursionDepth = config.MaxRecursionDepth,
5755
MaxOutputTokens = config.MaxOutputTokens,
5856
ReasoningEffortLevel = config.ReasoningEffortLevel,
59-
ImageGeneration = LlmImageGenerationConfigMongoModel.ToDomainModel(config.ImageGeneration),
60-
ImageEdit = LlmImageEditConfigMongoModel.ToDomainModel(config.ImageEdit),
57+
ImageComposition = LlmImageCompositionConfigMongoModel.ToDomainModel(config.ImageComposition),
6158
AudioTranscription = LlmAudioTranscriptionConfigMongoModel.ToDomainModel(config.AudioTranscription),
6259
Realtime = LlmRealtimeConfigMongoModel.ToDomainModel(config.Realtime)
6360
};
6461
}
6562
}
6663

6764
[BsonIgnoreExtraElements(Inherited = true)]
68-
public class LlmImageGenerationConfigMongoModel : LlmProviderModelMongoModel
65+
public class LlmImageCompositionConfigMongoModel : LlmProviderModelMongoModel
6966
{
70-
public static LlmImageGenerationConfig? ToDomainModel(LlmImageGenerationConfigMongoModel? config)
67+
public static LlmImageCompositionConfig? ToDomainModel(LlmImageCompositionConfigMongoModel? config)
7168
{
7269
if (config == null)
7370
{
7471
return null;
7572
}
7673

77-
return new LlmImageGenerationConfig
74+
return new LlmImageCompositionConfig
7875
{
7976
Provider = config.Provider,
80-
Model = config.Model,
77+
Model = config.Model
8178
};
8279
}
8380

84-
public static LlmImageGenerationConfigMongoModel? ToMongoModel(LlmImageGenerationConfig? config)
81+
public static LlmImageCompositionConfigMongoModel? ToMongoModel(LlmImageCompositionConfig? config)
8582
{
8683
if (config == null)
8784
{
8885
return null;
8986
}
9087

91-
return new LlmImageGenerationConfigMongoModel
88+
return new LlmImageCompositionConfigMongoModel
9289
{
9390
Provider = config.Provider,
94-
Model = config.Model,
95-
};
96-
}
97-
}
98-
99-
[BsonIgnoreExtraElements(Inherited = true)]
100-
public class LlmImageEditConfigMongoModel : LlmProviderModelMongoModel
101-
{
102-
public static LlmImageEditConfig? ToDomainModel(LlmImageEditConfigMongoModel? config)
103-
{
104-
if (config == null)
105-
{
106-
return null;
107-
}
108-
109-
return new LlmImageEditConfig
110-
{
111-
Provider = config.Provider,
112-
Model = config.Model,
113-
};
114-
}
115-
116-
public static LlmImageEditConfigMongoModel? ToMongoModel(LlmImageEditConfig? config)
117-
{
118-
if (config == null)
119-
{
120-
return null;
121-
}
122-
123-
return new LlmImageEditConfigMongoModel
124-
{
125-
Provider = config.Provider,
126-
Model = config.Model,
91+
Model = config.Model
12792
};
12893
}
12994
}
@@ -141,7 +106,7 @@ public class LlmAudioTranscriptionConfigMongoModel : LlmProviderModelMongoModel
141106
return new LlmAudioTranscriptionConfig
142107
{
143108
Provider = config.Provider,
144-
Model = config.Model,
109+
Model = config.Model
145110
};
146111
}
147112

@@ -155,7 +120,7 @@ public class LlmAudioTranscriptionConfigMongoModel : LlmProviderModelMongoModel
155120
return new LlmAudioTranscriptionConfigMongoModel
156121
{
157122
Provider = config.Provider,
158-
Model = config.Model,
123+
Model = config.Model
159124
};
160125
}
161126
}
@@ -173,7 +138,7 @@ public class LlmRealtimeConfigMongoModel : LlmProviderModelMongoModel
173138
return new LlmRealtimeConfig
174139
{
175140
Provider = config.Provider,
176-
Model = config.Model,
141+
Model = config.Model
177142
};
178143
}
179144

@@ -187,7 +152,7 @@ public class LlmRealtimeConfigMongoModel : LlmProviderModelMongoModel
187152
return new LlmRealtimeConfigMongoModel
188153
{
189154
Provider = config.Provider,
190-
Model = config.Model,
155+
Model = config.Model
191156
};
192157
}
193158
}

0 commit comments

Comments
 (0)