Skip to content

Commit

Permalink
docs: Added generation of samples.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jul 31, 2024
1 parent 64851da commit a41e409
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
paths:
- 'docs/**'
- 'mkdocs.yml'
- 'examples/**'

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
Expand All @@ -31,6 +32,9 @@ jobs:

- name: Install dependencies
run: pip install mkdocs-material

- name: Generate docs
run: dotnet run --project src/Helpers/GenerateDocs/GenerateDocs.csproj .

- name: Build with MkDocs
run: mkdocs build -d ./_site
Expand Down
7 changes: 7 additions & 0 deletions LangChain.sln
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{20D58A8D-D
docs\media\icon128.png = docs\media\icon128.png
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenerateDocs", "src\Helpers\GenerateDocs\GenerateDocs.csproj", "{EFFC19CE-9519-492D-A5CC-E1C90EB410E0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -765,6 +767,10 @@ Global
{90BC5243-139D-4CB2-8B68-3794070C1955}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90BC5243-139D-4CB2-8B68-3794070C1955}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90BC5243-139D-4CB2-8B68-3794070C1955}.Release|Any CPU.Build.0 = Release|Any CPU
{EFFC19CE-9519-492D-A5CC-E1C90EB410E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EFFC19CE-9519-492D-A5CC-E1C90EB410E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EFFC19CE-9519-492D-A5CC-E1C90EB410E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EFFC19CE-9519-492D-A5CC-E1C90EB410E0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -915,6 +921,7 @@ Global
{2DFDBF23-50E2-41DB-B2D5-CB2CC46D8C3B} = {E2B9833C-0397-4FAF-A3A8-116E58749750}
{90BC5243-139D-4CB2-8B68-3794070C1955} = {2DFDBF23-50E2-41DB-B2D5-CB2CC46D8C3B}
{20D58A8D-DB93-47AC-956B-9EB89EA75928} = {23506EB8-1B27-4FD0-B570-2F5EF2C33034}
{EFFC19CE-9519-492D-A5CC-E1C90EB410E0} = {1325D29E-D42F-423F-A6AC-5E880BE2AB68}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5C00D0F1-6138-4ED9-846B-97E43D6DFF1C}
Expand Down
6 changes: 4 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
site_name: LangChain .NET Documentation
#nav:
# - Overview: index.md
nav:
- Overview: index.md
# EXAMPLES #

# - Quick Start: QuickStart.md
# - Architecture: Architecture.md
# - FAQ: FAQ.md
Expand Down
9 changes: 9 additions & 0 deletions src/Helpers/GenerateDocs/GenerateDocs.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

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

</Project>
27 changes: 27 additions & 0 deletions src/Helpers/GenerateDocs/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var solutionDirectory = args.ElementAtOrDefault(0) ?? Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "../../../../../.."));
var sampleDirectory = Path.Combine(solutionDirectory, "examples");
var mkDocsPath = Path.Combine(solutionDirectory, "mkdocs.yml");

Console.WriteLine($"Generating samples from {sampleDirectory}...");
foreach (var path in Directory.EnumerateFiles(sampleDirectory, "Program.cs", SearchOption.AllDirectories))
{
var folder = Path.GetFileName(Path.GetDirectoryName(path) ?? string.Empty)?.Replace("LangChain.Samples.", string.Empty);
var code = await File.ReadAllTextAsync(path);

var newDir = Path.Combine(solutionDirectory, "docs", "samples");
Directory.CreateDirectory(newDir);

var newPath = Path.Combine(newDir, $"{folder}.md");
await File.WriteAllTextAsync(newPath, $@"```csharp
{code}
```");
}

var mkDocs = await File.ReadAllTextAsync(mkDocsPath);
var newMkDocs = mkDocs.Replace(
"# EXAMPLES #",
$"- Examples:{string.Concat(Directory.EnumerateFiles(Path.Combine(solutionDirectory, "docs", "samples"), "*.md")
.Select(x => $@"
- {Path.GetFileNameWithoutExtension(x)}: samples/{Path.GetFileNameWithoutExtension(x)}.md"))}");
await File.WriteAllTextAsync(mkDocsPath, newMkDocs);

0 comments on commit a41e409

Please sign in to comment.