Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net: Anthropic - samples #8585

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions dotnet/samples/Demos/AIModelRouter/AIModelRouter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>5ee045b0-aea3-4f08-8d31-32d1a6f8fed0</UserSecretsId>
<NoWarn>SKEXP0070</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand All @@ -14,6 +15,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Connectors\Connectors.Anthropic\Connectors.Anthropic.csproj" />
<ProjectReference Include="..\..\..\src\Connectors\Connectors.OpenAI\Connectors.OpenAI.csproj" />
</ItemGroup>

Expand Down
3 changes: 2 additions & 1 deletion dotnet/samples/Demos/AIModelRouter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private static async Task Main(string[] args)
.AddOpenAIChatCompletion(serviceId: "lmstudio", modelId: "N/A", endpoint: new Uri("http://localhost:1234"), apiKey: null)
.AddOpenAIChatCompletion(serviceId: "ollama", modelId: "phi3", endpoint: new Uri("http://localhost:11434"), apiKey: null)
.AddOpenAIChatCompletion(serviceId: "openai", modelId: "gpt-4o", apiKey: config["OpenAI:ApiKey"]!)
.AddAnthropicChatCompletion(serviceId: "claude", modelId: "claude-3-5-sonnet-20240620", apiKey: config["Anthropic:ApiKey"]!)

// Adding a custom filter to capture router selected service id
.Services.AddSingleton<IPromptRenderFilter>(new SelectedServiceFilter());
Expand All @@ -43,7 +44,7 @@ private static async Task Main(string[] args)
// Find the best service to use based on the user's input
KernelArguments arguments = new(new PromptExecutionSettings()
{
ServiceId = router.FindService(userMessage, ["lmstudio", "ollama", "openai"])
ServiceId = router.FindService(userMessage, ["lmstudio", "ollama", "openai", "claude"])
Krzysztof318 marked this conversation as resolved.
Show resolved Hide resolved
});

// Invoke the prompt and print the response
Expand Down
3 changes: 3 additions & 0 deletions dotnet/samples/Demos/AIModelRouter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ The sample can be configured by using the command line with .NET [Secret Manager
```powershell
# OpenAI (Not required if using Azure OpenAI)
dotnet user-secrets set "OpenAI:ApiKey" "... your api key ... "

# Anthropic
dotnet user-secrets set "Anthropic:ApiKey" "... your api key ... "
RogerBarreto marked this conversation as resolved.
Show resolved Hide resolved
```

## Running the sample
Expand Down
Loading