File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed
dotnet/src/Agents/OpenAI/Extensions Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -44,8 +44,10 @@ public static IEnumerable<ThreadInitializationMessage> ToThreadInitializationMes
4444 public static ResponseItem ToResponseItem ( this ChatMessageContent message )
4545 {
4646 var items = message . Items ;
47- IEnumerable < ResponseContentPart > contentParts = items . Select ( item => item . ToResponseContentPart ( ) ) ;
48- return message . Role . Label . ToUpperInvariant ( ) switch
47+ var roleLabel = message . Role . Label . ToUpperInvariant ( ) ;
48+
49+ IEnumerable < ResponseContentPart > contentParts = items . Select ( item => item . ToResponseContentPart ( roleLabel == "ASSISTANT" ) ) ;
50+ return roleLabel switch
4951 {
5052 "SYSTEM" => ResponseItem . CreateSystemMessageItem ( contentParts ) ,
5153 "USER" => ResponseItem . CreateUserMessageItem ( contentParts ) ,
Original file line number Diff line number Diff line change @@ -10,21 +10,23 @@ namespace Microsoft.SemanticKernel.Agents.OpenAI;
1010/// </summary>
1111internal static class KernelContentExtensions
1212{
13- internal static ResponseContentPart ToResponseContentPart ( this KernelContent content )
13+ internal static ResponseContentPart ToResponseContentPart ( this KernelContent content , bool isOutput = false )
1414 {
1515 return content switch
1616 {
17- TextContent textContent => textContent . ToResponseContentPart ( ) ,
17+ TextContent textContent => textContent . ToResponseContentPart ( isOutput ) ,
1818 ImageContent imageContent => imageContent . ToResponseContentPart ( ) ,
1919 BinaryContent binaryContent => binaryContent . ToResponseContentPart ( ) ,
2020 FileReferenceContent fileReferenceContent => fileReferenceContent . ToResponseContentPart ( ) ,
2121 _ => throw new NotSupportedException ( $ "Unsupported content type { content . GetType ( ) . Name } . Cannot convert to { nameof ( ResponseContentPart ) } .")
2222 } ;
2323 }
2424
25- internal static ResponseContentPart ToResponseContentPart ( this TextContent content )
25+ internal static ResponseContentPart ToResponseContentPart ( this TextContent content , bool isOutput )
2626 {
27- return ResponseContentPart . CreateInputTextPart ( content . Text ) ;
27+ return isOutput ?
28+ ResponseContentPart . CreateOutputTextPart ( content . Text , [ ] ) :
29+ ResponseContentPart . CreateInputTextPart ( content . Text ) ;
2830 }
2931
3032 internal static ResponseContentPart ToResponseContentPart ( this ImageContent content )
You can’t perform that action at this time.
0 commit comments