Skip to content

Commit

Permalink
refactor: Add helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jul 12, 2024
1 parent 762b24b commit f91982a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Ollama.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "helpers", "helpers", "{C612
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrimmingHelper", "src\helpers\TrimmingHelper\TrimmingHelper.csproj", "{7F5D3C78-1AEE-4835-BFC8-4AB75CFCE2D5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FixOpenApiSpec", "src\helpers\FixOpenApiSpec\FixOpenApiSpec.csproj", "{283F8457-4385-4169-BAC6-BCD23CDB83F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -47,6 +49,10 @@ Global
{7F5D3C78-1AEE-4835-BFC8-4AB75CFCE2D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F5D3C78-1AEE-4835-BFC8-4AB75CFCE2D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F5D3C78-1AEE-4835-BFC8-4AB75CFCE2D5}.Release|Any CPU.Build.0 = Release|Any CPU
{283F8457-4385-4169-BAC6-BCD23CDB83F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{283F8457-4385-4169-BAC6-BCD23CDB83F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{283F8457-4385-4169-BAC6-BCD23CDB83F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{283F8457-4385-4169-BAC6-BCD23CDB83F3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -55,6 +61,7 @@ Global
{0028BC85-0064-4CE8-A21A-C1F5E922BD59} = {61E7E11E-4558-434C-ACE8-06316A3097B3}
{2C15EAC0-08E6-447A-84E2-1398DDE358AC} = {AAA11B78-2764-4520-A97E-46AA7089A588}
{7F5D3C78-1AEE-4835-BFC8-4AB75CFCE2D5} = {C612F166-61F7-4552-A52B-2494F45DB431}
{283F8457-4385-4169-BAC6-BCD23CDB83F3} = {C612F166-61F7-4552-A52B-2494F45DB431}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CED9A020-DBA5-4BE6-8096-75E528648EC1}
Expand Down
15 changes: 15 additions & 0 deletions src/helpers/FixOpenApiSpec/FixOpenApiSpec.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.15" />
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions src/helpers/FixOpenApiSpec/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.OpenApi;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Readers;

var path = args[0];
var text = await File.ReadAllTextAsync(path);

var openApiDocument = new OpenApiStringReader().Read(text, out var diagnostics);
//openApiDocument.Components.Schemas["ParallelToolCalls"]!.Default = null;
//openApiDocument.Components.Schemas["ParallelToolCalls"]!.Nullable = true;

//openApiDocument.Components.Schemas["CreateEmbeddingRequest"]!.Properties["dimensions"].Nullable = true;

text = openApiDocument.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
_ = new OpenApiStringReader().Read(text, out diagnostics);

if (diagnostics.Errors.Count > 0)
{
foreach (var error in diagnostics.Errors)
{
Console.WriteLine(error.Message);
}
// Return Exit code 1
Environment.Exit(1);
}

await File.WriteAllTextAsync(path, text);
4 changes: 2 additions & 2 deletions src/libs/Ollama/generate.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dotnet tool install --global openapigenerator.cli --prerelease
rm -rf Generated
# curl -O https://raw.githubusercontent.com/openai/openai-openapi/master/openapi.yaml
# dotnet run --project ../../helpers/FixOpenApiSpec openapi.yaml
# curl -o ../../../docs/openapi.yaml https://raw.githubusercontent.com/davidmigloz/langchain_dart/main/packages/ollama_dart/oas/ollama-curated.yaml
# dotnet run --project ../../helpers/FixOpenApiSpec ../../../docs/openapi.yaml
# if [ $? -ne 0 ]; then
# echo "Failed, exiting..."
# exit 1
Expand Down

0 comments on commit f91982a

Please sign in to comment.