From f91982aa28f1302b9dc6d84c2bb73acebf9715a1 Mon Sep 17 00:00:00 2001 From: HavenDV Date: Fri, 12 Jul 2024 20:06:30 +0400 Subject: [PATCH] refactor: Add helper. --- Ollama.sln | 7 +++++ .../FixOpenApiSpec/FixOpenApiSpec.csproj | 15 +++++++++++ src/helpers/FixOpenApiSpec/Program.cs | 27 +++++++++++++++++++ src/libs/Ollama/generate.sh | 4 +-- 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/helpers/FixOpenApiSpec/FixOpenApiSpec.csproj create mode 100644 src/helpers/FixOpenApiSpec/Program.cs diff --git a/Ollama.sln b/Ollama.sln index 3e072fa..16bbabc 100755 --- a/Ollama.sln +++ b/Ollama.sln @@ -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 @@ -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 @@ -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} diff --git a/src/helpers/FixOpenApiSpec/FixOpenApiSpec.csproj b/src/helpers/FixOpenApiSpec/FixOpenApiSpec.csproj new file mode 100644 index 0000000..fa04206 --- /dev/null +++ b/src/helpers/FixOpenApiSpec/FixOpenApiSpec.csproj @@ -0,0 +1,15 @@ + + + + net8.0 + Exe + preview + enable + enable + + + + + + + diff --git a/src/helpers/FixOpenApiSpec/Program.cs b/src/helpers/FixOpenApiSpec/Program.cs new file mode 100644 index 0000000..ea77048 --- /dev/null +++ b/src/helpers/FixOpenApiSpec/Program.cs @@ -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); \ No newline at end of file diff --git a/src/libs/Ollama/generate.sh b/src/libs/Ollama/generate.sh index bd3c633..34f2ebb 100644 --- a/src/libs/Ollama/generate.sh +++ b/src/libs/Ollama/generate.sh @@ -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