@@ -38,7 +38,7 @@ public MicrosoftExtensionsAIChatCompletionProvider(
3838 IServiceProvider services )
3939 {
4040 _client = client ;
41- _model = _client . Metadata . ModelId ;
41+ _model = _client . GetService < ChatClientMetadata > ( ) ? . ModelId ;
4242 _logger = logger ;
4343 _services = services ;
4444 }
@@ -71,14 +71,7 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
7171 if ( agentService . RenderFunction ( agent , function ) )
7272 {
7373 var property = agentService . RenderFunctionProperty ( agent , function ) ;
74- ( options . Tools ??= [ ] ) . Add ( new NopAIFunction ( new ( function . Name )
75- {
76- Description = function . Description ,
77- Parameters = property ? . Properties . RootElement . Deserialize < Dictionary < string , object ? > > ( ) ? . Select ( p => new AIFunctionParameterMetadata ( p . Key )
78- {
79- Schema = p . Value ,
80- } ) . ToList ( ) ?? [ ] ,
81- } ) ) ;
74+ ( options . Tools ??= [ ] ) . Add ( new NopAIFunction ( function . Name , function . Description , JsonSerializer . SerializeToElement ( property ) ) ) ;
8275 }
8376 }
8477 }
@@ -111,7 +104,7 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
111104 messages . Add ( new ( ChatRole . Assistant ,
112105 [
113106 new FunctionCallContent ( x . FunctionName , x . FunctionName , JsonSerializer . Deserialize < Dictionary < string , object ? > > ( x . FunctionArgs ?? "{}" ) ) ,
114- new FunctionResultContent ( x . FunctionName , x . FunctionName , x . Content )
107+ new FunctionResultContent ( x . FunctionName , x . Content )
115108 ] ) ) ;
116109 }
117110 else if ( x . Role == AgentRole . System || x . Role == AgentRole . Assistant )
@@ -127,17 +120,17 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
127120 {
128121 if ( ! string . IsNullOrEmpty ( file . FileData ) )
129122 {
130- contents . Add ( new ImageContent ( file . FileData ) ) ;
123+ contents . Add ( new DataContent ( file . FileData ) ) ;
131124 }
132125 else if ( ! string . IsNullOrEmpty ( file . FileStorageUrl ) )
133126 {
134127 var contentType = FileUtility . GetFileContentType ( file . FileStorageUrl ) ;
135128 var bytes = fileStorage ! . GetFileBytes ( file . FileStorageUrl ) ;
136- contents . Add ( new ImageContent ( bytes , contentType ) ) ;
129+ contents . Add ( new DataContent ( bytes , contentType ) ) ;
137130 }
138131 else if ( ! string . IsNullOrEmpty ( file . FileUrl ) )
139132 {
140- contents . Add ( new ImageContent ( file . FileUrl ) ) ;
133+ contents . Add ( new DataContent ( file . FileUrl ) ) ;
141134 }
142135 }
143136 }
@@ -146,7 +139,7 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
146139 }
147140 }
148141
149- var completion = await _client . CompleteAsync ( messages ) ;
142+ var completion = await _client . GetResponseAsync ( messages ) ;
150143
151144 RoleDialogModel result = new ( AgentRole . Assistant , string . Concat ( completion . Message . Contents . OfType < TextContent > ( ) ) )
152145 {
@@ -175,9 +168,13 @@ public Task<bool> GetChatCompletionsAsync(Agent agent, List<RoleDialogModel> con
175168 public Task < bool > GetChatCompletionsStreamingAsync ( Agent agent , List < RoleDialogModel > conversations , Func < RoleDialogModel , Task > onMessageReceived ) =>
176169 throw new NotImplementedException ( ) ;
177170
178- private sealed class NopAIFunction ( AIFunctionMetadata metadata ) : AIFunction
171+ private sealed class NopAIFunction ( string name , string description , JsonElement schema ) : AIFunction
179172 {
180- public override AIFunctionMetadata Metadata { get ; } = metadata ;
173+ public override string Name => name ;
174+
175+ public override string Description => description ;
176+
177+ public override JsonElement JsonSchema => schema ;
181178
182179 protected override Task < object ? > InvokeCoreAsync ( IEnumerable < KeyValuePair < string , object ? > > arguments , CancellationToken cancellationToken ) =>
183180 throw new NotSupportedException ( ) ;
0 commit comments