Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 13 additions & 55 deletions Extensions.AI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AI", "src\AI\AI.csproj", "{
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AI.Tests", "src\AI.Tests\AI.Tests.csproj", "{3553B2FB-B06C-4766-93FD-1B7004761080}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnet-meai", "src\dotnet-meai\dotnet-meai.csproj", "{58FC11CF-7D61-48B9-B95F-0EAA889D6DED}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Weaving", "src\Weaving\Weaving.csproj", "{0DA390D2-2953-4CB6-8939-02E142B11733}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples", "src\Samples\Samples.csproj", "{4B78F0E3-E03B-4283-AB0B-B1D76CAEF1BC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AI.CodeAnalysis", "src\AI.CodeAnalysis\AI.CodeAnalysis.csproj", "{F6A9F74B-5C63-4C53-9745-F00BE40AF8C8}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AI.CodeAnalysis", "src\AI.CodeAnalysis\AI.CodeAnalysis.csproj", "{EEBAD5E8-1C76-0F75-7DD2-8A97BD31567B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -49,54 +43,18 @@ Global
{3553B2FB-B06C-4766-93FD-1B7004761080}.Release|x64.Build.0 = Release|Any CPU
{3553B2FB-B06C-4766-93FD-1B7004761080}.Release|x86.ActiveCfg = Release|Any CPU
{3553B2FB-B06C-4766-93FD-1B7004761080}.Release|x86.Build.0 = Release|Any CPU
{58FC11CF-7D61-48B9-B95F-0EAA889D6DED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58FC11CF-7D61-48B9-B95F-0EAA889D6DED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58FC11CF-7D61-48B9-B95F-0EAA889D6DED}.Debug|x64.ActiveCfg = Debug|Any CPU
{58FC11CF-7D61-48B9-B95F-0EAA889D6DED}.Debug|x64.Build.0 = Debug|Any CPU
{58FC11CF-7D61-48B9-B95F-0EAA889D6DED}.Debug|x86.ActiveCfg = Debug|Any CPU
{58FC11CF-7D61-48B9-B95F-0EAA889D6DED}.Debug|x86.Build.0 = Debug|Any CPU
{58FC11CF-7D61-48B9-B95F-0EAA889D6DED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58FC11CF-7D61-48B9-B95F-0EAA889D6DED}.Release|Any CPU.Build.0 = Release|Any CPU
{58FC11CF-7D61-48B9-B95F-0EAA889D6DED}.Release|x64.ActiveCfg = Release|Any CPU
{58FC11CF-7D61-48B9-B95F-0EAA889D6DED}.Release|x64.Build.0 = Release|Any CPU
{58FC11CF-7D61-48B9-B95F-0EAA889D6DED}.Release|x86.ActiveCfg = Release|Any CPU
{58FC11CF-7D61-48B9-B95F-0EAA889D6DED}.Release|x86.Build.0 = Release|Any CPU
{0DA390D2-2953-4CB6-8939-02E142B11733}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0DA390D2-2953-4CB6-8939-02E142B11733}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0DA390D2-2953-4CB6-8939-02E142B11733}.Debug|x64.ActiveCfg = Debug|Any CPU
{0DA390D2-2953-4CB6-8939-02E142B11733}.Debug|x64.Build.0 = Debug|Any CPU
{0DA390D2-2953-4CB6-8939-02E142B11733}.Debug|x86.ActiveCfg = Debug|Any CPU
{0DA390D2-2953-4CB6-8939-02E142B11733}.Debug|x86.Build.0 = Debug|Any CPU
{0DA390D2-2953-4CB6-8939-02E142B11733}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0DA390D2-2953-4CB6-8939-02E142B11733}.Release|Any CPU.Build.0 = Release|Any CPU
{0DA390D2-2953-4CB6-8939-02E142B11733}.Release|x64.ActiveCfg = Release|Any CPU
{0DA390D2-2953-4CB6-8939-02E142B11733}.Release|x64.Build.0 = Release|Any CPU
{0DA390D2-2953-4CB6-8939-02E142B11733}.Release|x86.ActiveCfg = Release|Any CPU
{0DA390D2-2953-4CB6-8939-02E142B11733}.Release|x86.Build.0 = Release|Any CPU
{4B78F0E3-E03B-4283-AB0B-B1D76CAEF1BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B78F0E3-E03B-4283-AB0B-B1D76CAEF1BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B78F0E3-E03B-4283-AB0B-B1D76CAEF1BC}.Debug|x64.ActiveCfg = Debug|Any CPU
{4B78F0E3-E03B-4283-AB0B-B1D76CAEF1BC}.Debug|x64.Build.0 = Debug|Any CPU
{4B78F0E3-E03B-4283-AB0B-B1D76CAEF1BC}.Debug|x86.ActiveCfg = Debug|Any CPU
{4B78F0E3-E03B-4283-AB0B-B1D76CAEF1BC}.Debug|x86.Build.0 = Debug|Any CPU
{4B78F0E3-E03B-4283-AB0B-B1D76CAEF1BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B78F0E3-E03B-4283-AB0B-B1D76CAEF1BC}.Release|Any CPU.Build.0 = Release|Any CPU
{4B78F0E3-E03B-4283-AB0B-B1D76CAEF1BC}.Release|x64.ActiveCfg = Release|Any CPU
{4B78F0E3-E03B-4283-AB0B-B1D76CAEF1BC}.Release|x64.Build.0 = Release|Any CPU
{4B78F0E3-E03B-4283-AB0B-B1D76CAEF1BC}.Release|x86.ActiveCfg = Release|Any CPU
{4B78F0E3-E03B-4283-AB0B-B1D76CAEF1BC}.Release|x86.Build.0 = Release|Any CPU
{F6A9F74B-5C63-4C53-9745-F00BE40AF8C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6A9F74B-5C63-4C53-9745-F00BE40AF8C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6A9F74B-5C63-4C53-9745-F00BE40AF8C8}.Debug|x64.ActiveCfg = Debug|Any CPU
{F6A9F74B-5C63-4C53-9745-F00BE40AF8C8}.Debug|x64.Build.0 = Debug|Any CPU
{F6A9F74B-5C63-4C53-9745-F00BE40AF8C8}.Debug|x86.ActiveCfg = Debug|Any CPU
{F6A9F74B-5C63-4C53-9745-F00BE40AF8C8}.Debug|x86.Build.0 = Debug|Any CPU
{F6A9F74B-5C63-4C53-9745-F00BE40AF8C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6A9F74B-5C63-4C53-9745-F00BE40AF8C8}.Release|Any CPU.Build.0 = Release|Any CPU
{F6A9F74B-5C63-4C53-9745-F00BE40AF8C8}.Release|x64.ActiveCfg = Release|Any CPU
{F6A9F74B-5C63-4C53-9745-F00BE40AF8C8}.Release|x64.Build.0 = Release|Any CPU
{F6A9F74B-5C63-4C53-9745-F00BE40AF8C8}.Release|x86.ActiveCfg = Release|Any CPU
{F6A9F74B-5C63-4C53-9745-F00BE40AF8C8}.Release|x86.Build.0 = Release|Any CPU
{EEBAD5E8-1C76-0F75-7DD2-8A97BD31567B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEBAD5E8-1C76-0F75-7DD2-8A97BD31567B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEBAD5E8-1C76-0F75-7DD2-8A97BD31567B}.Debug|x64.ActiveCfg = Debug|Any CPU
{EEBAD5E8-1C76-0F75-7DD2-8A97BD31567B}.Debug|x64.Build.0 = Debug|Any CPU
{EEBAD5E8-1C76-0F75-7DD2-8A97BD31567B}.Debug|x86.ActiveCfg = Debug|Any CPU
{EEBAD5E8-1C76-0F75-7DD2-8A97BD31567B}.Debug|x86.Build.0 = Debug|Any CPU
{EEBAD5E8-1C76-0F75-7DD2-8A97BD31567B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEBAD5E8-1C76-0F75-7DD2-8A97BD31567B}.Release|Any CPU.Build.0 = Release|Any CPU
{EEBAD5E8-1C76-0F75-7DD2-8A97BD31567B}.Release|x64.ActiveCfg = Release|Any CPU
{EEBAD5E8-1C76-0F75-7DD2-8A97BD31567B}.Release|x64.Build.0 = Release|Any CPU
{EEBAD5E8-1C76-0F75-7DD2-8A97BD31567B}.Release|x86.ActiveCfg = Release|Any CPU
{EEBAD5E8-1C76-0F75-7DD2-8A97BD31567B}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
58 changes: 0 additions & 58 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
[![License](https://img.shields.io/github/license/devlooped/Extensions.AI.svg?color=blue)](https://github.com//devlooped/Extensions.AI/blob/main/license.txt)
[![Build](https://github.com/devlooped/Extensions.AI/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/devlooped/Extensions.AI/actions/workflows/build.yml)

# Extensions

<!-- include src/AI/readme.md#content -->
<!-- #content -->
Extensions for Microsoft.Extensions.AI

Expand Down Expand Up @@ -110,62 +107,7 @@ IChatClient client = new GrokClient(Env.Get("XAI_API_KEY")!)
})
.Build();
```

<!-- #content -->
<!-- src/AI/readme.md#content -->

# Weaving

<!-- include src/Weaving/readme.md#content -->
<!-- #content -->
Run AI-powered C# files with the power of Microsoft.Extensions.AI and Devlooped.Extensions.AI

```csharp
#:package Weaving@0.*

// Sample X.AI client usage with .NET
var messages = new Chat()
{
{ "system", "You are a highly intelligent AI assistant." },
{ "user", "What is 101*3?" },
};

IChatClient grok = new GrokClient(Throw.IfNullOrEmpty(Env.Get("XAI_API_KEY")))
.GetChatClient("grok-3-mini") // or "grok-3-mini-fast"
.AsIChatClient();

var options = new GrokChatOptions
{
ReasoningEffort = ReasoningEffort.High, // or ReasoningEffort.Low
Search = GrokSearch.Auto, // or GrokSearch.On or GrokSearch.Off
};

var response = await grok.GetResponseAsync(messages, options);

AnsiConsole.MarkupLine($":robot: {response.Text}");
```

> [!NOTE]
> The most useful namespaces and dependencies for developing Microsoft.Extensions.AI-powered
> applications are automatically referenced and imported when using this package.

## Configuration / Environment Variables

The `Env` class provides access to the following variables/configuration automatically:

* `.env` files: in local and parent directories
* `~/.env` file: in the user's home directory (`%userprofile%\.env` on Windows)
* All default configuration sources from [App Builder](https://learn.microsoft.com/en-us/dotnet/core/extensions/generic-host?tabs=appbuilder#host-builder-settings):
* Environment variables prefixed with DOTNET_.
* Command-line arguments.
* appsettings.json.
* appsettings.{Environment}.json.
* Secret Manager when the app runs in the Development environment.
* Environment variables.
* Command-line arguments.

<!-- #content -->
<!-- src/Weaving/readme.md#content -->

<!-- include https://github.com/devlooped/sponsors/raw/main/footer.md -->
# Sponsors
Expand Down
9 changes: 5 additions & 4 deletions src/AI.CodeAnalysis/AI.CodeAnalysis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
<PackFolder>analyzers/dotnet/roslyn4.0/cs</PackFolder>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="..\AI\ChatClientExtensions.cs" Link="ChatClientExtensions.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="NuGetizer" Version="1.2.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" Pack="false" />
<PackageReference Include="PolySharp" Version="1.15.0" PrivateAssets="All" />
<PackageReference Include="ThisAssembly.Resources" Version="2.0.14" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<Compile Remove="ChatClientExtensions.cs" />
<EmbeddedResource Include="ChatClientExtensions.cs" />
</ItemGroup>

</Project>
5 changes: 1 addition & 4 deletions src/AI.Tests/AI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\AI\ChatClientExtensions.cs" Link="ChatClientExtensions.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.6.0-preview.1.25310.2" />
Expand All @@ -29,6 +25,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AI.CodeAnalysis\AI.CodeAnalysis.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\AI\AI.csproj" />
</ItemGroup>

Expand Down
103 changes: 1 addition & 102 deletions src/AI/readme.md
Original file line number Diff line number Diff line change
@@ -1,105 +1,4 @@
<!-- #content -->
Extensions for Microsoft.Extensions.AI

## Grok

Full support for Grok [Live Search](https://docs.x.ai/docs/guides/live-search)
and [Reasoning](https://docs.x.ai/docs/guides/reasoning) model options.

```csharp
// Sample X.AI client usage with .NET
var messages = new Chat()
{
{ "system", "You are a highly intelligent AI assistant." },
{ "user", "What is 101*3?" },
};

IChatClient grok = new GrokClient(Env.Get("XAI_API_KEY")!)
.GetChatClient("grok-3-mini")
.AsIChatClient();

var options = new GrokChatOptions
{
ModelId = "grok-3-mini-fast", // can override the model on the client
Temperature = 0.7f,
ReasoningEffort = ReasoningEffort.High, // or ReasoningEffort.Low
Search = GrokSearch.Auto, // or GrokSearch.On or GrokSearch.Off
};

var response = await grok.GetResponseAsync(messages, options);
```

Search can alternatively be configured using a regular `ChatOptions`
and adding the `HostedWebSearchTool` to the tools collection, which
sets the live search mode to `auto` like above:

```csharp
var messages = new Chat()
{
{ "system", "You are an AI assistant that knows how to search the web." },
{ "user", "What's Tesla stock worth today? Search X and the news for latest info." },
};

var grok = new GrokClient(Env.Get("XAI_API_KEY")!)
.GetChatClient("grok-3")
.AsIChatClient();

var options = new ChatOptions
{
Tools = [new HostedWebSearchTool()]
};

var response = await grok.GetResponseAsync(messages, options);
```

## Console Logging

Additional `UseJsonConsoleLogging` extension for rich JSON-formatted console logging of AI requests
are provided at two levels:

* Chat pipeline: similar to `UseLogging`.
* HTTP pipeline: lowest possible layer before the request is sent to the AI service,
can capture all requests and responses. Can also be used with other Azure SDK-based
clients that leverage `ClientPipelineOptions`.

> [!NOTE]
> Rich JSON formatting is provided by [Spectre.Console](https://spectreconsole.net/)

The HTTP pipeline logging can be enabled by calling `UseJsonConsoleLogging` on the
client options passed to the client constructor:

```csharp
var openai = new OpenAIClient(
Env.Get("OPENAI_API_KEY")!,
new OpenAIClientOptions().UseJsonConsoleLogging());
```

For a Grok client with search-enabled, a request would look like the following:

![](https://raw.githubusercontent.com/devlooped/Extensions.AI/main/assets/img/chatmessage.png)

Both alternatives receive an optional `JsonConsoleOptions` instance to configure
the output, including truncating or wrapping long messages, setting panel style,
and more.

The chat pipeline logging is added similar to other pipeline extensions:

```csharp
IChatClient client = new GrokClient(Env.Get("XAI_API_KEY")!)
.GetChatClient("grok-3-mini")
.AsIChatClient()
.AsBuilder()
.UseOpenTelemetry()
// other extensions...
.UseJsonConsoleLogging(new JsonConsoleOptions()
{
// Formatting options...
Border = BoxBorder.None,
WrapLength = 80,
})
.Build();
```

<!-- #content -->
<!-- include ../../readme.md#content -->
<!-- include https://github.com/devlooped/sponsors/raw/main/footer.md -->
<!-- exclude -->
1 change: 0 additions & 1 deletion src/Samples/.env

This file was deleted.

21 changes: 0 additions & 21 deletions src/Samples/Program.cs

This file was deleted.

10 changes: 0 additions & 10 deletions src/Samples/Properties/launchSettings.json

This file was deleted.

18 changes: 0 additions & 18 deletions src/Samples/Samples.csproj

This file was deleted.

13 changes: 0 additions & 13 deletions src/Samples/appsettings.json

This file was deleted.

25 changes: 0 additions & 25 deletions src/Weaving/AppInitializer.cs

This file was deleted.

Loading
Loading