Skip to content

Commit aad9020

Browse files
chore: fix snippet formatting
1 parent 8246eb6 commit aad9020

File tree

2 files changed

+113
-113
lines changed

2 files changed

+113
-113
lines changed

interactivity/custom-iclient.md

Lines changed: 93 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -19,137 +19,137 @@ To enable a custom AI client implementation, follow these steps:
1919
1. Create a class that implements the `Telerik.Reporting.AI.IClient` interface. The following example demonstrates an Azure OpenAI integration for illustration purposes, though you can use any LLM provider:
2020

2121
````C#
22-
using Azure.AI.OpenAI;
23-
using Microsoft.Extensions.AI;
24-
using System.ClientModel;
25-
using Telerik.Reporting.AI;
22+
using Azure.AI.OpenAI;
23+
using Microsoft.Extensions.AI;
24+
using System.ClientModel;
25+
using Telerik.Reporting.AI;
2626

27-
namespace WebApplication1.AI;
27+
namespace WebApplication1.AI;
2828

29-
public class CustomAIClient : IClient
30-
{
31-
public string Model { get; } = "gpt-4o-mini";
29+
public class CustomAIClient : IClient
30+
{
31+
public string Model { get; } = "gpt-4o-mini";
3232

33-
public bool SupportsSystemPrompts => false;
33+
public bool SupportsSystemPrompts => false;
3434

35-
private readonly IChatClient chatClient;
35+
private readonly IChatClient chatClient;
3636

37-
public CustomAIClient()
38-
{
39-
string endpoint = "https://ai-explorations.openai.azure.com/";
40-
string credential = "YOUR_API_KEY";
41-
string model = "gpt-4o-mini";
37+
public CustomAIClient()
38+
{
39+
string endpoint = "https://ai-explorations.openai.azure.com/";
40+
string credential = "YOUR_API_KEY";
41+
string model = "gpt-4o-mini";
4242

43-
chatClient = new AzureOpenAIClient(new Uri(endpoint), new ApiKeyCredential(credential))
44-
.GetChatClient(model)
45-
.AsIChatClient();
46-
}
43+
chatClient = new AzureOpenAIClient(new Uri(endpoint), new ApiKeyCredential(credential))
44+
.GetChatClient(model)
45+
.AsIChatClient();
46+
}
4747

48-
public async Task<IReadOnlyCollection<IMessage>> GetResponseAsync(IReadOnlyCollection<IMessage> query, CancellationToken cancellationToken)
48+
public async Task<IReadOnlyCollection<IMessage>> GetResponseAsync(IReadOnlyCollection<IMessage> query, CancellationToken cancellationToken)
49+
{
50+
// Convert Telerik.Reporting.AI IMessage to Microsoft.Extensions.AI ChatMessage
51+
var chatMessages = new List<ChatMessage>();
52+
foreach (var message in query)
4953
{
50-
// Convert Telerik.Reporting.AI IMessage to Microsoft.Extensions.AI ChatMessage
51-
var chatMessages = new List<ChatMessage>();
52-
foreach (var message in query)
53-
{
54-
ChatRole chatRole = message.Role switch
55-
{
56-
MessageRole.System => ChatRole.System,
57-
MessageRole.Assistant => ChatRole.Assistant,
58-
MessageRole.User => ChatRole.User,
59-
_ => throw new ArgumentException($"Invalid MessageRole: {message.Role}")
60-
};
61-
62-
// Convert text contents from Telerik.Reporting.AI TO Microsoft.Extensions.AI
63-
var textContents = message.Contents
64-
.OfType<Telerik.Reporting.AI.TextContent>()
65-
.Select(textContent => new Microsoft.Extensions.AI.TextContent(textContent.Text))
66-
.Cast<AIContent>()
67-
.ToList();
68-
69-
chatMessages.Add(new ChatMessage(chatRole, textContents));
70-
}
71-
72-
// Call Azure OpenAI
73-
var response = await chatClient.GetResponseAsync(chatMessages, new ChatOptions(), cancellationToken);
74-
75-
// Convert response back to Telerik.Reporting.AI IMessage
76-
var resultMessages = new List<IMessage>();
77-
foreach (var responseMessage in response.Messages)
54+
ChatRole chatRole = message.Role switch
7855
{
79-
MessageRole messageRole = responseMessage.Role.Value switch
80-
{
81-
"system" => MessageRole.System,
82-
"assistant" => MessageRole.Assistant,
83-
"user" => MessageRole.User,
84-
_ => throw new ArgumentException($"Invalid ChatRole: {responseMessage.Role}")
85-
};
86-
87-
// Convert back to Telerik.Reporting.AI content
88-
var contents = responseMessage.Contents
89-
.OfType<Microsoft.Extensions.AI.TextContent>()
90-
.Select(tc => new Telerik.Reporting.AI.TextContent(tc.Text))
91-
.Cast<IContent>()
92-
.ToList();
93-
94-
resultMessages.Add(new Message(messageRole, contents));
95-
}
96-
97-
return resultMessages;
56+
MessageRole.System => ChatRole.System,
57+
MessageRole.Assistant => ChatRole.Assistant,
58+
MessageRole.User => ChatRole.User,
59+
_ => throw new ArgumentException($"Invalid MessageRole: {message.Role}")
60+
};
61+
62+
// Convert text contents from Telerik.Reporting.AI TO Microsoft.Extensions.AI
63+
var textContents = message.Contents
64+
.OfType<Telerik.Reporting.AI.TextContent>()
65+
.Select(textContent => new Microsoft.Extensions.AI.TextContent(textContent.Text))
66+
.Cast<AIContent>()
67+
.ToList();
68+
69+
chatMessages.Add(new ChatMessage(chatRole, textContents));
9870
}
9971

100-
public static IClient GetCustomAIClient()
72+
// Call Azure OpenAI
73+
var response = await chatClient.GetResponseAsync(chatMessages, new ChatOptions(), cancellationToken);
74+
75+
// Convert response back to Telerik.Reporting.AI IMessage
76+
var resultMessages = new List<IMessage>();
77+
foreach (var responseMessage in response.Messages)
10178
{
102-
return new CustomAIClient();
79+
MessageRole messageRole = responseMessage.Role.Value switch
80+
{
81+
"system" => MessageRole.System,
82+
"assistant" => MessageRole.Assistant,
83+
"user" => MessageRole.User,
84+
_ => throw new ArgumentException($"Invalid ChatRole: {responseMessage.Role}")
85+
};
86+
87+
// Convert back to Telerik.Reporting.AI content
88+
var contents = responseMessage.Contents
89+
.OfType<Microsoft.Extensions.AI.TextContent>()
90+
.Select(tc => new Telerik.Reporting.AI.TextContent(tc.Text))
91+
.Cast<IContent>()
92+
.ToList();
93+
94+
resultMessages.Add(new Message(messageRole, contents));
10395
}
96+
97+
return resultMessages;
98+
}
99+
100+
public static IClient GetCustomAIClient()
101+
{
102+
return new CustomAIClient();
104103
}
105-
````
104+
}
105+
````
106106

