Skip to content

Commit

Permalink
refactor: Refactored OpenRouter generator tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Apr 7, 2024
1 parent 16be418 commit db1a795
Show file tree
Hide file tree
Showing 14 changed files with 986 additions and 1,373 deletions.
1,493 changes: 677 additions & 816 deletions src/Providers/OpenRouter/src/OpenRouterModelIds.cs

Large diffs are not rendered by default.

262 changes: 125 additions & 137 deletions src/Providers/OpenRouter/src/OpenRouterModelProvider.cs

Large diffs are not rendered by default.

27 changes: 5 additions & 22 deletions src/Providers/OpenRouter/src/Predefined/AllModels.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using LangChain.Providers.OpenRouter;

namespace LangChain.Providers.OpenRouter.Predefined;

/// <inheritdoc cref="OpenRouterModelIds.NousCapybara7BFree"/>
Expand All @@ -17,26 +15,11 @@ public class Mistral7BInstructFreeModel(OpenRouterProvider provider) : OpenRoute
public class Mythomist7BFreeModel(OpenRouterProvider provider) : OpenRouterModel(provider, OpenRouterModelIds.Mythomist7BFree);


/// <inheritdoc cref="OpenRouterModelIds.ToppyM7BFree"/>
/// <param name="provider">Open Router Provider Instance</param>
public class ToppyM7BFreeModel(OpenRouterProvider provider) : OpenRouterModel(provider, OpenRouterModelIds.ToppyM7BFree);


/// <inheritdoc cref="OpenRouterModelIds.Cinematika7BAlphaFree"/>
/// <param name="provider">Open Router Provider Instance</param>
public class Cinematika7BAlphaFreeModel(OpenRouterProvider provider) : OpenRouterModel(provider, OpenRouterModelIds.Cinematika7BAlphaFree);


/// <inheritdoc cref="OpenRouterModelIds.GoogleGemma7BFree"/>
/// <param name="provider">Open Router Provider Instance</param>
public class GoogleGemma7BFreeModel(OpenRouterProvider provider) : OpenRouterModel(provider, OpenRouterModelIds.GoogleGemma7BFree);


/// <inheritdoc cref="OpenRouterModelIds.Psyfighter13B"/>
/// <param name="provider">Open Router Provider Instance</param>
public class Psyfighter13BModel(OpenRouterProvider provider) : OpenRouterModel(provider, OpenRouterModelIds.Psyfighter13B);


/// <inheritdoc cref="OpenRouterModelIds.PsyfighterV213B"/>
/// <param name="provider">Open Router Provider Instance</param>
public class PsyfighterV213BModel(OpenRouterProvider provider) : OpenRouterModel(provider, OpenRouterModelIds.PsyfighterV213B);
Expand Down Expand Up @@ -327,11 +310,6 @@ public class PerplexitySonar7BModel(OpenRouterProvider provider) : OpenRouterMod
public class PerplexitySonar8X7BModel(OpenRouterProvider provider) : OpenRouterModel(provider, OpenRouterModelIds.PerplexitySonar8X7B);


/// <inheritdoc cref="OpenRouterModelIds.PerplexitySonar7BOnline"/>
/// <param name="provider">Open Router Provider Instance</param>
public class PerplexitySonar7BOnlineModel(OpenRouterProvider provider) : OpenRouterModel(provider, OpenRouterModelIds.PerplexitySonar7BOnline);


/// <inheritdoc cref="OpenRouterModelIds.PerplexitySonar8X7BOnline"/>
/// <param name="provider">Open Router Provider Instance</param>
public class PerplexitySonar8X7BOnlineModel(OpenRouterProvider provider) : OpenRouterModel(provider, OpenRouterModelIds.PerplexitySonar8X7BOnline);
Expand Down Expand Up @@ -562,3 +540,8 @@ public class CohereCommandModel(OpenRouterProvider provider) : OpenRouterModel(p
public class CohereCommandRModel(OpenRouterProvider provider) : OpenRouterModel(provider, OpenRouterModelIds.CohereCommandR);


/// <inheritdoc cref="OpenRouterModelIds.CohereCommandRPlus"/>
/// <param name="provider">Open Router Provider Instance</param>
public class CohereCommandRPlusModel(OpenRouterProvider provider) : OpenRouterModel(provider, OpenRouterModelIds.CohereCommandRPlus);


Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Net;
using System.Globalization;
using System.Net;
using HtmlAgilityPack;

namespace LangChain.Providers.OpenRouter.CodeGenerator.Helpers;

public class DocumentHelper
{
private string _DocHTML;
private string _docHtml = string.Empty;

public DocumentHelper()
{
Expand All @@ -21,40 +22,42 @@ public DocumentHelper()

public string DocumentText
{
get => _DocHTML;
get => _docHtml;

set
{
if (!string.IsNullOrEmpty(value))
{
Document = new HtmlDocument();
Document.LoadHtml(value);
_DocHTML = value;
_docHtml = value;
}
else
{
_DocHTML = "";
_docHtml = "";
Document = new HtmlDocument();
}
}
}

public HtmlNode FindNode(string TagName, string AttibuteName, string AttributeValue, bool Approx)
public HtmlNode? FindNode(string tagName, string attributeName, string attributeValue, bool approx)
{
if (!Approx)
tagName = tagName ?? throw new ArgumentNullException(nameof(tagName));

if (!approx)
{
var htmlNode =
Document.DocumentNode.SelectSingleNode(string.Format("//{0}[@{1}='{2}']", TagName.ToLower(),
AttibuteName, AttributeValue));
Document.DocumentNode.SelectSingleNode(string.Format("//{0}[@{1}='{2}']", tagName.ToLower(CultureInfo.InvariantCulture),
attributeName, attributeValue));

if (htmlNode != null) return htmlNode;
}
else
{
foreach (var nd in Document.DocumentNode.Descendants(TagName.ToLower()))
if (nd.Attributes[AttibuteName] != null)
if (!string.IsNullOrEmpty(nd.Attributes[AttibuteName].Value))
if (nd.Attributes[AttibuteName].Value.ToLower().Contains(AttributeValue.ToLower()))
foreach (var nd in Document.DocumentNode.Descendants(tagName.ToLower(CultureInfo.InvariantCulture)))
if (nd.Attributes[attributeName] != null)
if (!string.IsNullOrEmpty(nd.Attributes[attributeName].Value))
if (nd.Attributes[attributeName].Value.Contains(attributeValue, StringComparison.InvariantCultureIgnoreCase))
return nd;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,22 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);CA1303;CA1305;CA1304;CA1308</NoWarn>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Resources\AllModels.cs" />
<Compile Remove="Resources\OpenRouterModelIds.cs" />
<Compile Remove="Resources\OpenRouterModelProvider.cs" />
</ItemGroup>

<ItemGroup>
<None Include="Resources\AllModels.cs" />
<None Include="Resources\OpenRouterModelIds.cs" />
<None Include="Resources\OpenRouterModelProvider.cs" />
<Compile Remove="Resources\*.cs" />
<None Include="Resources\*.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="H.Resources.Generator">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="HtmlAgilityPack" />
<PackageReference Include="System.CommandLine" />
<PackageReference Include="System.CommandLine.NamingConventionBinder" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace LangChain.Providers.OpenRouter.CodeGenerator.Main;

public class GenerationOptions
{
public string OutputFolder { get; set; } = "Generated";
public Func<string, string, string, string>? ReplaceEnumNameFunc { get; set; }
}
Loading

0 comments on commit db1a795

Please sign in to comment.