Skip to content

Commit

Permalink
test: Refactor WeatherTools test to use custom providers.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Aug 6, 2024
1 parent d24f72b commit c25eb8c
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/tests/OpenAI.IntegrationTests/Tools/Tests.Tools.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using OpenAI;

namespace OpenAI.IntegrationTests;
namespace OpenAI.IntegrationTests;

public partial class Tests
{
[TestMethod]
//[Ignore]
public async Task SimpleMethod()
[DataTestMethod]
[DataRow(CustomProvider.OpenAi)]
// [DataRow(CustomProvider.Fireworks)]
// [DataRow(CustomProvider.DeepInfra)]
// [DataRow(CustomProvider.DeepSeek)]
// [DataRow(CustomProvider.OpenRouter)]
// [DataRow(CustomProvider.Together)]
public async Task WeatherTools(CustomProvider customProvider)
{
var pair = GetAuthorizedChatApi(customProvider);
using var api = pair.Api;

var messages = new List<ChatCompletionRequestMessage>
{
"You are a helpful weather assistant.".AsSystemMessage(),
"What is the current temperature in Dubai, UAE in Celsius?".AsUserMessage(),
};
var model = CreateChatCompletionRequestModel.Gpt35Turbo;

try
{
var apiKey =
Environment.GetEnvironmentVariable("OPENAI_API_KEY") ??
throw new AssertInconclusiveException("OPENAI_API_KEY is not set.");
using var api = new OpenAiApi();
api.AuthorizeUsingBearer(apiKey);
var service = new WeatherService();
var tools = service.AsTools();
var result = await api.Chat.CreateChatCompletionAsync(
messages,
model: model,
model: pair.Model,
tools: tools);
var resultMessage = result.Choices.First().Message;
messages.Add(resultMessage.AsRequestMessage());
Expand All @@ -51,7 +47,7 @@ public async Task SimpleMethod()

result = await api.Chat.CreateChatCompletionAsync(
messages,
model: model,
model: pair.Model,
tools: tools);
resultMessage = result.Choices.First().Message;
messages.Add(resultMessage.AsRequestMessage());
Expand Down

0 comments on commit c25eb8c

Please sign in to comment.