107107
1. Register the custom client in your `ReportServiceConfiguration`:
108108

109109
* .NET
110110

111111
````C#
112-
builder.Services.TryAddSingleton<IReportServiceConfiguration>(sp => new ReportServiceConfiguration
113-
{
114-
HostAppId = "MyApp",
115-
AIClientFactory = WebApplication1.AI.CustomAIClient.GetCustomAIClient,
116-
// ...
117-
});
118-
````
112+
builder.Services.TryAddSingleton<IReportServiceConfiguration>(sp => new ReportServiceConfiguration
113+
{
114+
HostAppId = "MyApp",
115+
AIClientFactory = WebApplication1.AI.CustomAIClient.GetCustomAIClient,
116+
// ...
117+
});
118+
````
119119

120-
* .NET Framework
120+
* .NET Framework
121121

122-
````C#
123-
public class CustomResolverReportsController : ReportsControllerBase
124-
{
125-
static ReportServiceConfiguration configurationInstance;
122+
````C#
123+
public class CustomResolverReportsController : ReportsControllerBase
124+
{
125+
static ReportServiceConfiguration configurationInstance;
126126

127-
static CustomResolverReportsController()
127+
static CustomResolverReportsController()
128+
{
129+
configurationInstance = new ReportServiceConfiguration
128130
{
129-
configurationInstance = new ReportServiceConfiguration
130-
{
131-
HostAppId = "MyApp",
132-
AIClientFactory = WebApplication1.AI.CustomAIClient.GetCustomAIClient,
133-
// ...
134-
};
135-
}
131+
HostAppId = "MyApp",
132+
AIClientFactory = WebApplication1.AI.CustomAIClient.GetCustomAIClient,
133+
// ...
134+
};
136135
}
137-
````
136+
}
137+
````
138138

