Skip to content

Commit

Permalink
feat: Updated 2 files
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Apr 23, 2024
1 parent c59ee9f commit ed21968
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/Cli/src/Commands/Auth/OpenAiCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ public OpenAiCommand() : base(name: Providers.OpenAi, description: "Authenticate
aliases: ["--model", "-m"],
getDefaultValue: () => ChatModels.Gpt35Turbo,
description: "Model to use for commands");
var temperatureOption = new Option<double?>(
aliases: ["--temperature", "-t"],
getDefaultValue: () => null,
description: "The temperature to use for OpenAI requests");
AddArgument(apiKeyArgument);
AddOption(modelOption);
AddOption(temperatureOption);

this.SetHandler(HandleAsync, apiKeyArgument, modelOption);
this.SetHandler(HandleAsync, apiKeyArgument, modelOption, temperatureOption);
}

private static async Task HandleAsync(string apiKey, string model)
private static async Task HandleAsync(string apiKey, string model, double? temperature)
{
await Helpers.AuthenticateWithApiKeyAsync(apiKey, model, Providers.OpenAi).ConfigureAwait(false);
await Helpers.AuthenticateWithApiKeyAsync(apiKey, model, Providers.OpenAi, temperature).ConfigureAwait(false);
}
}
7 changes: 6 additions & 1 deletion src/Cli/src/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ public static async Task SetModelAsync(string model)
Console.WriteLine($"Model set to {model}");
}

public static async Task AuthenticateWithApiKeyAsync(string apiKey, string model, string provider)
public static async Task AuthenticateWithApiKeyAsync(string apiKey, string model, string provider, double? temperature)
{
var settingsFolder = GetSettingsFolder();

await File.WriteAllTextAsync(Path.Combine(settingsFolder, "provider.txt"), provider).ConfigureAwait(false);
await File.WriteAllTextAsync(Path.Combine(settingsFolder, "api_key.txt"), apiKey).ConfigureAwait(false);
await SetModelAsync(model).ConfigureAwait(false);

if (temperature.HasValue)
{
await File.WriteAllTextAsync(Path.Combine(settingsFolder, "temperature.txt"), temperature.Value.ToString()).ConfigureAwait(false);
}
}

public static async Task<string> GenerateUsingAuthenticatedModelAsync(string prompt)
Expand Down

0 comments on commit ed21968

Please sign in to comment.