Skip to content

Commit a1a44d1

Browse files
Copilotkzu
authored andcommitted
Split console logging package
1 parent ccb21b4 commit a1a44d1

10 files changed

Lines changed: 59 additions & 14 deletions

Extensions.AI.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
</Configurations>
77
<Project Path="src/Extensions.CodeAnalysis/Extensions.CodeAnalysis.csproj" />
88
<Project Path="src/Extensions/Extensions.csproj" />
9+
<Project Path="src/Extensions.Console/Extensions.Console.csproj" />
910
<Project Path="src/Tests/Tests.csproj" />
1011
</Solution>

readme.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,20 @@ else
115115

116116
OpenAI-specific extensions enable more seamless usage with the MS.E.AI API:
117117

118-
* Setting reasoning effort: the Microsoft.Extensions.AI API does not expose a way to set reasoning
119-
effort for reasoning-capable models, which is very useful for some models like
120-
[`gpt-5.2`](https://platform.openai.com/docs/guides/latest-model#lower-reasoning-effort)
121118
* Setting output verbosity: similarly, [output verbosity](https://platform.openai.com/docs/guides/latest-model#verbosity) is not exposed in the base API.
122119

123120
These can be used as extension properties on `ChatOptions` whenever `Devlooped.Extensions.AI.OpenAI` is imported:
124121

125122
```csharp
126123
var options = new ChatOptions
127124
{
128-
ReasoningEffort = ReasoningEffort.High, // 👈 or Medium/Low/Minimal/None, extension property
129125
Verbosity = Verbosity.Low // 👈 or Medium/High, extension property
130126
};
131127

132128
var response = await chat.GetResponseAsync(messages, options);
133129
```
134130

135-
Or you can opt to use the `ChatOptions`-derived `OpenAIChatOptions` class directly:
131+
Or you can opt to use the `ChatOptions`-derived `OpenAIChatOptions` class directly.
136132

137133
### Web Search
138134

@@ -199,11 +195,13 @@ var openai = new OpenAIClient(
199195
Environment.GetEnvironmentVariable("OPENAI_API_KEY")!,
200196
OpenAIClientOptions.Observable(requests.Add, responses.Add));
201197
```
198+
<!-- #extensions -->
202199

200+
<!-- #console -->
203201
## Console Logging
204202

205-
Additional `UseJsonConsoleLogging` extension for rich JSON-formatted console logging of AI requests
206-
are provided at two levels:
203+
Additional `UseJsonConsoleLogging` extension for rich JSON-formatted console logging
204+
of `IChatClient` requests and responses are provided at two levels:
207205

208206
* Chat pipeline: similar to `UseLogging`.
209207
* HTTP pipeline: lowest possible layer before the request is sent to the AI service,
@@ -241,7 +239,11 @@ IChatClient chat = new OpenAIChatClient(Environment.GetEnvironmentVariable("OPEN
241239
})
242240
.Build();
243241
```
244-
<!-- #extensions -->
242+
243+
> [!IMPORTANT]
244+
> By default, the logging will only be performed if the console is interactive.
245+
246+
<!-- #console -->
245247

246248
<!-- include https://github.com/devlooped/.github/raw/main/osmf.md -->
247249
## Open Source Maintenance Fee
File renamed without changes.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
5+
<LangVersion>Preview</LangVersion>
6+
<AssemblyName>Devlooped.Extensions.AI.Console</AssemblyName>
7+
<RootNamespace>Devlooped.Extensions.AI</RootNamespace>
8+
<PackageId>Devlooped.Extensions.AI.Console</PackageId>
9+
<Description>Console logging extensions for Devlooped.Extensions.AI</Description>
10+
<PackageLicenseExpression></PackageLicenseExpression>
11+
<PackageLicenseFile>OSMFEULA.txt</PackageLicenseFile>
12+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="NuGetizer" Version="1.4.7" PrivateAssets="all" />
17+
<PackageReference Include="Spectre.Console" Version="0.54.0" />
18+
<PackageReference Include="Spectre.Console.Json" Version="0.54.0" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<ProjectReference Include="..\Extensions\Extensions.csproj" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<None Include="..\..\osmfeula.txt" Link="osmfeula.txt" PackagePath="OSMFEULA.txt" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<InternalsVisibleTo Include="Devlooped.Agents.AI" />
31+
<InternalsVisibleTo Include="Tests" />
32+
</ItemGroup>
33+
34+
</Project>

src/Extensions/Console/JsonConsoleLoggingExtensions.cs renamed to src/Extensions.Console/JsonConsoleLoggingExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public ChatClientBuilder UseJsonConsoleLogging(JsonConsoleOptions? consoleOption
5151
{
5252
consoleOptions ??= JsonConsoleOptions.Default;
5353

54-
if (consoleOptions.InteractiveConfirm && ConsoleExtensions.IsConsoleInteractive && !AnsiConsole.Confirm("Do you want to enable rich JSON console logging for HTTP pipeline messages?"))
54+
if (consoleOptions.InteractiveConfirm && ConsoleExtensions.IsConsoleInteractive && !AnsiConsole.Confirm("Do you want to enable rich JSON console logging for chat messages and responses?"))
5555
return builder;
5656

5757
if (consoleOptions.InteractiveOnly && !ConsoleExtensions.IsConsoleInteractive)

src/Extensions/Console/JsonConsoleOptions.cs renamed to src/Extensions.Console/JsonConsoleOptions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,16 @@ internal Panel CreatePanel(object value)
144144
}
145145

146146
#pragma warning disable CS9113 // Parameter is unread. BOGUS
147-
sealed class WrappedJsonText(string json, int maxWidth) : Renderable
147+
sealed class WrappedJsonText(string json, int fixedMaxWidth) : Renderable
148148
#pragma warning restore CS9113 // Parameter is unread. BOGUS
149149
{
150150
readonly JsonText jsonText = new(json);
151151

152152
protected override Measurement Measure(RenderOptions options, int maxWidth)
153153
{
154154
// Clamp the measurement to the desired maxWidth
155-
return new Measurement(Math.Min(maxWidth, maxWidth), Math.Min(maxWidth, maxWidth));
155+
var width = Math.Min(fixedMaxWidth, maxWidth);
156+
return new Measurement(width, width);
156157
}
157158

158159
protected override IEnumerable<Segment> Render(RenderOptions options, int maxWidth)
@@ -170,7 +171,7 @@ protected override IEnumerable<Segment> Render(RenderOptions options, int maxWid
170171
var idx = 0;
171172
while (idx < text.Length)
172173
{
173-
var len = Math.Min(maxWidth, text.Length - idx);
174+
var len = Math.Min(fixedMaxWidth, text.Length - idx);
174175
wrapped.Add(new Segment(text.Substring(idx, len), style));
175176
idx += len;
176177
if (idx < text.Length)

src/Extensions.Console/readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[![EULA](https://img.shields.io/badge/EULA-OSMF-blue?labelColor=black&color=C9FF30)](osmfeula.txt)
2+
[![OSS](https://img.shields.io/github/license/devlooped/oss.svg?color=blue)](license.txt)
3+
[![GitHub](https://img.shields.io/badge/-source-181717.svg?logo=GitHub)](https://github.com/devlooped/AI)
4+
5+
<!-- include ../../readme.md#console -->
6+
<!-- include https://github.com/devlooped/.github/raw/main/osmf.md -->
7+
<!-- include https://github.com/devlooped/sponsors/raw/main/footer.md -->
8+
<!-- exclude -->

src/Extensions/Extensions.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
<PackageReference Include="NuGetizer" Version="1.4.7" PrivateAssets="all" />
2525
<PackageReference Include="Microsoft.Extensions.AI" Version="10.3.0" />
2626
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="10.3.0" />
27-
<PackageReference Include="Spectre.Console" Version="0.54.0" />
28-
<PackageReference Include="Spectre.Console.Json" Version="0.54.0" />
2927
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.4" />
3028
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.4" />
3129
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.4" />

src/Tests/Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<ItemGroup>
3434
<ProjectReference Include="..\Extensions.CodeAnalysis\Extensions.CodeAnalysis.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
3535
<ProjectReference Include="..\Extensions\Extensions.csproj" />
36+
<ProjectReference Include="..\Extensions.Console\Extensions.Console.csproj" />
3637
</ItemGroup>
3738

3839
<ItemGroup>

0 commit comments

Comments
 (0)