Skip to content

Commit

Permalink
docs: Fixed generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Aug 19, 2024
1 parent 008a153 commit b256815
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
- 'docs/**'
- 'mkdocs.yml'
- 'examples/**'
- 'src/helpers/GenerateDocs/**'
- '.github/workflows/mkdocs.yml'

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
Expand Down
3 changes: 3 additions & 0 deletions LangSmith.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
docs\openapi.yaml = docs\openapi.yaml
docs\openapi.json = docs\openapi.json
.github\workflows\pull-request.yml = .github\workflows\pull-request.yml
.github\workflows\auto-merge.yml = .github\workflows\auto-merge.yml
.github\workflows\auto-update.yml = .github\workflows\auto-update.yml
.github\workflows\mkdocs.yml = .github\workflows\mkdocs.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libs", "libs", "{61E7E11E-4558-434C-ACE8-06316A3097B3}"
Expand Down
29 changes: 23 additions & 6 deletions src/helpers/GenerateDocs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,36 @@

File.Copy(
Path.Combine(solutionDirectory, "README.md"),
Path.Combine(solutionDirectory, "docs", "index.md"));
Path.Combine(solutionDirectory, "docs", "index.md"),
overwrite: true);

Console.WriteLine($"Generating samples from {sampleDirectory}...");
foreach (var path in Directory.EnumerateFiles(sampleDirectory, "Tests.*.cs", SearchOption.AllDirectories))
{
var code = await File.ReadAllTextAsync(path);

var start = code.IndexOf("\n {", StringComparison.Ordinal);
var end = code.IndexOf("\n }", StringComparison.Ordinal);
code = code.Substring(start + 4, end - start + 4);
var lines = code.Split('\n').ToList();
if (lines.All(x => string.IsNullOrWhiteSpace(x) || x.StartsWith("//")))
{
continue;
}

var lines = code.Split('\n')[1..^2];
code = string.Join('\n', lines.Select(x => x.Length > 8 ? x[8..] : string.Empty));
var start = lines.IndexOf(" {");
var end = lines.IndexOf(" }");
lines = lines.GetRange(start + 1, end - start - 1);

code = string.Join('\n', lines
.Where(x => !x.Contains(".Should()"))
.Select(x => x.Length > 8 ? x[8..] : string.Empty));

code = code
.Replace(
"using var api = GetAuthorizedApi();",
"using var api = new LangSmithApi(\"API_KEY\");")
.Replace(
"using var openAiApi = GetAuthorizedOpenAiApi();",
"using var openAiApi = new OpenAiApi(\"API_KEY\");")
;

var newPath = Path.Combine(newDir, $"{Path.GetExtension(Path.GetFileNameWithoutExtension(path)).TrimStart('.')}.md");
await File.WriteAllTextAsync(newPath, $@"```csharp
Expand Down

0 comments on commit b256815

Please sign in to comment.