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 Together provider support to LangChain CLI #238

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/Providers.cs` ✓ https://github.com/tryAGI/LangChain/commit/8724d6bfb930b4932e0f67815d6ff6c3a00b7e56 [Edit](https://github.com/tryAGI/LangChain/edit/sweep/add_together_provider_support_to_langcha_72208/src/Cli/src/Providers.cs) - [X] Modify `src/Cli/src/Commands/SummarizeCommand.cs` ✓ https://github.com/tryAGI/LangChain/commit/8724d6bfb930b4932e0f67815d6ff6c3a00b7e56 [Edit](https://github.com/tryAGI/LangChain/edit/sweep/add_together_provider_support_to_langcha_72208/src/Cli/src/Commands/SummarizeCommand.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: ad85373223).


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

File Path Proposed Changes
src/Cli/src/Providers.cs Modify src/Cli/src/Providers.cs with contents:
In the Providers class, add a new constant for the Together provider:

```csharp
public const string TogetherAi = "togetherai";
```

This will allow us to check for and use the Together provider in other parts of the CLI code.
src/Cli/src/Commands/SummarizeCommand.cs Modify src/Cli/src/Commands/SummarizeCommand.cs with contents:
In the SummarizeCommand class, modify the HandleAsync method to support the Together provider:

First, add a new Option for specifying the provider:

``csharp<br/>var providerOption = new Option<string>(<br/> aliases: ["--provider", "-p"], <br/> getDefaultValue: () => Providers.OpenAi,<br/> description: "Provider to use for summarization (default: OpenAI)");<br/><br/>AddOption(providerOption);<br/>\```<br/><br/>Then update the method signature to accept the provider option:<br/><br/>\```csharp <br/>private static async Task HandleAsync(string input, string inputPath, string outputPath, int wordCount, string provider) <br/>\```<br/><br/>Inside the method, check if the Together provider is specified. If so, use the TogetherAiModel to generate the summary:<br/><br/>\```csharp<br/>if (provider == Providers.TogetherAi)<br/>{<br/> var togetherAiProvider = new TogetherAiProvider();<br/> var model = new TogetherAiModel(togetherAiProvider, TogetherAiModelIds.TogetherAiGpt3_5);<br/> <br/> outputText = await model.GenerateAsync(<br/> $"""<br/> Please summarize the the following text in {wordCount} words or less:<br/> {inputText}<br/> """);<br/>}<br/>else <br/>{<br/> outputText = await Helpers.GenerateUsingAuthenticatedModelAsync(<br/> $"""<br/> Please summarize the the following text in {wordCount} words or less:<br/> {inputText}<br/> """).ConfigureAwait(false);<br/>}<br/>\```<br/><br/>This checks if theproviderargument equals the newProviders.TogetherAiconstant. If so, it creates aTogetherAiProviderandTogetherAiModelto generate the summary. Otherwise, it falls back to the existing OpenAI provider logic.<br/><br/>TheTogetherAiModelconstructor takes the provider instance and aTogetherAiModelIds` enum value to specify which Together model to use.

🎉 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.