tryAGI / LangChain

C# implementation of LangChain. We try to be as close to the original as possible in terms of abstractions, but are open to new entities.
https://tryagi.github.io/LangChain/
MIT License
507 stars 78 forks source link

Add options like temperature to LangChain CLI OpenAI provider command #239

Open HavenDV opened 4 months ago

HavenDV commented 4 months ago

What would you like to be added:

Why is this needed:

Anything else we need to know?

Checklist - [X] Modify `src/Cli/src/Commands/Auth/OpenAiCommand.cs` ✓ https://github.com/tryAGI/LangChain/commit/09d364b4e0600e2cba75210cbfae321f06b13642 [Edit](https://github.com/tryAGI/LangChain/edit/sweep/add_options_like_temperature_to_langchai/src/Cli/src/Commands/Auth/OpenAiCommand.cs) - [X] Modify `src/Cli/src/Commands/Auth/OpenAiCommand.cs` ✓ https://github.com/tryAGI/LangChain/commit/09d364b4e0600e2cba75210cbfae321f06b13642 [Edit](https://github.com/tryAGI/LangChain/edit/sweep/add_options_like_temperature_to_langchai/src/Cli/src/Commands/Auth/OpenAiCommand.cs) - [X] Modify `src/Providers/OpenAI/src/OpenAiConfiguration.cs` ✓ https://github.com/tryAGI/LangChain/commit/09d364b4e0600e2cba75210cbfae321f06b13642 [Edit](https://github.com/tryAGI/LangChain/edit/sweep/add_options_like_temperature_to_langchai/src/Providers/OpenAI/src/OpenAiConfiguration.cs)
sweep-ai[bot] commented 4 months ago

[!TIP] I can email you next time I complete a pull request if you set up your email here!


Actions (click)


❌ Unable to Complete PR

I'm sorry, but it looks like an error has occurred due to a planning failure. Feel free to add more details to the issue description so Sweep can better address it. Alternatively, reach out to Kevin or William for help at https://discord.gg/sweep.

For bonus GPT-4 tickets, please report this bug on Discord (tracking ID: 3e0d1ac776).


Please look at the generated plan. If something looks wrong, please add more details to your issue.

File Path Proposed Changes
src/Cli/src/Commands/Auth/OpenAiCommand.cs Modify src/Cli/src/Commands/Auth/OpenAiCommand.cs with contents:
In the OpenAiCommand constructor, add a new Option for temperature after the modelOption:

```csharp
var temperatureOption = new Option<double?>(
aliases: ["--temperature", "-t"],
getDefaultValue: () => null,
description: "The temperature to use for OpenAI requests");
AddOption(temperatureOption);
```

Then update the SetHandler call to pass temperatureOption:

```csharp
this.SetHandler(HandleAsync, apiKeyArgument, modelOption, temperatureOption);
```
src/Cli/src/Commands/Auth/OpenAiCommand.cs Modify src/Cli/src/Commands/Auth/OpenAiCommand.cs with contents:
Update the HandleAsync method to accept the temperature parameter:

```csharp
private static async Task HandleAsync(string apiKey, string model, double? temperature)
{
await Helpers.AuthenticateWithApiKeyAsync(apiKey, model, Providers.OpenAi, temperature).ConfigureAwait(false);
}
```
src/Cli/src/Helpers.cs Modify src/Cli/src/Helpers.cs with contents:
Update the AuthenticateWithApiKeyAsync method signature to accept the temperature parameter:

```csharp
public static async Task AuthenticateWithApiKeyAsync(string apiKey, string model, string provider, double? temperature)
```
src/Cli/src/Helpers.cs Modify src/Cli/src/Helpers.cs with contents:
In the AuthenticateWithApiKeyAsync method, write the temperature value to a settings file after writing the model:

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

🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description.