139139
You can further customize the AI client to enable additional features like RAG optimization, predefined prompts, and user consent settings. For more details, refer to [Configuring the AI-Powered Insights]({%slug telerikreporting/designing-reports/adding-interactivity-to-reports/configuring-ai-powered-insights%}).
140140

141141
## Understanding the IClient Interface
142142

143143
The `Telerik.Reporting.AI.IClient` interface defines the contract for AI service integration:
144144

145-
```csharp
145+
````C#
146146
public interface IClient
147147
{
148148
string Model { get; }
149149
bool SupportsSystemPrompts { get; }
150150
Task<IReadOnlyCollection<IMessage>> GetResponseAsync(IReadOnlyCollection<IMessage> query, CancellationToken cancellationToken);
151151
}
152-
```
152+
````
153153

154154
### Key Properties and Methods
155155

interactivity/using-ai-powered-insights-rest-service.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,28 @@ To enable the AI-powered insights, follow these steps:
4141

4242
1. Add the [AIClient element]({%slug telerikreporting/aiclient-element%}) to the report engine configuration in your application's configuration file. This element allows you to specify the AI model, endpoint, and authentication credentials. The following example demonstrates a basic Azure OpenAI configuration:
4343

44-
````JSON
45-
{
46-
"telerikReporting": {
47-
"AIClient": {
48-
"friendlyName": "MicrosoftExtensionsAzureOpenAI",
49-
"model": "gpt-4o-mini",
50-
"endpoint": "https://ai-explorations.openai.azure.com/",
51-
"credential": "YOUR_API_KEY"
52-
}
44+
````JSON
45+
{
46+
"telerikReporting": {
47+
"AIClient": {
48+
"friendlyName": "MicrosoftExtensionsAzureOpenAI",
49+
"model": "gpt-4o-mini",
50+
"endpoint": "https://ai-explorations.openai.azure.com/",
51+
"credential": "YOUR_API_KEY"
5352
}
5453
}
55-
````
56-
````XML
57-
<Telerik.Reporting>
58-
<AIClient
59-
friendlyName="MicrosoftExtensionsAzureOpenAI"
60-
model="gpt-4o-mini"
61-
endpoint="https://ai-explorations.openai.azure.com/"
62-
credential="YOUR_API_KEY">
63-
</AIClient>
64-
</Telerik.Reporting>
65-
````
54+
}
55+
````
56+
````XML
57+
<Telerik.Reporting>
58+
<AIClient
59+
friendlyName="MicrosoftExtensionsAzureOpenAI"
60+
model="gpt-4o-mini"
61+
endpoint="https://ai-explorations.openai.azure.com/"
62+
credential="YOUR_API_KEY">
63+
</AIClient>
64+
</Telerik.Reporting>
65+
````
6666

6767
>tip If you haven't configured the report engine previously, make sure to check the article [Report Engine Configuration Overview]({%slug telerikreporting/using-reports-in-applications/export-and-configure/configure-the-report-engine/overview%}) to get familiar with this topic.
6868

0 commit comments

Comments
 (0)