Skip to content

Commit 795986d

Browse files
committed
Showcase OpenAI features in readme
1 parent f017650 commit 795986d

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

readme.md

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Icon](assets/img/icon-32.png) Devlooped.Extensions.AI
1+
![Icon](assets/img/icon-32.png) Devlooped.Extensions.AI
22
============
33

44
[![Version](https://img.shields.io/nuget/vpre/Devlooped.Extensions.AI.svg?color=royalblue)](https://www.nuget.org/packages/Devlooped.Extensions.AI)
@@ -22,16 +22,14 @@ var messages = new Chat()
2222
{ "user", "What is 101*3?" },
2323
};
2424

25-
IChatClient grok = new GrokClient(Env.Get("XAI_API_KEY")!)
26-
.GetChatClient("grok-3-mini")
27-
.AsIChatClient();
25+
var grok = new GrokChatClient(Env.Get("XAI_API_KEY")!, "grok-3-mini");
2826

2927
var options = new GrokChatOptions
3028
{
31-
ModelId = "grok-3-mini-fast", // can override the model on the client
29+
ModelId = "grok-3-mini-fast", // 👈 can override the model on the client
3230
Temperature = 0.7f,
33-
ReasoningEffort = ReasoningEffort.High, // or ReasoningEffort.Low
34-
Search = GrokSearch.Auto, // or GrokSearch.On or GrokSearch.Off
31+
ReasoningEffort = ReasoningEffort.High, // 👈 or Low
32+
Search = GrokSearch.Auto, // 👈 or On/Off
3533
};
3634

3735
var response = await grok.GetResponseAsync(messages, options);
@@ -48,18 +46,50 @@ var messages = new Chat()
4846
{ "user", "What's Tesla stock worth today? Search X and the news for latest info." },
4947
};
5048

51-
var grok = new GrokClient(Env.Get("XAI_API_KEY")!)
52-
.GetChatClient("grok-3")
53-
.AsIChatClient();
49+
var grok = new GrokChatClient(Env.Get("XAI_API_KEY")!, "grok-3");
5450

5551
var options = new ChatOptions
5652
{
57-
Tools = [new HostedWebSearchTool()]
53+
Tools = [new HostedWebSearchTool()] // 👈 equals setting GrokSearch.Auto
54+
};
55+
56+
var response = await grok.GetResponseAsync(messages, options);
57+
```
58+
59+
## OpenAI
60+
61+
The support for OpenAI chat clients provided in [Microsoft.Extensions.AI.OpenAI](https://www.nuget.org/packages/Microsoft.Extensions.AI.OpenAI) fall short in some scenarios:
62+
63+
* Specifying per-chat model identifier: the OpenAI client options only allow setting
64+
a single model identifier for all requests, at the time the `OpenAIClient.GetChatClient` is
65+
invoked.
66+
* Setting reasoning effort: the Microsoft.Extensions.AI API does not expose a way to set reasoning
67+
effort for reasoning-capable models, which is very useful for some models like `o4-mini`.
68+
69+
So solve both issues, this package provides an `OpenAIChatClient` that wraps the underlying
70+
`OpenAIClient` and allows setting the model identifier and reasoning effort per request, just
71+
like the above Grok examples showed:
72+
73+
```csharp
74+
var messages = new Chat()
75+
{
76+
{ "system", "You are a highly intelligent AI assistant." },
77+
{ "user", "What is 101*3?" },
78+
};
79+
80+
IChatClient chat = new OpenAIChatClient(Env.Get("OPENAI_API_KEY")!, "o3-mini");
81+
82+
var options = new GrokChatOptions
83+
{
84+
ModelId = "o4-mini", // 👈 can override the model on the client
85+
ReasoningEffort = ReasoningEffort.High, // 👈 or Medium/Low
5886
};
5987

6088
var response = await grok.GetResponseAsync(messages, options);
89+
6190
```
6291

92+
6393
## Console Logging
6494

6595
Additional `UseJsonConsoleLogging` extension for rich JSON-formatted console logging of AI requests

0 commit comments

Comments
 (0)