Skip to content

Commit

Permalink
Fixed contentful issue that partly hydrates second and subsequent ent…
Browse files Browse the repository at this point in the history
…ries for a parent
  • Loading branch information
andresharpe committed Jun 13, 2024
1 parent 920b081 commit fc845be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
6 changes: 0 additions & 6 deletions sln.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{D35DD32C
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cut.Lib", "source\Cut.Lib\Cut.Lib.csproj", "{FD9C605B-BD40-437E-B27E-3BBFCB9726EA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contentful.Core", "..\contentful.net\Contentful.Core\Contentful.Core.csproj", "{3E897A98-C7A3-4BC6-9057-57B21BFD6CB5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -33,10 +31,6 @@ Global
{FD9C605B-BD40-437E-B27E-3BBFCB9726EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD9C605B-BD40-437E-B27E-3BBFCB9726EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD9C605B-BD40-437E-B27E-3BBFCB9726EA}.Release|Any CPU.Build.0 = Release|Any CPU
{3E897A98-C7A3-4BC6-9057-57B21BFD6CB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E897A98-C7A3-4BC6-9057-57B21BFD6CB5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E897A98-C7A3-4BC6-9057-57B21BFD6CB5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E897A98-C7A3-4BC6-9057-57B21BFD6CB5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 1 addition & 4 deletions source/Cut.Lib/Cut.Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="2.0.0-beta.1" />
<PackageReference Include="ClosedXML" Version="0.102.2" />
<PackageReference Include="contentful.csharp" Version="7.5.3" />
<PackageReference Include="CsvHelper" Version="32.0.3" />
<PackageReference Include="Html2Markdown" Version="6.2.1.4" />
<PackageReference Include="scriban" Version="5.10.0" />
<PackageReference Include="YamlDotNet" Version="15.1.6" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\contentful.net\Contentful.Core\Contentful.Core.csproj" />
</ItemGroup>

</Project>
21 changes: 19 additions & 2 deletions source/Cut/Commands/GenerateCommand.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Azure;
using Azure.AI.OpenAI;
using Contentful.Core;
using Contentful.Core.Configuration;
using Contentful.Core.Models;
using Contentful.Core.Search;
using Cut.Constants;
using Cut.Lib.Exceptions;
using Cut.Services;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Spreadsheet;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenAI.Chat;
using Scriban;
Expand Down Expand Up @@ -100,7 +103,14 @@ public override async Task<int> ExecuteAsync(CommandContext context, Settings se
PresencePenalty = 0,
};

var cfclient = new ContentfulClient(new HttpClient(), _appSettings.ContentfulDeliveryApiKey, _appSettings.ContentfulPreviewApiKey, _appSettings.DefaultSpace);
var cfoptions = new ContentfulOptions()
{
DeliveryApiKey = _appSettings.ContentfulDeliveryApiKey,
PreviewApiKey = _appSettings.ContentfulPreviewApiKey,
SpaceId = _appSettings.DefaultSpace,
ResolveEntriesSelectively = true,
};
var cfclient = new ContentfulClient(new HttpClient(), cfoptions);

var entries = Entries(cfclient, contentType.SystemProperties.Id, contentType.DisplayField);

Expand Down Expand Up @@ -128,9 +138,16 @@ public override async Task<int> ExecuteAsync(CommandContext context, Settings se

_console.WriteBlankLine();

var prompt = ReplaceFields(promptMainPrompt, entry);

_console.WriteDim(prompt);

_console.WriteBlankLine();
_console.WriteBlankLine();

List<ChatMessage> messages = [
new SystemChatMessage(promptSystemMessage),
new UserChatMessage(ReplaceFields(promptMainPrompt, entry)),
new UserChatMessage(prompt),
];

_console.WriteBlankLine();
Expand Down

0 comments on commit fc845be

Please sign in to comment.