Add function call integration tests (#90)

* Add function call tests

* Address PR comment
This commit is contained in:
westey
2025-06-23 09:02:17 +00:00
committed by GitHub
parent 578b35723a
commit 5f2af80735
8 changed files with 175 additions and 100 deletions
@@ -18,13 +18,12 @@ public class OpenAIChatCompletionFixture : IChatClientAgentFixture
private static readonly OpenAIConfiguration s_config = TestConfiguration.LoadSection<OpenAIConfiguration>();
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
private IChatClient _chatClient;
private Agent _agent;
private ChatClientAgent _agent;
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
public Agent Agent => this._agent;
public IChatClient ChatClient => this._chatClient;
public IChatClient ChatClient => this._agent.ChatClient;
public async Task<List<ChatMessage>> GetChatHistoryAsync(AgentThread thread)
{
@@ -36,16 +35,20 @@ public class OpenAIChatCompletionFixture : IChatClientAgentFixture
return await chatClientThread.GetMessagesAsync().ToListAsync();
}
public Task<ChatClientAgent> CreateAgentWithInstructionsAsync(string instructions)
public Task<ChatClientAgent> CreateChatClientAgentAsync(
string name = "HelpfulAssistant",
string instructions = "You are a helpful assistant.",
IList<AITool>? aiTools = null)
{
this._chatClient = new OpenAIClient(s_config.ApiKey)
var chatClient = new OpenAIClient(s_config.ApiKey)
.GetChatClient(s_config.ChatModelId)
.AsIChatClient();
return Task.FromResult(new ChatClientAgent(this._chatClient, new()
return Task.FromResult(new ChatClientAgent(chatClient, new()
{
Name = "HelpfulAssistant",
Name = name,
Instructions = instructions,
ChatOptions = new() { Tools = aiTools }
}));
}
@@ -61,25 +64,13 @@ public class OpenAIChatCompletionFixture : IChatClientAgentFixture
return Task.CompletedTask;
}
public Task InitializeAsync()
public async Task InitializeAsync()
{
this._chatClient = new OpenAIClient(s_config.ApiKey)
.GetChatClient(s_config.ChatModelId)
.AsIChatClient();
this._agent =
new ChatClientAgent(this._chatClient, new()
{
Name = "HelpfulAssistant",
Instructions = "You are a helpful assistant.",
});
return Task.CompletedTask;
this._agent = await this.CreateChatClientAgentAsync();
}
public Task DisposeAsync()
{
this._chatClient.Dispose();
return Task.CompletedTask;
}
}