diff --git a/ej2-asp-core-mvc/Release-notes/31.2.9.md b/ej2-asp-core-mvc/Release-notes/31.2.9.md new file mode 100644 index 0000000000..67f1971431 --- /dev/null +++ b/ej2-asp-core-mvc/Release-notes/31.2.9.md @@ -0,0 +1,16 @@ +--- +title: Essential Studio for ##Platform_Name## Release Notes +description: Learn here about the controls in the Essential Studio for ##Platform_Name## 2025 Volume 3 SP2 Release - Release Notes +platform: ej2-asp-core-mvc +documentation: ug +--- + +# Essential Studio for ##Platform_Name## - v31.2.9 Release Notes + +{% include release-info.html date="November 12, 2025" version="v31.2.9" %} + +{% directory path: _includes/release-notes/v31.2.9 %} + +{% include {{file.url}} %} + +{% enddirectory %} \ No newline at end of file diff --git a/ej2-asp-core-mvc/Test-Results/asp-core/29.1.35.md b/ej2-asp-core-mvc/Test-Results/asp-core/29.1.35.md deleted file mode 100644 index dcac81babd..0000000000 --- a/ej2-asp-core-mvc/Test-Results/asp-core/29.1.35.md +++ /dev/null @@ -1,91 +0,0 @@ ---- -title: Essential Studio for ##Platform_Name## Weekly Release Test Automation Results -description: Essential Studio for ##Platform_Name## Weekly Release Test Automation Results -platform: ej2-asp-core-mvc -documentation: ug ---- - -# Essential Studio®##Platform_Name## Test Automation Results - -| Component Name | Test Cases | Passed | Failed | Remarks | -|---------------|------------|--------|--------|---------| -| Accordion | 109 | 109 | 0 | Fully Passed | -| AI Assist View | 430 | 430 | 0 | Fully Passed | -| App Bar | 50 | 50 | 0 | Fully Passed | -| Autocomplete | 482 | 482 | 0 | Fully Passed | -| Avatar | 1 | 1 | 0 | Fully Passed | -| Breadcrumb | 450 | 450 | 0 | Fully Passed | -| Bullet Chart | 164 | 164 | 0 | Fully Passed | -| Button | 721 | 721 | 0 | Fully Passed | -| Button Group | 420 | 420 | 0 | Fully Passed | -| Calendar | 177 | 177 | 0 | Fully Passed | -| Carousel | 60 | 60 | 0 | Fully Passed | -| Chart | 4442 | 4442 | 0 | Fully Passed | -| Checkbox | 120 | 120 | 0 | Fully Passed | -| Chips | 45 | 45 | 0 | Fully Passed | -| Circular Gauge | 281 | 281 | 0 | Fully Passed | -| Color Picker | 225 | 225 | 0 | Fully Passed | -| Combo Box | 365 | 365 | 0 | Fully Passed | -| Common | 1739 | 1739 | 0 | Fully Passed | -| Context Menu | 150 | 150 | 0 | Fully Passed | -| Dashboard Layout | 59 | 59 | 0 | Fully Passed | -| Data Grid | 5634 | 5634 | 0 | Fully Passed | -| Date Picker | 378 | 378 | 0 | Fully Passed | -| Date Range Picker | 417 | 417 | 0 | Fully Passed | -| Date Time Picker | 321 | 321 | 0 | Fully Passed | -| Dialog | 1 | 1 | 0 | Fully Passed | -| Dropdown Button | 240 | 240 | 0 | Fully Passed | -| Dropdown List | 437 | 437 | 0 | Fully Passed | -| Dropdown Tree | 159 | 159 | 0 | Fully Passed | -| File Manager | 2174 | 2174 | 0 | Fully Passed | -| Floating Action Button | 64 | 64 | 0 | Fully Passed | -| Gantt Chart | 2758 | 2758 | 0 | Fully Passed | -| Heat Map | 478 | 478 | 0 | Fully Passed | -| Image Editor | 1583 | 1583 | 0 | Fully Passed | -| Inplace Editor | 620 | 620 | 0 | Fully Passed | -| Kanban | 65 | 65 | 0 | Fully Passed | -| Linear Gauge | 308 | 308 | 0 | Fully Passed | -| List Box | 350 | 350 | 0 | Fully Passed | -| List View | 113 | 113 | 0 | Fully Passed | -| Map | 1126 | 1126 | 0 | Fully Passed | -| Mention | 125 | 125 | 0 | Fully Passed | -| Menu | 335 | 335 | 0 | Fully Passed | -| Message | 7 | 7 | 0 | Fully Passed | -| Multicolumn Combo Box | 254 | 254 | 0 | Fully Passed | -| Multiselect Dropdown | 784 | 784 | 0 | Fully Passed | -| OTP Input | 156 | 156 | 0 | Fully Passed | -| Pivot Table | 3448 | 3448 | 0 | Fully Passed | -| Progress Bar | 78 | 78 | 0 | Fully Passed | -| Progress Button | 660 | 660 | 0 | Fully Passed | -| Query Builder | 1080 | 1080 | 0 | Fully Passed | -| Radio Button | 181 | 181 | 0 | Fully Passed | -| Range Navigator | 138 | 138 | 0 | Fully Passed | -| Rating | 121 | 121 | 0 | Fully Passed | -| Ribbon | 1848 | 1848 | 0 | Fully Passed | -| Rich Text Editor | 3875 | 3875 | 0 | Fully Passed | -| Schedule | 4576 | 4576 | 0 | Fully Passed | -| Sidebar | 194 | 194 | 0 | Fully Passed | -| Signature | 200 | 200 | 0 | Fully Passed | -| Skeleton | 44 | 44 | 0 | Fully Passed | -| Slider | 195 | 195 | 0 | Fully Passed | -| Smith Chart | 49 | 49 | 0 | Fully Passed | -| Sparkline Chart | 57 | 57 | 0 | Fully Passed | -| Speed Dial | 366 | 366 | 0 | Fully Passed | -| Split Button | 240 | 240 | 0 | Fully Passed | -| Splitter | 13 | 13 | 0 | Fully Passed | -| Spreadsheet | 8515 | 8515 | 0 | Fully Passed | -| Stepper | 250 | 250 | 0 | Fully Passed | -| Stock Chart | 677 | 677 | 0 | Fully Passed | -| Switch | 122 | 122 | 0 | Fully Passed | -| Tab | 81 | 81 | 0 | Fully Passed | -| Text Area | 198 | 198 | 0 | Fully Passed | -| Text Box | 36 | 36 | 0 | Fully Passed | -| Time Picker | 176 | 176 | 0 | Fully Passed | -| Timeline | 213 | 213 | 0 | Fully Passed | -| Toast | 47 | 47 | 0 | Fully Passed | -| Toolbar | 131 | 131 | 0 | Fully Passed | -| Tooltip | 148 | 148 | 0 | Fully Passed | -| Tree Grid | 6243 | 6243 | 0 | Fully Passed | -| Tree Map | 210 | 210 | 0 | Fully Passed | -| Tree View | 709 | 709 | 0 | Fully Passed | - diff --git a/ej2-asp-core-mvc/Test-Results/asp-mvc/29.1.35.md b/ej2-asp-core-mvc/Test-Results/asp-mvc/29.1.35.md deleted file mode 100644 index dcac81babd..0000000000 --- a/ej2-asp-core-mvc/Test-Results/asp-mvc/29.1.35.md +++ /dev/null @@ -1,91 +0,0 @@ ---- -title: Essential Studio for ##Platform_Name## Weekly Release Test Automation Results -description: Essential Studio for ##Platform_Name## Weekly Release Test Automation Results -platform: ej2-asp-core-mvc -documentation: ug ---- - -# Essential Studio®##Platform_Name## Test Automation Results - -| Component Name | Test Cases | Passed | Failed | Remarks | -|---------------|------------|--------|--------|---------| -| Accordion | 109 | 109 | 0 | Fully Passed | -| AI Assist View | 430 | 430 | 0 | Fully Passed | -| App Bar | 50 | 50 | 0 | Fully Passed | -| Autocomplete | 482 | 482 | 0 | Fully Passed | -| Avatar | 1 | 1 | 0 | Fully Passed | -| Breadcrumb | 450 | 450 | 0 | Fully Passed | -| Bullet Chart | 164 | 164 | 0 | Fully Passed | -| Button | 721 | 721 | 0 | Fully Passed | -| Button Group | 420 | 420 | 0 | Fully Passed | -| Calendar | 177 | 177 | 0 | Fully Passed | -| Carousel | 60 | 60 | 0 | Fully Passed | -| Chart | 4442 | 4442 | 0 | Fully Passed | -| Checkbox | 120 | 120 | 0 | Fully Passed | -| Chips | 45 | 45 | 0 | Fully Passed | -| Circular Gauge | 281 | 281 | 0 | Fully Passed | -| Color Picker | 225 | 225 | 0 | Fully Passed | -| Combo Box | 365 | 365 | 0 | Fully Passed | -| Common | 1739 | 1739 | 0 | Fully Passed | -| Context Menu | 150 | 150 | 0 | Fully Passed | -| Dashboard Layout | 59 | 59 | 0 | Fully Passed | -| Data Grid | 5634 | 5634 | 0 | Fully Passed | -| Date Picker | 378 | 378 | 0 | Fully Passed | -| Date Range Picker | 417 | 417 | 0 | Fully Passed | -| Date Time Picker | 321 | 321 | 0 | Fully Passed | -| Dialog | 1 | 1 | 0 | Fully Passed | -| Dropdown Button | 240 | 240 | 0 | Fully Passed | -| Dropdown List | 437 | 437 | 0 | Fully Passed | -| Dropdown Tree | 159 | 159 | 0 | Fully Passed | -| File Manager | 2174 | 2174 | 0 | Fully Passed | -| Floating Action Button | 64 | 64 | 0 | Fully Passed | -| Gantt Chart | 2758 | 2758 | 0 | Fully Passed | -| Heat Map | 478 | 478 | 0 | Fully Passed | -| Image Editor | 1583 | 1583 | 0 | Fully Passed | -| Inplace Editor | 620 | 620 | 0 | Fully Passed | -| Kanban | 65 | 65 | 0 | Fully Passed | -| Linear Gauge | 308 | 308 | 0 | Fully Passed | -| List Box | 350 | 350 | 0 | Fully Passed | -| List View | 113 | 113 | 0 | Fully Passed | -| Map | 1126 | 1126 | 0 | Fully Passed | -| Mention | 125 | 125 | 0 | Fully Passed | -| Menu | 335 | 335 | 0 | Fully Passed | -| Message | 7 | 7 | 0 | Fully Passed | -| Multicolumn Combo Box | 254 | 254 | 0 | Fully Passed | -| Multiselect Dropdown | 784 | 784 | 0 | Fully Passed | -| OTP Input | 156 | 156 | 0 | Fully Passed | -| Pivot Table | 3448 | 3448 | 0 | Fully Passed | -| Progress Bar | 78 | 78 | 0 | Fully Passed | -| Progress Button | 660 | 660 | 0 | Fully Passed | -| Query Builder | 1080 | 1080 | 0 | Fully Passed | -| Radio Button | 181 | 181 | 0 | Fully Passed | -| Range Navigator | 138 | 138 | 0 | Fully Passed | -| Rating | 121 | 121 | 0 | Fully Passed | -| Ribbon | 1848 | 1848 | 0 | Fully Passed | -| Rich Text Editor | 3875 | 3875 | 0 | Fully Passed | -| Schedule | 4576 | 4576 | 0 | Fully Passed | -| Sidebar | 194 | 194 | 0 | Fully Passed | -| Signature | 200 | 200 | 0 | Fully Passed | -| Skeleton | 44 | 44 | 0 | Fully Passed | -| Slider | 195 | 195 | 0 | Fully Passed | -| Smith Chart | 49 | 49 | 0 | Fully Passed | -| Sparkline Chart | 57 | 57 | 0 | Fully Passed | -| Speed Dial | 366 | 366 | 0 | Fully Passed | -| Split Button | 240 | 240 | 0 | Fully Passed | -| Splitter | 13 | 13 | 0 | Fully Passed | -| Spreadsheet | 8515 | 8515 | 0 | Fully Passed | -| Stepper | 250 | 250 | 0 | Fully Passed | -| Stock Chart | 677 | 677 | 0 | Fully Passed | -| Switch | 122 | 122 | 0 | Fully Passed | -| Tab | 81 | 81 | 0 | Fully Passed | -| Text Area | 198 | 198 | 0 | Fully Passed | -| Text Box | 36 | 36 | 0 | Fully Passed | -| Time Picker | 176 | 176 | 0 | Fully Passed | -| Timeline | 213 | 213 | 0 | Fully Passed | -| Toast | 47 | 47 | 0 | Fully Passed | -| Toolbar | 131 | 131 | 0 | Fully Passed | -| Tooltip | 148 | 148 | 0 | Fully Passed | -| Tree Grid | 6243 | 6243 | 0 | Fully Passed | -| Tree Map | 210 | 210 | 0 | Fully Passed | -| Tree View | 709 | 709 | 0 | Fully Passed | - diff --git a/ej2-asp-core-mvc/ai-assistview/EJ2_ASP.MVC/speech/speech-to-text.md b/ej2-asp-core-mvc/ai-assistview/EJ2_ASP.MVC/speech/speech-to-text.md index 9f40bd899c..cb80d2ec7c 100644 --- a/ej2-asp-core-mvc/ai-assistview/EJ2_ASP.MVC/speech/speech-to-text.md +++ b/ej2-asp-core-mvc/ai-assistview/EJ2_ASP.MVC/speech/speech-to-text.md @@ -24,7 +24,18 @@ Before integrating `Speech-to-Text`, ensure the following: ## Configure Speech-to-Text -To enable Speech-to-Text functionality, modify the `Index.cshtml` file to incorporate the Web Speech API. The [SpeechToText](https://ej2.syncfusion.com/aspnetmvc/documentation/speech-to-text/getting-started) control listens for microphone input, transcribes spoken words, and updates the AI AssistView's editable footer with the transcribed text. The transcribed text is then sent as a prompt to the Azure OpenAI service via the AI AssistView control. +To enable Speech-to-Text functionality in the ASP.NET MVC AssistView control, update the `index.cshtml` file to incorporate the Web Speech API. + +The [SpeechToText](https://ej2.syncfusion.com/aspnetmvc/documentation/speech-to-text/getting-started) control listens to audio input from the device’s microphone, transcribes spoken words into text, and updates the AssistView’s editable footer using the [FooterTemplate](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.InteractiveChat.AIAssistView.html#Syncfusion_EJ2_InteractiveChat_AIAssistView_FooterTemplate) property to display the transcribed text. The transcribed text is then sent as a prompt to the Azure OpenAI service via the AI AssistView control. + +### Configuration Options + +* **[`Lang`](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.Inputs.SpeechToText.html#Syncfusion_EJ2_Inputs_SpeechToText_Lang)**: Specifies the language for speech recognition. For example: + + * `en-US` for American English + * `fr-FR` for French + +* **[`AllowInterimResults`](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.Inputs.SpeechToText.html#Syncfusion_EJ2_Inputs_SpeechToText_AllowInterimResults)**: Set to `true` to receive real-time (interim) recognition results, or `false` to receive only final results. {% tabs %} {% highlight razor tabtitle="CSHTML" %} @@ -37,6 +48,14 @@ To enable Speech-to-Text functionality, modify the `Index.cshtml` file to incorp ![Integrating Speech-to-Text with AI AssistView](images/aiassist-stt.png) +## Error Handling + +The `SpeechToText` control provides events to handle errors that may occur during speech recognition. For more information, refer to the [Error Handling](https://ej2.syncfusion.com/aspnetmvc/documentation/speech-to-text/speech-recognition#error-handling ) section in the documentation. + +## Browser Compatibility + +The `SpeechToText` control relies on the [Speech Recognition API](https://ej2.syncfusion.com/aspnetmvc/documentation/speech-to-text/speech-recognition#browser-support), which has limited browser support. Refer to the [Browser Compatibility](https://ej2.syncfusion.com/aspnetmvc/documentation/speech-to-text/speech-recognition#browser-support) section for detailed information. + ## See Also * [Text-to-Speech](./text-to-speech) diff --git a/ej2-asp-core-mvc/ai-assistview/EJ2_ASP.NETCORE/speech/speech-to-text.md b/ej2-asp-core-mvc/ai-assistview/EJ2_ASP.NETCORE/speech/speech-to-text.md index 5401f41fc3..347a5c99b0 100644 --- a/ej2-asp-core-mvc/ai-assistview/EJ2_ASP.NETCORE/speech/speech-to-text.md +++ b/ej2-asp-core-mvc/ai-assistview/EJ2_ASP.NETCORE/speech/speech-to-text.md @@ -24,7 +24,18 @@ Before integrating `Speech-to-Text`, ensure the following: ## Configure Speech-to-Text -To enable Speech-to-Text functionality, modify the `Index.cshtml` file to incorporate the Web Speech API. The [SpeechToText](https://ej2.syncfusion.com/aspnetcore/documentation/speech-to-text/getting-started) control listens for microphone input, transcribes spoken words, and updates the AI AssistView's editable footer with the transcribed text. The transcribed text is then sent as a prompt to the Azure OpenAI service via the AI AssistView control. +To enable Speech-to-Text functionality in the ASP.NET Core AssistView control, update the `index.cshtml` file to incorporate the Web Speech API. + +The [SpeechToText](https://ej2.syncfusion.com/aspnetcore/documentation/speech-to-text/getting-started) control listens to audio input from the device’s microphone, transcribes spoken words into text, and updates the AssistView’s editable footer using the [footerTemplate](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.InteractiveChat.AIAssistView.html#Syncfusion_EJ2_InteractiveChat_AIAssistView_FooterTemplate) property to display the transcribed text. The transcribed text is then sent as a prompt to the Azure OpenAI service via the AI AssistView control. + +### Configuration Options + +* **[`lang`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Inputs.SpeechToText.html#Syncfusion_EJ2_Inputs_SpeechToText_Lang)**: Specifies the language for speech recognition. For example: + + * `en-US` for American English + * `fr-FR` for French + +* **[`allowInterimResults`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Inputs.SpeechToText.html#Syncfusion_EJ2_Inputs_SpeechToText_AllowInterimResults)**: Set to `true` to receive real-time (interim) recognition results, or `false` to receive only final results. {% tabs %} {% highlight razor tabtitle="CSHTML" %} @@ -37,6 +48,14 @@ To enable Speech-to-Text functionality, modify the `Index.cshtml` file to incorp ![Integrating Speech-to-Text with AI AssistView](images/aiassist-stt.png) +## Error Handling + +The `SpeechToText` control provides events to handle errors that may occur during speech recognition. For more information, refer to the [Error Handling](https://ej2.syncfusion.com/aspnetcore/documentation/speech-to-text/speech-recognition#error-handling) section in the documentation. + +## Browser Compatibility + +The `SpeechToText` control relies on the [Speech Recognition API](https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition), which has limited browser support. Refer to the [Browser Compatibility](https://ej2.syncfusion.com/aspnetcore/documentation/speech-to-text/speech-recognition#browser-support) section for detailed information. + ## See Also * [Text-to-Speech](./text-to-speech) diff --git a/ej2-asp-core-mvc/chat-ui/EJ2_ASP.MVC/speech-to-text.md b/ej2-asp-core-mvc/chat-ui/EJ2_ASP.MVC/speech-to-text.md new file mode 100644 index 0000000000..20f931a708 --- /dev/null +++ b/ej2-asp-core-mvc/chat-ui/EJ2_ASP.MVC/speech-to-text.md @@ -0,0 +1,51 @@ +--- +layout: post +title: Speech-to-Text With ##Platform_Name## Chat UI Control | Syncfusion +description: Checkout and learn about configuration of Speech-to-Text with Azure OpenAI in ##Platform_Name## Chat UI control of Syncfusion Essential JS 2 and more. +platform: ej2-asp-core-mvc +control: Azure Open AI +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Speech-to-Text in ASP.NET MVC Chat UI + +The Syncfusion ASP.NET MVC Chat UI control integrates `Speech-to-Text` functionality through the browser's [Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API). This enables the conversion of spoken words into text using the device's microphone, allowing users to interact with the Chat UI through voice input. + +## Configure Speech-to-Text + +To enable Speech-to-Text functionality in the ASP.NET MVC Chat UI control, update the `index.cshtml` file to incorporate the Web Speech API. + +The [SpeechToText](https://ej2.syncfusion.com/aspnetmvc/documentation/speech-to-text/getting-started) control listens to audio input from the device’s microphone, transcribes spoken words into text, and updates the Chat UI’s editable footer using the [FooterTemplate](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.InteractiveChat.ChatUI.html#Syncfusion_EJ2_InteractiveChat_ChatUI_FooterTemplate) property to display the transcribed text. Once the transcription appears in the footer, users can send it as a message to others. + +### Configuration Options + +* **[`Lang`](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.Inputs.SpeechToText.html#Syncfusion_EJ2_Inputs_SpeechToText_Lang)**: Specifies the language for speech recognition. For example: + + * `en-US` for American English + * `fr-FR` for French + +* **[`AllowInterimResults`](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.Inputs.SpeechToText.html#Syncfusion_EJ2_Inputs_SpeechToText_AllowInterimResults)**: Set to `true` to receive real-time (interim) recognition results, or `false` to receive only final results. + +{% tabs %} +{% highlight razor tabtitle="CSHTML" %} +{% include code-snippet/chat-ui/stt/razor %} +{% endhighlight %} +{% highlight c# tabtitle="SpeechToText.cs" %} +{% include code-snippet/chat-ui/stt/speechtotext.cs %} +{% endhighlight %} +{% endtabs %} + +![Integrating Speech-to-Text with Chat UI](images/chatui-stt.png) + +## Error Handling + +The `SpeechToText` control provides events to handle errors that may occur during speech recognition. For more information, refer to the [Error Handling](https://ej2.syncfusion.com/aspnetmvc/documentation/speech-to-text/speech-recognition#error-handling ) section in the documentation. + +## Browser Compatibility + +The `SpeechToText` control relies on the [Speech Recognition API](https://ej2.syncfusion.com/aspnetmvc/documentation/speech-to-text/speech-recognition#browser-support), which has limited browser support. Refer to the [Browser Compatibility](https://ej2.syncfusion.com/aspnetmvc/documentation/speech-to-text/speech-recognition#browser-support) section for detailed information. + +## See Also + +* [Messages](./messages) diff --git a/ej2-asp-core-mvc/chat-ui/EJ2_ASP.NETCORE/speech-to-text.md b/ej2-asp-core-mvc/chat-ui/EJ2_ASP.NETCORE/speech-to-text.md new file mode 100644 index 0000000000..95612f2411 --- /dev/null +++ b/ej2-asp-core-mvc/chat-ui/EJ2_ASP.NETCORE/speech-to-text.md @@ -0,0 +1,51 @@ +--- +layout: post +title: Speech-to-Text With ##Platform_Name## Chat UI Control | Syncfusion +description: Checkout and learn about configuration of Speech-to-Text with Azure OpenAI in ##Platform_Name## Chat UI control of Syncfusion Essential JS 2 and more. +platform: ej2-asp-core-mvc +control: Azure Open AI +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Speech-to-Text in ASP.NET Core Chat UI + +The Syncfusion ASP.NET Core Chat UI control integrates `Speech-to-Text` functionality through the browser's [Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API). This enables the conversion of spoken words into text using the device's microphone, allowing users to interact with the Chat UI through voice input. + +## Configure Speech-to-Text + +To enable Speech-to-Text functionality in the ASP.NET Core Chat UI control, update the `index.cshtml` file to incorporate the Web Speech API. + +The [SpeechToText](https://ej2.syncfusion.com/aspnetcore/documentation/speech-to-text/getting-started) control listens to audio input from the device’s microphone, transcribes spoken words into text, and updates the Chat UI’s editable footer using the [footerTemplate](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.InteractiveChat.ChatUI.html#Syncfusion_EJ2_InteractiveChat_ChatUI_FooterTemplate) property to display the transcribed text. Once the transcription appears in the footer, users can send it as a message to others. + +### Configuration Options + +* **[`lang`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Inputs.SpeechToText.html#Syncfusion_EJ2_Inputs_SpeechToText_Lang)**: Specifies the language for speech recognition. For example: + + * `en-US` for American English + * `fr-FR` for French + +* **[`allowInterimResults`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Inputs.SpeechToText.html#Syncfusion_EJ2_Inputs_SpeechToText_AllowInterimResults)**: Set to `true` to receive real-time (interim) recognition results, or `false` to receive only final results. + +{% tabs %} +{% highlight razor tabtitle="CSHTML" %} +{% include code-snippet/chat-ui/stt/tagHelper %} +{% endhighlight %} +{% highlight c# tabtitle="Gemini.cs" %} +{% include code-snippet/chat-ui/stt/speechtotext.cs %} +{% endhighlight %} +{% endtabs %} + +![Integrating Speech-to-Text with Chat UI](images/chatui-stt.png) + +## Error Handling + +The `SpeechToText` control provides events to handle errors that may occur during speech recognition. For more information, refer to the [Error Handling](https://ej2.syncfusion.com/aspnetcore/documentation/speech-to-text/speech-recognition#error-handling) section in the documentation. + +## Browser Compatibility + +The `SpeechToText` control relies on the [Speech Recognition API](https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition), which has limited browser support. Refer to the [Browser Compatibility](https://ej2.syncfusion.com/aspnetcore/documentation/speech-to-text/speech-recognition#browser-support) section for detailed information. + +## See Also + +* [Messages](./messages) diff --git a/ej2-asp-core-mvc/chat-ui/images/chatui-stt.png b/ej2-asp-core-mvc/chat-ui/images/chatui-stt.png new file mode 100644 index 0000000000..215da92a78 Binary files /dev/null and b/ej2-asp-core-mvc/chat-ui/images/chatui-stt.png differ diff --git a/ej2-asp-core-mvc/code-snippet/chat-ui/stt/razor b/ej2-asp-core-mvc/code-snippet/chat-ui/stt/razor new file mode 100644 index 0000000000..e057e9407f --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/chat-ui/stt/razor @@ -0,0 +1,144 @@ +@using Syncfusion.EJ2.InteractiveChat; +@using Newtonsoft.Json; + +
+ @Html.EJS().ChatUI("chatui").Created("onCreate").FooterTemplate("#footerContent").Messages(ViewBag.ChatMessagesData).User(ViewBag.CurrentUser).Render() +
+ + + + + + \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/chat-ui/stt/speechtotext.cs b/ej2-asp-core-mvc/code-snippet/chat-ui/stt/speechtotext.cs new file mode 100644 index 0000000000..3ff60f18f6 --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/chat-ui/stt/speechtotext.cs @@ -0,0 +1,30 @@ +using Syncfusion.EJ2.InteractiveChat; + +public ChatUIUser CurrentUser { get; set; } +public List ChatMessagesData { get; set; } = new List(); +public ChatUIUser CurrentUserModel { get; set; } = new ChatUIUser() { Id = "user1", User = "Albert" }; +public ChatUIUser MichaleUserModel { get; set; } = new ChatUIUser() { Id = "user2", User = "Michale Suyama" }; + +public ActionResult SpeechToText() +{ + CurrentUser = CurrentUserModel; + ChatMessagesData.Add(new ChatUIMessage() + { + Text = "Hi Michale, are we on track for the deadline?", + Author = CurrentUserModel + }); + ChatMessagesData.Add(new ChatUIMessage() + { + Text = "Yes, the design phase is complete.", + Author = MichaleUserModel + }); + ChatMessagesData.Add(new ChatUIMessage() + { + Text = "I’ll review it and send feedback by today.", + Author = CurrentUserModel + }); + ViewBag.ChatMessagesData = ChatMessagesData; + ViewBag.CurrentUser = CurrentUser; + ViewBag.MichaleUser = MichaleUserModel; + return View(); +} diff --git a/ej2-asp-core-mvc/code-snippet/chat-ui/stt/tagHelper b/ej2-asp-core-mvc/code-snippet/chat-ui/stt/tagHelper new file mode 100644 index 0000000000..1b7024e9b9 --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/chat-ui/stt/tagHelper @@ -0,0 +1,152 @@ +@using Syncfusion.EJ2.InteractiveChat +@using Newtonsoft.Json; + +
+ + + + @foreach (var message in ViewBag.ChatMessagesData) + { + + } + + +
+ + + + + + \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/rich-text-editor/slashmenu/controller.cs b/ej2-asp-core-mvc/code-snippet/rich-text-editor/slashmenu/controller.cs index 0692f3ac0a..e37415605c 100644 --- a/ej2-asp-core-mvc/code-snippet/rich-text-editor/slashmenu/controller.cs +++ b/ej2-asp-core-mvc/code-snippet/rich-text-editor/slashmenu/controller.cs @@ -27,7 +27,21 @@ public ActionResult Index() iconCss= "e-icons e-signature", type= "Custom", command= "Signature" - } + }, + new { + text: 'HorizontalLine', + description: 'Insert a horizontal line', + iconCss: 'e-icons e-horizontal-line', + type: 'Custom', + command: 'HorizontalLine', + }, + new { + text: 'CheckList', + description: 'Insert a check list', + iconCss: 'e-icons e-checklist', + type: 'Custom', + command: 'CheckList', + }, } } return View(); diff --git a/ej2-asp-core-mvc/code-snippet/rich-text-editor/slashmenu/razor b/ej2-asp-core-mvc/code-snippet/rich-text-editor/slashmenu/razor index 5ef521ee18..d04723da1b 100644 --- a/ej2-asp-core-mvc/code-snippet/rich-text-editor/slashmenu/razor +++ b/ej2-asp-core-mvc/code-snippet/rich-text-editor/slashmenu/razor @@ -13,5 +13,11 @@ if (args.itemData.command === "Signature") { rteObj.executeCommand("insertHTML", signature, { undo: true }); } + if (args.itemData.command === 'HorizontalLine') { + rteObj.executeCommand('insertHTML', '
'); + } + if (args.itemData.command === 'CheckList') { + rteObj.executeCommand('insertHTML',``); + } } \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/rich-text-editor/slashmenu/tagHelper b/ej2-asp-core-mvc/code-snippet/rich-text-editor/slashmenu/tagHelper index d25ba0cdad..eb8a8ae918 100644 --- a/ej2-asp-core-mvc/code-snippet/rich-text-editor/slashmenu/tagHelper +++ b/ej2-asp-core-mvc/code-snippet/rich-text-editor/slashmenu/tagHelper @@ -21,5 +21,11 @@ if (args.itemData.command === "Signature") { rteObj.executeCommand("insertHTML", signature, { undo: true }); } + if (args.itemData.command === 'HorizontalLine') { + rteObj.executeCommand('insertHTML', '
'); + } + if (args.itemData.command === 'CheckList') { + rteObj.executeCommand('insertHTML',``); + } } \ No newline at end of file diff --git a/ej2-asp-core-mvc/common/EJ2_ASP.NETCORE/content-security-policy.md b/ej2-asp-core-mvc/common/EJ2_ASP.NETCORE/content-security-policy.md index e845898604..96401b6de2 100644 --- a/ej2-asp-core-mvc/common/EJ2_ASP.NETCORE/content-security-policy.md +++ b/ej2-asp-core-mvc/common/EJ2_ASP.NETCORE/content-security-policy.md @@ -29,9 +29,8 @@ using System.Security.Cryptography; ... app.Use(async (context, next) => { - RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); byte[] nonceBytes = new byte[32]; - rng.GetBytes(nonceBytes); + RandomNumberGenerator.Fill(nonceBytes); string nonceValue = Convert.ToBase64String(nonceBytes); context.Items.Add("ScriptNonce", nonceValue); context.Response.Headers.Add("Content-Security-Policy", string.Format( diff --git a/ej2-asp-core-mvc/grid/EJ2_ASP.MVC/filtering/filter-bar.md b/ej2-asp-core-mvc/grid/EJ2_ASP.MVC/filtering/filter-bar.md index ab4f8e9a80..e802659738 100644 --- a/ej2-asp-core-mvc/grid/EJ2_ASP.MVC/filtering/filter-bar.md +++ b/ej2-asp-core-mvc/grid/EJ2_ASP.MVC/filtering/filter-bar.md @@ -1,6 +1,6 @@ --- layout: post -title: Filter Bar in ##Platform_Name## Grid Component +title: Filter Bar Syncfusion in ##Platform_Name## Grid Component description: Learn here all about Filter Bar in Syncfusion ##Platform_Name## Grid component of Syncfusion Essential JS 2 and more. platform: ej2-asp-core-mvc control: Filter Bar @@ -43,7 +43,7 @@ The following example demonstrates how to activate default filtering in the grid ![Filter bar](../images/filtering/filterbar.png) -> To enable or dynamically switch the filter type, you must set the [FilterSettings.Type](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.Grids.GridFilterSettings.html#Syncfusion_EJ2_Grids_GridFilterSettings_Type) as **FilterBar**. +> If the [FilterSettings.Type](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.Grids.GridFilterSettings.html#Syncfusion_EJ2_Grids_GridFilterSettings_Type) is not explicitly specified, it defaults to **FilterBar**. ## Filter bar modes @@ -154,4 +154,4 @@ To utilize this feature, you can define a custom template for the filter bar by ## See also -* [How to perform filter by using Wildcard and LIKE operator filter](./filtering/#wildcard-and-like-operator-filter) \ No newline at end of file +* [How to perform filter by using Wildcard and LIKE operator filter](./filtering#wildcard-and-like-operator-filter) \ No newline at end of file diff --git a/ej2-asp-core-mvc/grid/EJ2_ASP.NETCORE/filtering/filter-bar.md b/ej2-asp-core-mvc/grid/EJ2_ASP.NETCORE/filtering/filter-bar.md index a142192bd8..6189f2e112 100644 --- a/ej2-asp-core-mvc/grid/EJ2_ASP.NETCORE/filtering/filter-bar.md +++ b/ej2-asp-core-mvc/grid/EJ2_ASP.NETCORE/filtering/filter-bar.md @@ -1,6 +1,6 @@ --- layout: post -title: Filter Bar in ##Platform_Name## Grid Component +title: Filter Bar Syncfusion in ##Platform_Name## Grid Component description: Learn here all about Filter Bar in Syncfusion ##Platform_Name## Grid component of Syncfusion Essential JS 2 and more. platform: ej2-asp-core-mvc control: Filter Bar @@ -43,7 +43,7 @@ The following example demonstrates how to activate default filtering in the grid ![Filter bar](../images/filtering/filterbar.png) -> To enable or dynamically switch the filter type, you must set the [filterSettings.type](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.GridFilterSettings.html#Syncfusion_EJ2_Grids_GridFilterSettings_Type) as **FilterBar**. +> If the [filterSettings.type](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.GridFilterSettings.html#Syncfusion_EJ2_Grids_GridFilterSettings_Type) is not explicitly specified, it defaults to **FilterBar**. ## Filter bar modes @@ -153,4 +153,4 @@ To utilize this feature, you can define a custom template for the filter bar by ## See also -* [How to perform filter by using Wildcard and LIKE operator filter](./filtering/#wildcard-and-like-operator-filter) \ No newline at end of file +* [How to perform filter by using Wildcard and LIKE operator filter](./filtering#wildcard-and-like-operator-filter) \ No newline at end of file diff --git a/ej2-asp-core-mvc/markdown-editor/EJ2_ASP.MVC/getting-started.md b/ej2-asp-core-mvc/markdown-editor/EJ2_ASP.MVC/getting-started.md index dbba234144..d9dd718009 100644 --- a/ej2-asp-core-mvc/markdown-editor/EJ2_ASP.MVC/getting-started.md +++ b/ej2-asp-core-mvc/markdown-editor/EJ2_ASP.MVC/getting-started.md @@ -10,7 +10,7 @@ documentation: ug # Getting Started with ASP.NET MVC Markdown Editor Control -This section briefly explains about how to include [ASP.NET MVC Rich Text Editor](https://www.syncfusion.com/aspnet-mvc-ui-controls/wysiwyg-rich-text-editor) control in your ASP.NET MVC application using Visual Studio. +This section briefly explains about how to include [ASP.NET MVC Markdown Editor](https://www.syncfusion.com/aspnet-mvc-ui-controls/wysiwyg-rich-text-editor) control in your ASP.NET MVC application using Visual Studio. ## Prerequisites diff --git a/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/annotation.md b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/annotation.md new file mode 100644 index 0000000000..10656dde36 --- /dev/null +++ b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/annotation.md @@ -0,0 +1,77 @@ +--- +layout: post +title: Annotations in ##Platform_Name## Smart Paste Button Control | Syncfusion +description: Learn how to use annotations with the ##Platform_Name## Smart Paste Button control of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: Annotations +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Annotations in ASP.NET Core Smart Paste Button Control + +The Syncfusion ASP.NET Core Smart Paste Button control leverages AI to intelligently parse clipboard content and populate form fields, enhancing user productivity. By default, the control analyzes form fields (e.g., ``, ` + +
+ + +
+
+ +
+ + +
+
+ + +
+
+
+ + +
+ + + + + +
+
+ I am John Doe from the United States. My email is johndoe@example.com, and my phone number is 555-123-4567. I’d like to inquire about your services and have a detailed discussion regarding your product offerings. Please contact me via email. I’m happy to subscribe to your newsletter for updates. Thank you! +
+ +{% endhighlight %} +{% endtabs %} + +![Syncfusion ASP.NET Core Smart Paste Button with Annotation](images/SmartPaste_Annotation.gif) diff --git a/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/claude-service.md b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/claude-service.md new file mode 100644 index 0000000000..b42deedf6b --- /dev/null +++ b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/claude-service.md @@ -0,0 +1,252 @@ +--- +layout: post +title: Claude AI in ##Platform_Name## Smart Paste Button Control | Syncfusion +description: Learn how to implement a custom AI service using Claude AI with ##Platform_Name## Smart Paste Button control of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: Claude AI +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Claude AI Integration with ASP.NET Core Smart Paste Button + +The Syncfusion ASP.NET Core SmartPaste Button control enables AI-powered, context-aware content pasting into forms, typically using OpenAI or Azure OpenAI. This guide explains how to integrate the Anthropic Claude AI service with the Smart Paste Button using the `IChatInferenceService` interface, enabling custom AI-driven responses in a ASP.NET Core App. + +## Setting Up Claude + +1. **Create an Anthropic Account** + Visit [Anthropic Console](https://console.anthropic.com), sign up, and complete the verification process. +2. **Obtain an API Key** + Navigate to [API Keys](https://console.anthropic.com/settings/keys) and click "Create Key." +3. **Review Model Specifications** + Refer to [Claude Models Documentation](https://docs.anthropic.com/claude/docs/models-overview) for details on available models. + +## Create a Claude AI Service + +Create a service class to manage interactions with the Claude API, including authentication and response processing for the Smart Paste Button. + +1. Create a `Services` folder in your project. +2. Add a new file named `ClaudeAIService.cs` in the `Services` folder. +3. Implement the service as shown below, storing the API key securely in a configuration file or environment variable (e.g., `appsettings.json`). + +```csharp +using Microsoft.Extensions.AI; +using System.Net; +using System.Text; +using System.Text.Json; + +public class ClaudeAIService +{ + private readonly string _apiKey; + private readonly string _modelName = "claude-3-5-sonnet-20241022"; // Example model + private readonly string _endpoint = "https://api.anthropic.com/v1/messages"; + private static readonly HttpClient HttpClient = new(new SocketsHttpHandler + { + PooledConnectionLifetime = TimeSpan.FromMinutes(30), + EnableMultipleHttp2Connections = true + }) + { + DefaultRequestVersion = HttpVersion.Version20 // Fallback to HTTP/2 for compatibility + }; + private static readonly JsonSerializerOptions JsonOptions = new() + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; + + public ClaudeAIService(IConfiguration configuration) + { + _apiKey = configuration["Claude:ApiKey"] ?? throw new ArgumentNullException("Claude API key is missing."); + if (!HttpClient.DefaultRequestHeaders.Contains("x-api-key")) + { + HttpClient.DefaultRequestHeaders.Clear(); + HttpClient.DefaultRequestHeaders.Add("x-api-key", _apiKey); + HttpClient.DefaultRequestHeaders.Add("anthropic-version", "2023-06-01"); // Check latest version in Claude API docs + } + } + + public async Task CompleteAsync(IList chatMessages) + { + var requestBody = new ClaudeChatRequest + { + Model = _modelName, + Max_tokens = 1000, // Maximum tokens in response + Messages = chatMessages.Select(m => new ClaudeMessage + { + Role = m.Role == ChatRole.User ? "user" : "assistant", + Content = m.Text + }).ToList(), + Stop_sequences = new List { "END_INSERTION", "NEED_INFO", "END_RESPONSE" } // Configurable stop sequences + }; + + var content = new StringContent(JsonSerializer.Serialize(requestBody, JsonOptions), Encoding.UTF8, "application/json"); + + try + { + var response = await HttpClient.PostAsync(_endpoint, content); + response.EnsureSuccessStatusCode(); + var responseString = await response.Content.ReadAsStringAsync(); + var responseObject = JsonSerializer.Deserialize(responseString, JsonOptions); + return responseObject?.Content?.FirstOrDefault()?.Text ?? "No response from Claude model."; + } + catch (Exception ex) when (ex is HttpRequestException || ex is JsonException) + { + throw new InvalidOperationException("Failed to communicate with Claude API.", ex); + } + } +} +``` + +N> Store the Claude API key in `appsettings.json` (e.g., `{ "Claude": { "ApiKey": "your-api-key" } }`) or as an environment variable to ensure security. Verify the `anthropic-version` header in [Claude API Documentation](https://docs.anthropic.com/claude/docs) for the latest version. + +## Define Request and Response Models + +Define C# classes to match the Claude API’s JSON request and response format. + +1. Create a new file named `ClaudeModels.cs` in the `Services` folder. +2. Add the following model classes: + +```csharp +public class ClaudeChatRequest +{ + public string Model { get; set; } + public int Max_tokens { get; set; } + public List Messages { get; set; } + public List Stop_sequences { get; set; } +} + +public class ClaudeMessage +{ + public string Role { get; set; } + public string Content { get; set; } +} + +public class ClaudeChatResponse +{ + public List Content { get; set; } +} + +public class ClaudeContentBlock +{ + public string Text { get; set; } +} +``` + +## Create a Custom AI Service + +Implement the `IChatInferenceService` interface to connect the Smart Paste Button to the Claude service, acting as a bridge for AI-generated responses. + +1. Create a new file named `ClaudeInferenceService.cs` in the `Services` folder. +2. Add the following implementation: + +```csharp +using Syncfusion.EJ2.AI; +using System.Threading.Tasks; + +public class ClaudeInferenceService : IChatInferenceService +{ + private readonly ClaudeAIService _claudeService; + + public ClaudeInferenceService(ClaudeAIService claudeService) + { + _claudeService = claudeService; + } + + public async Task GenerateResponseAsync(ChatParameters options) + { + return await _claudeService.CompleteAsync(options.Messages); + } +} +``` + +## Configure the ASP.NET Core App + +Register the Claude service and `IChatInferenceService` implementation in the dependency injection container. + +Update the **~/Program.cs** file as follows: + +```csharp +using Syncfusion.EJ2; +using Syncfusion.EJ2.AI; + +builder.Services.AddRazorPages(); +builder.Services.AddSyncfusionSmartComponents(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); + +var app = builder.Build(); +// ... +``` + +## Add the Smart Paste Button + +Add the Smart Paste Button to a form in the **~/Pages/Index.cshtml** file to test the Claude AI integration. + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +

Contact Form

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+
+ + +
+
+
+ + +
+ + + +
+ +
+
+ I am John Doe from the United States. My email is johndoe@example.com, and my phone number is 555-123-4567. I’d like to inquire about your services and have a detailed discussion regarding your product offerings. Please contact me via email. I’m happy to subscribe to your newsletter for updates. Thank you! +
+ +{% endhighlight %} +{% endtabs %} + +Press Ctrl+F5 (Windows) or +F5 (macOS) to run the app. Then, the Syncfusion® ASP.NET Core +Smart Paste Button control will be rendered in the default web browser. + +![ASP.NET Core Smart Paste Button Control](images/SmartPaste.gif) + +## Troubleshooting + +If the Claude AI integration does not work, try the following: +- **No Suggestions Displayed**: Verify that the Claude API key and model name are correct in the configuration. Check the `ClaudeAIService` implementation for errors. +- **HTTP Request Failures**: Ensure a stable internet connection and that the Claude API endpoint (`https://api.anthropic.com/v1/messages`) is accessible. Test with HTTP/2 if compatibility issues arise. +- **Service Registration Errors**: Confirm that `ClaudeAIService` and `ClaudeInferenceService` are registered in **Program.cs**. \ No newline at end of file diff --git a/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/custom-inference-backend.md b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/custom-inference-backend.md new file mode 100644 index 0000000000..a8b829f83b --- /dev/null +++ b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/custom-inference-backend.md @@ -0,0 +1,77 @@ +--- +layout: post +title: Custom AI with ##Platform_Name## Smart Paste Button Control | Syncfusion +description: Learn how to integrate custom AI services with ##Platform_Name## Smart Paste Button control of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: Custom AI Service +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Custom AI Service Integration with ASP.NET Core Smart Paste Button + +The Syncfusion ASP.NET Core Smart Paste Button leverages AI to parse clipboard content and populate form fields, enhancing user productivity. By default, it supports OpenAI and Azure OpenAI services, but you can integrate custom AI services using the `IChatInferenceService` interface. This interface facilitates communication between the Smart Paste Button and your custom AI provider, enabling precise mapping of clipboard data to form fields. + +## IChatInferenceService Interface + +The `IChatInferenceService` interface defines a contract for integrating AI services with the Smart Paste Button, enabling the control to process clipboard data for form field mapping. + +```csharp +public interface IChatInferenceService +{ + Task GenerateResponseAsync(ChatParameters options); +} +``` + +The `GenerateResponseAsync` method takes `ChatParameters` (containing clipboard data and form field metadata) and returns a string response from the AI service, which the Smart Paste Button uses to populate form fields. + +## Simple Implementation of a Custom AI Service + +Below is a sample implementation of a mock AI service named `MockAIService`. This service demonstrates how to implement the `IChatInferenceService` interface by returning sample, context-aware responses. You can replace the logic with your own AI integration. + +```csharp +using Syncfusion.EJ2.AI; +using System.Threading.Tasks; + +public class MockAIService : IChatInferenceService +{ + public Task GenerateResponseAsync(ChatParameters options) + { + + } +} +``` + +## Registering the Custom AI Service + +Register the custom AI service in the **~/Program.cs** file of your ASP.NET Core Application: + +```csharp +using Syncfusion.EJ2; +using Syncfusion.EJ2.AI; + +builder.Services.AddRazorPages(); +builder.Services.AddSyncfusionSmartComponents(); +builder.Services.AddSingleton(); + +var app = builder.Build(); +// ... +``` + +## Implemented AI Services + +Here are examples of AI services integrated using the `IChatInferenceService` interface: + +| Service | Documentation | +|---------|---------------| +| Claude | [Claude Integration](claude-service) | +| DeepSeek | [DeepSeek Integration](deepseek-service) | +| Groq | [Groq Integration](groq-service) | +| Gemini | [Gemini Integration](gemini-service) | + +## Troubleshooting + +If the custom AI integration does not work as expected, try the following: +- **Fields Not Populating**: Verify that the custom AI service’s endpoint, model, and API key are correct in `appsettings.json`. Ensure the `GenerateResponseAsync` method returns valid data. +- **Service Registration Errors**: Confirm that `CustomAIService` and `CustomInferenceService` are registered in **Program.cs**. +- **AI Parsing Errors**: Check the AI service’s response format and ensure it matches the expected `CustomAIResponse` structure. Test the API independently to verify connectivity. diff --git a/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/customization.md b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/customization.md new file mode 100644 index 0000000000..6788ca4a80 --- /dev/null +++ b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/customization.md @@ -0,0 +1,20 @@ +--- +layout: post +title: Customization in ##Platform_Name## Smart Paste Button Control | Syncfusion +description: Explore styles and appearance customization options with ##Platform_Name## Smart Paste Button control of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: Types and Appearance +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Types and Appearance + +The Syncfusion® ASP.NET Core Smart Paste Button control inherits all properties, types, and styling options of the Syncfusion® ASP.NET Core Button control. This allows users to utilize the existing features and flexibility of the Syncfusion® ASP.NET Core Button while taking advantage of the enhanced Smart Paste Button functionality. + +- [Types and Styles](https://ej2.syncfusion.com/aspnetcore/documentation/button/types-and-styles) +- [Style and Appearance](https://ej2.syncfusion.com/aspnetcore/documentation/button/style-and-appearance) + +## See Also + +- [ASP.NET Core Button Control: Types and Styles](https://ej2.syncfusion.com/aspnetcore/documentation/button/types-and-styles) \ No newline at end of file diff --git a/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/deepseek-service.md b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/deepseek-service.md new file mode 100644 index 0000000000..86e8c9f153 --- /dev/null +++ b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/deepseek-service.md @@ -0,0 +1,249 @@ +--- +layout: post +title: DeepSeek AI in ##Platform_Name## Smart Paste Button Control | Syncfusion +description: Learn how to implement a custom AI service using DeepSeek AI with ##Platform_Name## Smart Paste Button control of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: DeepSeek AI +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# DeepSeek AI Integration with ASP.NET Core Smart Paste Button + +The Syncfusion ASP.NET Core SmartPaste Button control enables AI-powered, context-aware content pasting into forms, typically using OpenAI or Azure OpenAI. This guide explains how to integrate the DeepSeek AI service with the Smart Paste Button using the `IChatInferenceService` interface, enabling custom AI-driven responses in a ASP.NET Core App. + +## Setting Up DeepSeek + +1. **Obtain a DeepSeek API Key** + Create an account at [DeepSeek Platform](https://platform.deepseek.com), sign in, and navigate to [API Keys](https://platform.deepseek.com/api_keys) to generate an API key. +2. **Review Model Specifications** + Refer to [DeepSeek Models Documentation](https://api-docs.deepseek.com/quick_start/pricing) for details on available models (e.g., `deepseek-chat`). + +## Create a DeepSeek AI Service + +Create a service class to manage interactions with the DeepSeek API, including authentication and response processing for the Smart Paste Button. + +1. Create a `Services` folder in your project. +2. Add a new file named `DeepSeekAIService.cs` in the `Services` folder. +3. Implement the service as shown below, storing the API key securely in a configuration file or environment variable (e.g., `appsettings.json`). + +```csharp +using System.Net; +using System.Text; +using System.Text.Json; +using Microsoft.Extensions.AI; + +public class DeepSeekAIService +{ + private readonly string _apiKey; + private readonly string _modelName = "deepseek-chat"; // Example model + private readonly string _endpoint = "https://api.deepseek.com/chat/completions"; + private static readonly HttpClient HttpClient = new(new SocketsHttpHandler + { + PooledConnectionLifetime = TimeSpan.FromMinutes(30), + EnableMultipleHttp2Connections = true + }) + { + DefaultRequestVersion = HttpVersion.Version20 // Fallback to HTTP/2 for compatibility + }; + private static readonly JsonSerializerOptions JsonOptions = new() + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; + + public DeepSeekAIService(IConfiguration configuration) + { + _apiKey = configuration["DeepSeek:ApiKey"] ?? throw new ArgumentNullException("DeepSeek API key is missing."); + if (!HttpClient.DefaultRequestHeaders.Contains("Authorization")) + { + HttpClient.DefaultRequestHeaders.Clear(); + HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {_apiKey}"); + } + } + + public async Task CompleteAsync(IList chatMessages) + { + var requestBody = new DeepSeekChatRequest + { + Model = _modelName, + Temperature = 0.7f, // Controls response randomness (0.0 to 1.0) + Messages = chatMessages.Select(m => new DeepSeekMessage + { + Role = m.Role == ChatRole.User ? "user" : "system", // Align with DeepSeek API roles + Content = m.Text + }).ToList() + }; + + var content = new StringContent(JsonSerializer.Serialize(requestBody, JsonOptions), Encoding.UTF8, "application/json"); + + try + { + var response = await HttpClient.PostAsync(_endpoint, content); + response.EnsureSuccessStatusCode(); + var responseString = await response.Content.ReadAsStringAsync(); + var responseObject = JsonSerializer.Deserialize(responseString, JsonOptions); + return responseObject?.Choices?.FirstOrDefault()?.Message?.Content ?? "No response from DeepSeek."; + } + catch (Exception ex) when (ex is HttpRequestException || ex is JsonException) + { + throw new InvalidOperationException("Failed to communicate with DeepSeek API.", ex); + } + } +} +``` + +N> Store the DeepSeek API key in `appsettings.json` (e.g., `{ "DeepSeek": { "ApiKey": "your-api-key" } }`) or as an environment variable to ensure security. + +## Define Request and Response Models + +Define C# classes to match the DeepSeek API’s JSON request and response format. + +1. Create a new file named `DeepSeekModels.cs` in the `Services` folder. +2. Add the following model classes: + +```csharp +public class DeepSeekMessage +{ + public string Role { get; set; } + public string Content { get; set; } +} + +public class DeepSeekChatRequest +{ + public string Model { get; set; } + public float Temperature { get; set; } + public List Messages { get; set; } +} + +public class DeepSeekChatResponse +{ + public List Choices { get; set; } +} + +public class DeepSeekChoice +{ + public DeepSeekMessage Message { get; set; } +} +``` + +## Create a Custom AI Service + +Implement the `IChatInferenceService` interface to connect the Smart Paste Button to the DeepSeek service, acting as a bridge for AI-generated responses. + +1. Create a new file named `DeepSeekInferenceService.cs` in the `Services` folder. +2. Add the following implementation: + +```csharp +using Syncfusion.EJ2.AI; +using System.Threading.Tasks; + +public class DeepSeekInferenceService : IChatInferenceService +{ + private readonly DeepSeekAIService _deepSeekService; + + public DeepSeekInferenceService(DeepSeekAIService deepSeekService) + { + _deepSeekService = deepSeekService; + } + + public async Task GenerateResponseAsync(ChatParameters options) + { + return await _deepSeekService.CompleteAsync(options.Messages); + } +} +``` + +## Configure the Blazor App + +Register the DeepSeek service and `IChatInferenceService` implementation in the dependency injection container. + +Update the **~/Program.cs** file as follows: + +```csharp +using Syncfusion.EJ2; +using Syncfusion.EJ2.AI; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddRazorPages(); +builder.Services.AddSyncfusionSmartComponents(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); + +var app = builder.Build(); +// ... +``` + +## Add the Smart Paste Button + +Add the Smart Paste Button to a form in the **~/Pages/Index.cshtml** file to test the DeepSeek AI integration. + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +

Contact Form

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+
+ + +
+
+
+ + +
+ + + +
+ +
+
+ I am John Doe from the United States. My email is johndoe@example.com, and my phone number is 555-123-4567. I’d like to inquire about your services and have a detailed discussion regarding your product offerings. Please contact me via email. I’m happy to subscribe to your newsletter for updates. Thank you! +
+ +{% endhighlight %} +{% endtabs %} + +Press Ctrl+F5 (Windows) or +F5 (macOS) to run the app. Then, the Syncfusion® ASP.NET Core +Smart Paste Button control will be rendered in the default web browser. + +![ASP.NET Core Smart Paste Button Control](images/SmartPaste.gif) + +## Troubleshooting + +If the DeepSeek AI integration does not work, try the following: +- **No Suggestions Displayed**: Verify that the DeepSeek API key and model name are correct in the configuration. Check the `DeepSeekAIService` implementation for errors. +- **HTTP Request Failures**: Ensure a stable internet connection and that the DeepSeek API endpoint (`https://api.deepseek.com/v1/chat/completions`) is accessible. Test with HTTP/2 if compatibility issues arise. +- **Service Registration Errors**: Confirm that `DeepSeekAIService` and `DeepSeekInferenceService` are registered in **Program.cs**. \ No newline at end of file diff --git a/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/gemini-service.md b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/gemini-service.md new file mode 100644 index 0000000000..2257eb586e --- /dev/null +++ b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/gemini-service.md @@ -0,0 +1,297 @@ +--- +layout: post +title: Gemini AI in ##Platform_Name## Smart Paste Button Control | Syncfusion +description: Learn how to implement a custom AI service using Google's Gemini API with ##Platform_Name## Smart Paste Button control of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: Gemini AI +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Gemini AI Integration with ASP.NET Core Smart Paste Button + +The Syncfusion ASP.NET Core SmartPaste Button control enables AI-powered, context-aware content pasting into forms, typically using OpenAI or Azure OpenAI. This guide explains how to integrate the Google Gemini AI service with the Smart Paste Button using the `IChatInferenceService` interface, enabling custom AI-driven responses in a ASP.NET Core Web App. + +## Setting Up Gemini + +1. **Obtain a Gemini API Key** + Visit [Google AI Studio](https://ai.google.dev/gemini-api/docs/api-key), sign in, and generate an API key. +2. **Review Model Specifications** + Refer to [Gemini Models Documentation](https://ai.google.dev/gemini-api/docs/models) for details on available models. + +## Create a Gemini AI Service + +Create a service class to manage interactions with the Gemini API, including authentication, request/response handling, and safety settings for the Smart Paste Button. + +1. Create a `Services` folder in your project. +2. Add a new file named `GeminiService.cs` in the `Services` folder. +3. Implement the service as shown below, storing the API key securely in a configuration file or environment variable (e.g., `appsettings.json`). + +```csharp +using System.Net; +using System.Text; +using System.Text.Json; +using Microsoft.Extensions.AI; + +public class GeminiService +{ + private readonly string _apiKey; + private readonly string _modelName = "gemini-2.0-flash"; // Example model + private readonly string _endpoint = "https://generativelanguage.googleapis.com/v1beta/models/"; + private static readonly HttpClient HttpClient = new(new SocketsHttpHandler + { + PooledConnectionLifetime = TimeSpan.FromMinutes(30), + EnableMultipleHttp2Connections = true + }) + { + DefaultRequestVersion = HttpVersion.Version20 // Fallback to HTTP/2 for compatibility + }; + private static readonly JsonSerializerOptions JsonOptions = new() + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; + + public GeminiService(IConfiguration configuration) + { + _apiKey = configuration["Gemini:ApiKey"] ?? throw new ArgumentNullException("Gemini API key is missing."); + HttpClient.DefaultRequestHeaders.Clear(); + HttpClient.DefaultRequestHeaders.Add("x-goog-api-key", _apiKey); + } + + public async Task CompleteAsync(IList chatMessages) + { + var requestUri = $"{_endpoint}{_modelName}:generateContent"; + var parameters = BuildGeminiChatParameters(chatMessages); + var payload = new StringContent( + JsonSerializer.Serialize(parameters, JsonOptions), + Encoding.UTF8, + "application/json" + ); + + try + { + using var response = await HttpClient.PostAsync(requestUri, payload); + response.EnsureSuccessStatusCode(); + var json = await response.Content.ReadAsStringAsync(); + var result = JsonSerializer.Deserialize(json, JsonOptions); + return result?.Candidates?.FirstOrDefault()?.Content?.Parts?.FirstOrDefault()?.Text + ?? "No response from model."; + } + catch (Exception ex) when (ex is HttpRequestException or JsonException) + { + throw new InvalidOperationException("Gemini API error.", ex); + } + } + + private GeminiChatParameters BuildGeminiChatParameters(IList messages) + { + var contents = messages.Select(m => new ResponseContent( + m.Text, + m.Role == ChatRole.User ? "user" : "model" + )).ToList(); + + return new GeminiChatParameters + { + Contents = contents, + GenerationConfig = new GenerationConfig + { + MaxOutputTokens = 2000, + StopSequences = new List { "END_INSERTION", "NEED_INFO", "END_RESPONSE" } // Configurable stop sequences + }, + SafetySettings = new List + { + new() { Category = "HARM_CATEGORY_HARASSMENT", Threshold = "BLOCK_ONLY_HIGH" }, + new() { Category = "HARM_CATEGORY_HATE_SPEECH", Threshold = "BLOCK_ONLY_HIGH" }, + new() { Category = "HARM_CATEGORY_SEXUALLY_EXPLICIT", Threshold = "BLOCK_ONLY_HIGH" }, + new() { Category = "HARM_CATEGORY_DANGEROUS_CONTENT", Threshold = "BLOCK_ONLY_HIGH" } + } + }; + } +} +``` + +N> Store the Gemini API key in `appsettings.json` (e.g., `{ "Gemini": { "ApiKey": "your-api-key" } }`) or as an environment variable to ensure security. The `SafetySettings` filter harmful content; adjust thresholds based on your application’s needs. + +## Define Request and Response Models + +Define C# classes to match the Gemini API’s JSON request and response format. + +1. Create a new file named `GeminiModels.cs` in the `Services` folder. +2. Add the following model classes: + +```csharp +public class Part +{ + public string Text { get; set; } +} + +public class Content +{ + public Part[] Parts { get; init; } = Array.Empty(); +} + +public class Candidate +{ + public Content Content { get; init; } = new(); +} + +public class GeminiResponseObject +{ + public Candidate[] Candidates { get; init; } = Array.Empty(); +} + +public class ResponseContent +{ + public List Parts { get; init; } + public string Role { get; init; } + + public ResponseContent(string text, string role) + { + Parts = new List { new Part { Text = text } }; + Role = role; + } +} + +public class GenerationConfig +{ + public int Temperature { get; init; } = 0; + public int TopK { get; init; } = 0; + public int TopP { get; init; } = 0; + public int MaxOutputTokens { get; init; } = 2048; + public List StopSequences { get; init; } = new(); +} + +public class SafetySetting +{ + public string Category { get; init; } = string.Empty; + public string Threshold { get; init; } = string.Empty; +} + +public class GeminiChatParameters +{ + public List Contents { get; init; } = new(); + public GenerationConfig GenerationConfig { get; init; } = new(); + public List SafetySettings { get; init; } = new(); +} +``` + +## Create a Custom AI Service + +Implement the `IChatInferenceService` interface to connect the Smart Paste Button to the Gemini service, acting as a bridge for AI-generated responses. + +1. Create a new file named `GeminiInferenceService.cs` in the `Services` folder. +2. Add the following implementation: + +```csharp +using Syncfusion.EJ2.AI; +using System.Threading.Tasks; + +public class GeminiInferenceService : IChatInferenceService +{ + private readonly GeminiService _geminiService; + + public GeminiInferenceService(GeminiService geminiService) + { + _geminiService = geminiService; + } + + public async Task GenerateResponseAsync(ChatParameters options) + { + return await _geminiService.CompleteAsync(options.Messages); + } +} +``` + +## Configure the ASP.NET Core App + +Register the Gemini service and `IChatInferenceService` implementation in the dependency injection container. + +Update the **~/Program.cs** file as follows: + +```csharp +using Syncfusion.EJ2; +using Syncfusion.EJ2.AI; + +builder.Services.AddRazorPages(); + +builder.Services.AddSyncfusionSmartComponents(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); + +var app = builder.Build(); +// ... +``` + +## Add the Smart Paste Button + +Add the Smart Paste Button to a form in the **~/Pages/Index.cshtml** file to test the Gemini AI integration. + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +

Contact Form

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+
+ + +
+
+
+ + +
+ + + +
+ +
+
+ I am John Doe from the United States. My email is johndoe@example.com, and my phone number is 555-123-4567. I’d like to inquire about your services and have a detailed discussion regarding your product offerings. Please contact me via email. I’m happy to subscribe to your newsletter for updates. Thank you! +
+ +{% endhighlight %} +{% endtabs %} + +Press Ctrl+F5 (Windows) or +F5 (macOS) to run the app. Then, the Syncfusion® ASP.NET Core +Smart Paste Button control will be rendered in the default web browser. + +![ASP.NET Core Smart Paste Button Control](images/SmartPaste.gif) + +## Troubleshooting + +If the Gemini AI integration does not work, try the following: +- **No Suggestions Displayed**: Verify that the Gemini API key and model name are correct in the configuration. Check the `GeminiService` implementation for errors. +- **HTTP Request Failures**: Ensure a stable internet connection and that the Gemini API endpoint (`https://generativelanguage.googleapis.com/v1beta/models/`) is accessible. Test with HTTP/2 if compatibility issues arise. +- **Service Registration Errors**: Confirm that `GeminiService` and `GeminiInferenceService` are registered in **Program.cs**. \ No newline at end of file diff --git a/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/getting-started.md b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/getting-started.md new file mode 100644 index 0000000000..6f736a385c --- /dev/null +++ b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/getting-started.md @@ -0,0 +1,285 @@ +--- +layout: post +title: Getting Started with ##Platform_Name## Smart Paste Button | Syncfusion +description: Checkout and learn about getting started with ##Platform_Name## Smart Paste Button control of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: Getting Started +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Getting Started with ASP.NET Core Smart Paste Button Control + +This section briefly explains about how to include `ASP.NET Core Smart Paste Button` control in your ASP.NET Core application using Visual Studio. + +## Prerequisites + +[System requirements for ASP.NET Core controls](https://ej2.syncfusion.com/aspnetcore/documentation/system-requirements) + +## Create ASP.NET Core web application with Razor pages + +* [Create a Project using Microsoft Templates](https://learn.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/razor-pages-start?view=aspnetcore-8.0&tabs=visual-studio#create-a-razor-pages-web-app) + +* [Create a Project using Syncfusion® ASP.NET Core Extension](https://ej2.syncfusion.com/aspnetcore/documentation/visual-studio-integration/create-project) + +## Install ASP.NET Core package in the application + +To add `ASP.NET Core` controls in the application, open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), search for [Syncfusion.EJ2.AspNet.Core](https://www.nuget.org/packages/Syncfusion.EJ2.AspNet.Core/) and then install it. Alternatively, you can utilize the following package manager command to achieve the same. + +{% tabs %} +{% highlight C# tabtitle="Package Manager" %} + +Install-Package Syncfusion.EJ2.AspNet.Core -Version {{ site.releaseversion }} + +{% endhighlight %} +{% endtabs %} + +N> Syncfusion® ASP.NET Core controls are available in [nuget.org.](https://www.nuget.org/packages?q=syncfusion.EJ2) Refer to [NuGet packages topic](https://ej2.syncfusion.com/aspnetcore/documentation/nuget-packages) to learn more about installing NuGet packages in various OS environments. The Syncfusion.EJ2.AspNet.Core NuGet package has dependencies, [Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json/) for JSON serialization and [Syncfusion.Licensing](https://www.nuget.org/packages/Syncfusion.Licensing/) for validating Syncfusion® license key. + +## Add Syncfusion® ASP.NET Core Tag Helper +Open `~/Pages/_ViewImports.cshtml` file and import the `Syncfusion.EJ2` TagHelper. + +{% tabs %} +{% highlight C# tabtitle="~/_ViewImports.cshtml" %} + +@addTagHelper *, Syncfusion.EJ2 + +{% endhighlight %} +{% endtabs %} + +## Add stylesheet and script resources + +Here, the theme and script is referred using CDN inside the `` of `~/Pages/Shared/_Layout.cshtml` file as follows, + +{% tabs %} +{% highlight cshtml tabtitle="~/_Layout.cshtml" %} + + + ... + + + + + + +{% endhighlight %} +{% endtabs %} + +N> Checkout the [Themes topic](https://ej2.syncfusion.com/aspnetcore/documentation/appearance/theme) to learn different ways ([CDN](https://ej2.syncfusion.com/aspnetcore/documentation/common/adding-script-references#cdn-reference), [NPM package](https://ej2.syncfusion.com/aspnetcore/documentation/common/adding-script-references#node-package-manager-npm), and [CRG](https://ej2.syncfusion.com/aspnetcore/documentation/common/custom-resource-generator)) to refer styles in ASP.NET Core application, and to have the expected appearance for Syncfusion® ASP.NET Core controls. + +N> Checkout the [Adding Script Reference](https://ej2.syncfusion.com/aspnetcore/documentation/common/adding-script-references) topic to learn different approaches for adding script references in your ASP.NET Core application. + +## Register Syncfusion® Script Manager + +Also, register the script manager `` at the end of `` in the ASP.NET Core application as follows. + +{% tabs %} +{% highlight cshtml tabtitle="~/_Layout.cshtml" %} + + + ... + + + + +{% endhighlight %} +{% endtabs %} + +## Configure AI Service + +The Smart Paste Button requires an AI service (OpenAI, Azure OpenAI, or Ollama) to analyze and map copied text to form fields. Follow the instructions below to configure an AI model in your application. + +### Install AI Service NuGet Packages + +Install the following NuGet packages based on your chosen AI provider: + +{% tabs %} +{% highlight c# tabtitle="Package Manager" %} + +Install-Package Microsoft.Extensions.AI +Install-Package Microsoft.Extensions.AI.OpenAI +@* For Azure OpenAI only *@ +Install-Package Azure.AI.OpenAI +@* For Ollama only *@ +Install-Package OllamaSharp + +{% endhighlight %} +{% endtabs %} + +### OpenAI Configuration + +For OpenAI, obtain an API key from [OpenAI](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key) and specify the desired model (e.g., `gpt-3.5-turbo`, `gpt-4`). Store the API key securely in a configuration file or environment variable. + +Add the following to the **~/Program.cs** file: + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +using Microsoft.Extensions.AI; +using OpenAI; +using Syncfusion.EJ2; + + +builder.Services.AddRazorPages(); + +string openAIApiKey = "API-KEY"; +string openAIModel = "OPENAI_MODEL"; +OpenAIClient openAIClient = new OpenAIClient(openAIApiKey); +IChatClient openAIChatClient = openAIClient.GetChatClient(openAIModel).AsIChatClient(); +builder.Services.AddChatClient(openAIChatClient); + +builder.Services.AddSyncfusionSmartComponents() + .InjectOpenAIInference(); + +var app = builder.Build(); +.... + +{% endhighlight %} +{% endtabs %} + +### Azure OpenAI Configuration + +For Azure OpenAI, deploy a resource and model as described in [Azure OpenAI documentation](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource). Obtain the API key, endpoint, and model name from your Azure portal. + +Add the following to the **~/Program.cs** file: + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +using Syncfusion.EJ2; +using Microsoft.Extensions.AI; +using Azure.AI.OpenAI; +using System.ClientModel; + +builder.Services.AddRazorPages(); + +string azureOpenAIKey = "AZURE_OPENAI_KEY"; +string azureOpenAIEndpoint = "AZURE_OPENAI_ENDPOINT"; +string azureOpenAIModel = "AZURE_OPENAI_MODEL"; +AzureOpenAIClient azureOpenAIClient = new AzureOpenAIClient( + new Uri(azureOpenAIEndpoint), + new ApiKeyCredential(azureOpenAIKey) +); +IChatClient azureOpenAIChatClient = azureOpenAIClient.GetChatClient(azureOpenAIModel).AsIChatClient(); +builder.Services.AddChatClient(azureOpenAIChatClient); + +builder.Services.AddSyncfusionSmartComponents() + .InjectOpenAIInference(); + +var app = builder.Build(); +.... + +{% endhighlight %} +{% endtabs %} + +### Ollama Configuration + +To use Ollama for self-hosted models: + +1. Download and install Ollama from [Ollama's official website](https://ollama.com). +2. Install a model from the [Ollama Library](https://ollama.com/library) (e.g., `llama2:13b`, `mistral:7b`). +3. Configure the endpoint URL (e.g., `http://localhost:11434`) and model name. + +Add the following to the **~/Program.cs** file: + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +using Syncfusion.EJ2; +using Microsoft.Extensions.AI; +using OllamaSharp; + +builder.Services.AddRazorPages(); + +string ModelName = "MODEL_NAME"; +IChatClient chatClient = new OllamaApiClient("http://localhost:11434", ModelName); +builder.Services.AddChatClient(chatClient); + +builder.Services.AddSyncfusionSmartComponents() + .InjectOpenAIInference(); + +var app = builder.Build(); +.... + +{% endhighlight %} +{% endtabs %} + +## Add ASP.NET Core Smart Paste Button Control + +Now, add the Syncfusion® ASP.NET Core Smart Paste Button tag helper in `~/Pages/Index.cshtml` page. + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +

Contact Form

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+
+ + +
+
+
+ + +
+ + + +
+ +
+
+ I am John Doe from the United States. My email is johndoe@example.com, and my phone number is 555-123-4567. I’d like to inquire about your services and have a detailed discussion regarding your product offerings. Please contact me via email. I’m happy to subscribe to your newsletter for updates. Thank you! +
+ +{% endhighlight %} +{% endtabs %} + +Press Ctrl+F5 (Windows) or +F5 (macOS) to run the app. Then, the Syncfusion® ASP.NET Core +Smart Paste Button control will be rendered in the default web browser. + +![ASP.NET Core Smart Paste Button Control](images/SmartPaste.gif) + +## Performance Considerations + +For optimal performance with the Smart Paste Button: +- Use lightweight AI models (e.g., `gpt-3.5-turbo` or `mistral:7b`) for faster processing. +- Limit form complexity to reduce AI parsing time, especially for large datasets. +- Cache AI model responses where possible to minimize repeated API calls. + +## Troubleshooting Common Issues + +- **AI Service Configuration Errors**: Verify the API key, endpoint, and model name in `Program.cs`. Check for typos or incorrect values. +- **Network Failures**: Ensure a stable internet connection for OpenAI or Azure OpenAI. For Ollama, confirm the local server is running at the specified endpoint (e.g., `http://localhost:11434`). +- **Form Not Populating**: Confirm that the copied text matches the form field structure and that the AI model is correctly configured. diff --git a/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/groq-service.md b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/groq-service.md new file mode 100644 index 0000000000..20c3163380 --- /dev/null +++ b/ej2-asp-core-mvc/smart-paste/EJ2_ASP.NETCORE/groq-service.md @@ -0,0 +1,250 @@ +--- +layout: post +title: Groq AI in ##Platform_Name## Smart Paste Button Control | Syncfusion +description: Learn how to implement a custom AI service using Groq AI with ##Platform_Name## Smart Paste Button control of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: Groq AI +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Groq AI Integration with ASP.NET Core Smart Paste Button + +The Syncfusion ASP.NET Core Smart Paste Button control enables AI-powered, context-aware content pasting into forms, typically using OpenAI or Azure OpenAI. This guide explains how to integrate the Groq AI service with the Smart Paste Button using the `IChatInferenceService` interface, enabling custom AI-driven responses in a ASP.NET Core app. + +## Setting Up Groq + +1. **Create a Groq Account** + Visit [Groq Cloud Console](https://console.groq.com), sign up or sign in, and complete the verification process. +2. **Obtain an API Key** + Navigate to [API Keys](https://console.groq.com/keys) in the Groq Console and click "Create API Key." +3. **Review Model Specifications** + Refer to [Groq Models Documentation](https://console.groq.com/docs/models) for details on available models (e.g., `llama3-8b-8192`). + +## Create a Groq AI Service + +Create a service class to manage interactions with the Groq API, including authentication and response processing for the Smart Paste Button. + +1. Create a `Services` folder in your project. +2. Add a new file named `GroqService.cs` in the `Services` folder. +3. Implement the service as shown below, storing the API key securely in a configuration file or environment variable (e.g., `appsettings.json` or environment variables). + +```csharp +using Microsoft.Extensions.AI; +using System.Net; +using System.Text; +using System.Text.Json; + +public class GroqService +{ + private readonly string _apiKey; + private readonly string _modelName = "llama-3.3-70b-versatile"; // Example model + private readonly string _endpoint = "https://api.groq.com/openai/v1/chat/completions"; + private static readonly HttpClient HttpClient = new(new SocketsHttpHandler + { + PooledConnectionLifetime = TimeSpan.FromMinutes(30), + EnableMultipleHttp2Connections = true + }) + { + DefaultRequestVersion = HttpVersion.Version20 // Fallback to HTTP/2 for broader compatibility + }; + private static readonly JsonSerializerOptions JsonOptions = new() + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; + + public GroqService(IConfiguration configuration) + { + _apiKey = configuration["Groq:ApiKey"] ?? throw new ArgumentNullException("Groq API key is missing."); + if (!HttpClient.DefaultRequestHeaders.Contains("Authorization")) + { + HttpClient.DefaultRequestHeaders.Clear(); + HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {_apiKey}"); + } + } + + public async Task CompleteAsync(IList chatMessages) + { + var requestPayload = new GroqChatParameters + { + Model = _modelName, + Messages = chatMessages.Select(m => new Message + { + Role = m.Role == ChatRole.User ? "user" : "assistant", + Content = m.Text + }).ToList(), + Stop = new List { "END_INSERTION", "NEED_INFO", "END_RESPONSE" } // Configurable stop sequences + }; + + var content = new StringContent(JsonSerializer.Serialize(requestPayload, JsonOptions), Encoding.UTF8, "application/json"); + + try + { + var response = await HttpClient.PostAsync(_endpoint, content); + response.EnsureSuccessStatusCode(); + var responseString = await response.Content.ReadAsStringAsync(); + var responseObject = JsonSerializer.Deserialize(responseString, JsonOptions); + return responseObject?.Choices?.FirstOrDefault()?.Message?.Content ?? "No response from model."; + } + catch (Exception ex) when (ex is HttpRequestException || ex is JsonException) + { + throw new InvalidOperationException("Failed to communicate with Groq API.", ex); + } + } +} +``` + +N> Store the Groq API key in `appsettings.json` (e.g., `{ "Groq": { "ApiKey": "your-api-key" } }`) or as an environment variable to ensure security. + +## Define Request and Response Models + +Define C# classes to match the Groq API’s request and response format. + +1. Create a new file named `GroqModels.cs` in the `Services` folder. +2. Add the following model classes: + +```csharp +public class Choice +{ + public Message Message { get; set; } +} + +public class Message +{ + public string Role { get; set; } + public string Content { get; set; } +} + +public class GroqChatParameters +{ + public string Model { get; set; } + public List Messages { get; set; } + public List Stop { get; set; } +} + +public class GroqResponseObject +{ + public string Model { get; set; } + public List Choices { get; set; } +} +``` + +## Create a Custom AI Service + +Implement the `IChatInferenceService` interface to connect the Smart Paste Button to the Groq service. + +1. Create a new file named `GroqInferenceService.cs` in the `Services` folder. +2. Add the following implementation: + +```csharp +using Syncfusion.EJ2.AI; +using System.Threading.Tasks; + +public class GroqInferenceService : IChatInferenceService +{ + private readonly GroqService _groqService; + + public GroqInferenceService(GroqService groqService) + { + _groqService = groqService; + } + + public async Task GenerateResponseAsync(ChatParameters options) + { + return await _groqService.CompleteAsync(options.Messages); + } +} +``` + +## Configure the ASP.NET Core App + +Register the Groq service and `IChatInferenceService` implementation in the dependency injection container. + +Update the **~/Program.cs** file as follows: + +```csharp +using Syncfusion.EJ2; +using Syncfusion.EJ2.AI; + +builder.Services.AddRazorPages(); +builder.Services.AddSyncfusionSmartComponents(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); + +var app = builder.Build(); +// ... +``` + +## Add the Smart Paste Button + +Add the Smart Paste Button to a form in the **~/Pages/Index.cshtml** file to test the Gemini AI integration. + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +

Contact Form

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+
+ + +
+
+
+ + +
+ + + +
+ +
+
+ I am John Doe from the United States. My email is johndoe@example.com, and my phone number is 555-123-4567. I’d like to inquire about your services and have a detailed discussion regarding your product offerings. Please contact me via email. I’m happy to subscribe to your newsletter for updates. Thank you! +
+ +{% endhighlight %} +{% endtabs %} + +Press Ctrl+F5 (Windows) or +F5 (macOS) to run the app. Then, the Syncfusion® ASP.NET Core +Smart Paste Button control will be rendered in the default web browser. + +![ASP.NET Core Smart Paste Button Control](images/SmartPaste.gif) + +## Troubleshooting + +If the Groq AI integration does not work, try the following: +- **No Suggestions Displayed**: Verify that the Groq API key and model name are correct in the configuration. Check the `GroqService` implementation for errors. +- **HTTP Request Failures**: Ensure a stable internet connection and that the Groq API endpoint (`https://api.groq.com/openai/v1/chat/completions`) is accessible. Test with HTTP/2 instead of HTTP/3 if compatibility issues arise. +- **Service Registration Errors**: Confirm that `GroqService` and `GroqInferenceService` are registered in **Program.cs**. \ No newline at end of file diff --git a/ej2-asp-core-mvc/smart-paste/images/SmartPaste.gif b/ej2-asp-core-mvc/smart-paste/images/SmartPaste.gif new file mode 100644 index 0000000000..0a177a1633 Binary files /dev/null and b/ej2-asp-core-mvc/smart-paste/images/SmartPaste.gif differ diff --git a/ej2-asp-core-mvc/smart-paste/images/SmartPaste_Annotation.gif b/ej2-asp-core-mvc/smart-paste/images/SmartPaste_Annotation.gif new file mode 100644 index 0000000000..28f361e143 Binary files /dev/null and b/ej2-asp-core-mvc/smart-paste/images/SmartPaste_Annotation.gif differ diff --git a/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/claude-service.md b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/claude-service.md new file mode 100644 index 0000000000..828e8b673a --- /dev/null +++ b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/claude-service.md @@ -0,0 +1,208 @@ +--- +layout: post +title: Claude AI in ##Platform_Name## Smart TextArea Control | Syncfusion +description: Learn how to implement a custom AI service using Claude AI with ##Platform_Name## Smart TextArea control of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: Claude AI +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Claude AI Integration with ASP.NET Core Smart TextArea + +The Syncfusion ASP.NET Core Smart TextArea control provides AI-powered autocompletion for context-aware text input, typically using OpenAI or Azure OpenAI. This guide explains how to integrate the Anthropic Claude AI service with the Smart TextArea using the `IChatInferenceService` interface, enabling custom AI-driven responses in a ASP.NET Core App. + +## Setting Up Claude + +1. **Create an Anthropic Account** + Visit [Anthropic Console](https://console.anthropic.com), sign up, and complete the verification process. +2. **Obtain an API Key** + Navigate to [API Keys](https://console.anthropic.com/settings/keys) and click "Create Key." +3. **Review Model Specifications** + Refer to [Claude Models Documentation](https://docs.anthropic.com/claude/docs/models-overview) for details on available models. + +## Create a Claude AI Service + +Create a service class to manage interactions with the Claude API, including authentication and response processing for the Smart TextArea. + +1. Create a `Services` folder in your project. +2. Add a new file named `ClaudeAIService.cs` in the `Services` folder. +3. Implement the service as shown below, storing the API key securely in a configuration file or environment variable (e.g., `appsettings.json`). + +```csharp +using Microsoft.Extensions.AI; +using System.Net; +using System.Text; +using System.Text.Json; + +public class ClaudeAIService +{ + private readonly string _apiKey; + private readonly string _modelName = "claude-3-5-sonnet-20241022"; // Example model + private readonly string _endpoint = "https://api.anthropic.com/v1/messages"; + private static readonly HttpClient HttpClient = new(new SocketsHttpHandler + { + PooledConnectionLifetime = TimeSpan.FromMinutes(30), + EnableMultipleHttp2Connections = true + }) + { + DefaultRequestVersion = HttpVersion.Version20 // Fallback to HTTP/2 for compatibility + }; + private static readonly JsonSerializerOptions JsonOptions = new() + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; + + public ClaudeAIService(IConfiguration configuration) + { + _apiKey = configuration["Claude:ApiKey"] ?? throw new ArgumentNullException("Claude API key is missing."); + if (!HttpClient.DefaultRequestHeaders.Contains("x-api-key")) + { + HttpClient.DefaultRequestHeaders.Clear(); + HttpClient.DefaultRequestHeaders.Add("x-api-key", _apiKey); + HttpClient.DefaultRequestHeaders.Add("anthropic-version", "2023-06-01"); // Check latest version in Claude API docs + } + } + + public async Task CompleteAsync(IList chatMessages) + { + var requestBody = new ClaudeChatRequest + { + Model = _modelName, + Max_tokens = 1000, // Maximum tokens in response + Messages = chatMessages.Select(m => new ClaudeMessage + { + Role = m.Role == ChatRole.User ? "user" : "assistant", + Content = m.Text + }).ToList(), + Stop_sequences = new List { "END_INSERTION", "NEED_INFO", "END_RESPONSE" } // Configurable stop sequences + }; + + var content = new StringContent(JsonSerializer.Serialize(requestBody, JsonOptions), Encoding.UTF8, "application/json"); + + try + { + var response = await HttpClient.PostAsync(_endpoint, content); + response.EnsureSuccessStatusCode(); + var responseString = await response.Content.ReadAsStringAsync(); + var responseObject = JsonSerializer.Deserialize(responseString, JsonOptions); + return responseObject?.Content?.FirstOrDefault()?.Text ?? "No response from Claude model."; + } + catch (Exception ex) when (ex is HttpRequestException || ex is JsonException) + { + throw new InvalidOperationException("Failed to communicate with Claude API.", ex); + } + } +} +``` + +N> Store the Claude API key in `appsettings.json` (e.g., `{ "Claude": { "ApiKey": "your-api-key" } }`) or as an environment variable to ensure security. Verify the `anthropic-version` header in [Claude API Documentation](https://docs.anthropic.com/claude/docs) for the latest version. + +## Define Request and Response Models + +Define C# classes to match the Claude API’s JSON request and response format. + +1. Create a new file named `ClaudeModels.cs` in the `Services` folder. +2. Add the following model classes: + +```csharp +public class ClaudeChatRequest +{ + public string Model { get; set; } + public int Max_tokens { get; set; } + public List Messages { get; set; } + public List Stop_sequences { get; set; } +} + +public class ClaudeMessage +{ + public string Role { get; set; } + public string Content { get; set; } +} + +public class ClaudeChatResponse +{ + public List Content { get; set; } +} + +public class ClaudeContentBlock +{ + public string Text { get; set; } +} +``` + +## Create a Custom AI Service + +Implement the `IChatInferenceService` interface to connect the Smart TextArea to the Claude service, acting as a bridge for AI-generated responses. + +1. Create a new file named `ClaudeInferenceService.cs` in the `Services` folder. +2. Add the following implementation: + +```csharp +using Syncfusion.EJ2.AI; +using System.Threading.Tasks; + +public class ClaudeInferenceService : IChatInferenceService +{ + private readonly ClaudeAIService _claudeService; + + public ClaudeInferenceService(ClaudeAIService claudeService) + { + _claudeService = claudeService; + } + + public async Task GenerateResponseAsync(ChatParameters options) + { + return await _claudeService.CompleteAsync(options.Messages); + } +} +``` + +## Configure the ASP.NET Core App + +Register the Claude service and `IChatInferenceService` implementation in the dependency injection container. + +Update the **~/Program.cs** file as follows: + +```csharp +using Syncfusion.EJ2.AI; + +builder.Services.AddRazorPages(); +builder.Services.AddSyncfusionSmartComponents(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); + +var app = builder.Build(); +// ... +``` + +## Add ASP.NET Core Smart TextArea Control + +Add the Smart TextArea in the **~/Pages/Index.cshtml** file to test the Claude AI integration. + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +@{ + var presets = new { + userRole = "Maintainer of an open-source project replying to GitHub issues", + userPhrases = new[] { "Thank you for contacting us.", "To investigate, we'll need a repro as a public Git repo.", "Could you please post a screenshot of NEED_INFO?", "This sounds like a usage question. This issue tracker is intended for bugs and feature proposals. Unfortunately, we don't have the capacity to answer general usage questions and would recommend StackOverflow for a faster response.", "We don't accept ZIP files as repros." }, + placeHolder = "Write your response to the GitHub issue..." }; +} + + + +{% endhighlight %} +{% endtabs %} + +Press Ctrl+F5 (Windows) or +F5 (macOS) to run the app. Then, the Syncfusion® ASP.NET Core +Smart TextArea control will be rendered in the default web browser. + +![ASP.NET Core Smart TextArea Control](images/SmartTextArea.gif) + +## Troubleshooting + +If the Claude AI integration does not work, try the following: +- **No Suggestions Displayed**: Verify that the Claude API key and model name are correct in the configuration. Check the `ClaudeAIService` implementation for errors. +- **HTTP Request Failures**: Ensure a stable internet connection and that the Claude API endpoint (`https://api.anthropic.com/v1/messages`) is accessible. Test with HTTP/2 if compatibility issues arise. +- **Service Registration Errors**: Confirm that `ClaudeAIService` and `ClaudeInferenceService` are registered in **Program.cs**. diff --git a/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/custom-inference-backend.md b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/custom-inference-backend.md new file mode 100644 index 0000000000..083a4f2c9e --- /dev/null +++ b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/custom-inference-backend.md @@ -0,0 +1,80 @@ +--- +layout: post +title: Custom AI with ##Platform_Name## Smart TextArea Control | Syncfusion +description: Learn how to integrate custom AI services with ##Platform_Name## Smart TextArea control of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: Custom AI Service +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Custom AI Service Integration with ASP.NET Core Smart TextArea + +The Syncfusion ASP.NET Core Smart TextArea control leverages AI to provide context-aware autocompletion, typically using OpenAI or Azure OpenAI services. Developers can integrate custom AI services using the `IChatInferenceService` interface, which standardizes communication between the Smart TextArea and third-party AI providers. This section explains how to implement and register a custom AI service for the Smart TextArea. + +## IChatInferenceService Interface + +The `IChatInferenceService` interface defines a contract for integrating custom AI services with Syncfusion Smart Controls. It enables the Smart TextArea to request and receive AI-generated responses. + +```csharp +public interface IChatInferenceService +{ + Task GenerateResponseAsync(ChatParameters options); +} +``` + +- **Purpose**: Standardizes communication for AI-generated responses. +- **Parameters**: The `ChatParameters` type includes properties like user input and context. +- **Benefits**: Enables seamless switching between AI providers without modifying component code. + +## Simple Implementation of a Custom AI Service + +Below is a sample implementation of a mock AI service named `MockAIService`. This service demonstrates how to implement the `IChatInferenceService` interface by returning sample, context-aware responses. You can replace the logic with your own AI integration. + +```csharp +using Syncfusion.EJ2.AI; +using System.Threading.Tasks; + +public class MockAIService : IChatInferenceService +{ + public Task GenerateResponseAsync(ChatParameters options) + { + + } +} +``` + +## Registering the Custom AI Service + +Register the custom AI service in the **~/Program.cs** file of your ASP.NET Core Application: + +```csharp +using Syncfusion.EJ2; +using Syncfusion.EJ2.AI; + +builder.Services.AddRazorPages(); +builder.Services.AddSyncfusionSmartComponents(); +builder.Services.AddSingleton(); + +var app = builder.Build(); +// ... +``` + +## Implemented AI Services + +Here are examples of AI services integrated using the `IChatInferenceService` interface: + +| Service | Documentation | +|---------|---------------| +| Claude | [Claude Integration](claude-service) | +| DeepSeek | [DeepSeek Integration](deepseek-service) | +| Groq | [Groq Integration](groq-service) | +| Gemini | [Gemini Integration](gemini-service) | + +## Troubleshooting + +If the custom AI service does not work as expected, try the following: +- **No Suggestions Displayed**: Ensure the `IChatInferenceService` implementation is registered in **Program.cs** and returns valid responses. Check for errors in the `GenerateResponseAsync` method. +- **Dependency Issues**: Verify that all required NuGet packages are installed. Run `dotnet restore` to resolve dependencies. +- **Incorrect Responses**: Debug the custom AI service implementation to ensure it processes `ChatParameters` correctly and returns expected responses. + diff --git a/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/customization.md b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/customization.md new file mode 100644 index 0000000000..b0c3341f63 --- /dev/null +++ b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/customization.md @@ -0,0 +1,68 @@ +--- +layout: post +title: Customize Suggestions ##Platform_Name## Smart TextArea Control | Syncfusion +description: Learn how to customize suggestion display in ##Platform_Name## Smart TextArea of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: Customizaion +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Customize Suggestions in ASP.NET Core Smart TextArea + +The Syncfusion ASP.NET Core Smart TextArea control provides AI-powered autocompletion for context-aware text input, with customizable suggestion display options. This section explains how to configure the appearance and behavior of suggestions to enhance user experience in applications like issue trackers or customer support systems. + +## Configure Suggestion Display + +The `show-suggestion-on-popup` attribute controls how AI-generated suggestions are presented to users in the Smart TextArea control. Suggestions are based on the `user-role` and optional `user-phrases` attributes, which define the context and predefined phrases for autocompletion. + +### Pop-up Suggestions + +Set `show-suggestion-on-popup="true"` to display suggestions in a pop-up window above the text area, ideal for scenarios where users need to select from multiple suggestions without cluttering the input area. + +Add the following code in the `~/Pages/Index.cshtml`: + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +@{ + var presets = new { + userRole = "Maintainer of an open-source project replying to GitHub issues", + userPhrases = new[] { "Thank you for contacting us.", "To investigate, we'll need a repro as a public Git repo.", "Could you please post a screenshot of NEED_INFO?", "This sounds like a usage question. This issue tracker is intended for bugs and feature proposals. Unfortunately, we don't have the capacity to answer general usage questions and would recommend StackOverflow for a faster response.", "We don't accept ZIP files as repros." }, + placeHolder = "Write your response to the GitHub issue..." }; +} + + + +{% endhighlight %} +{% endtabs %} + +![ASP.NET Core Smart TextArea Control Suggestion on popup](images/SmartTextArea-Popup.gif) + +### Inline Suggestions + +Set `show-suggestion-on-popup="false"` (default) to display suggestions inline within the text area, suitable for seamless text entry where users can accept suggestions by continuing to type or pressing a tab key. + +Add the following code in the `~/Pages/Index.cshtml`: + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +@{ + var presets = new { + userRole = "Maintainer of an open-source project replying to GitHub issues", + userPhrases = new[] { "Thank you for contacting us.", "To investigate, we'll need a repro as a public Git repo.", "Could you please post a screenshot of NEED_INFO?", "This sounds like a usage question. This issue tracker is intended for bugs and feature proposals. Unfortunately, we don't have the capacity to answer general usage questions and would recommend StackOverflow for a faster response.", "We don't accept ZIP files as repros." }, + placeHolder = "Write your response to the GitHub issue..." }; +} + + + +{% endhighlight %} +{% endtabs %} + +![ASP.NET Core Smart TextArea Control Suggestion on inline](images/SmartTextArea-Inline.gif) + +## Troubleshooting + +If suggestions do not appear, try the following: +- **AI Configuration Errors**: Verify that the API key, endpoint, and model name are correctly configured in **Program.cs**. Check for typos or invalid credentials. \ No newline at end of file diff --git a/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/deepseek-service.md b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/deepseek-service.md new file mode 100644 index 0000000000..ed2bb4c284 --- /dev/null +++ b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/deepseek-service.md @@ -0,0 +1,206 @@ +--- +layout: post +title: DeepSeek AI in ##Platform_Name## Smart TextArea Control | Syncfusion +description: Learn how to implement a custom AI service using DeepSeek AI with ##Platform_Name## Smart TextArea control of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: DeepSeek AI +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# DeepSeek AI Integration with ASP.NET Core Smart TextArea + +The Syncfusion ASP.NET Core Smart TextArea control provides AI-powered autocompletion for context-aware text input, typically using OpenAI or Azure OpenAI. This guide explains how to integrate the DeepSeek AI service with the Smart TextArea using the `IChatInferenceService` interface, enabling custom AI-driven responses in a ASP.NET Core App. + +## Setting Up DeepSeek + +1. **Obtain a DeepSeek API Key** + Create an account at [DeepSeek Platform](https://platform.deepseek.com), sign in, and navigate to [API Keys](https://platform.deepseek.com/api_keys) to generate an API key. +2. **Review Model Specifications** + Refer to [DeepSeek Models Documentation](https://api-docs.deepseek.com/quick_start/pricing) for details on available models (e.g., `deepseek-chat`). + +## Create a DeepSeek AI Service + +Implement the `IChatInferenceService` interface to connect the Smart TextArea to the DeepSeek service, acting as a bridge for AI-generated responses. + +1. Create a `Services` folder in your project. +2. Add a new file named `DeepSeekAIService.cs` in the `Services` folder. +3. Implement the service as shown below, storing the API key securely in a configuration file or environment variable (e.g., `appsettings.json`). + +```csharp +using System.Net; +using System.Text; +using System.Text.Json; +using Microsoft.Extensions.AI; + +public class DeepSeekAIService +{ + private readonly string _apiKey; + private readonly string _modelName = "deepseek-chat"; // Example model + private readonly string _endpoint = "https://api.deepseek.com/chat/completions"; + private static readonly HttpClient HttpClient = new(new SocketsHttpHandler + { + PooledConnectionLifetime = TimeSpan.FromMinutes(30), + EnableMultipleHttp2Connections = true + }) + { + DefaultRequestVersion = HttpVersion.Version20 // Fallback to HTTP/2 for compatibility + }; + private static readonly JsonSerializerOptions JsonOptions = new() + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; + + public DeepSeekAIService(IConfiguration configuration) + { + _apiKey = configuration["DeepSeek:ApiKey"] ?? throw new ArgumentNullException("DeepSeek API key is missing."); + if (!HttpClient.DefaultRequestHeaders.Contains("Authorization")) + { + HttpClient.DefaultRequestHeaders.Clear(); + HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {_apiKey}"); + } + } + + public async Task CompleteAsync(IList chatMessages) + { + var requestBody = new DeepSeekChatRequest + { + Model = _modelName, + Temperature = 0.7f, // Controls response randomness (0.0 to 1.0) + Messages = chatMessages.Select(m => new DeepSeekMessage + { + Role = m.Role == ChatRole.User ? "user" : "system", // Align with DeepSeek API roles + Content = m.Text + }).ToList() + }; + + var content = new StringContent(JsonSerializer.Serialize(requestBody, JsonOptions), Encoding.UTF8, "application/json"); + + try + { + var response = await HttpClient.PostAsync(_endpoint, content); + response.EnsureSuccessStatusCode(); + var responseString = await response.Content.ReadAsStringAsync(); + var responseObject = JsonSerializer.Deserialize(responseString, JsonOptions); + return responseObject?.Choices?.FirstOrDefault()?.Message?.Content ?? "No response from DeepSeek."; + } + catch (Exception ex) when (ex is HttpRequestException || ex is JsonException) + { + throw new InvalidOperationException("Failed to communicate with DeepSeek API.", ex); + } + } +} +``` + +N> Store the DeepSeek API key in `appsettings.json` (e.g., `{ "DeepSeek": { "ApiKey": "your-api-key" } }`) or as an environment variable to ensure security. + +## Define Request and Response Models + +Define C# classes to match the DeepSeek API’s JSON request and response format. + +1. Create a new file named `DeepSeekModels.cs` in the `Services` folder. +2. Add the following model classes: + +```csharp +public class DeepSeekMessage +{ + public string Role { get; set; } + public string Content { get; set; } +} + +public class DeepSeekChatRequest +{ + public string Model { get; set; } + public float Temperature { get; set; } + public List Messages { get; set; } +} + +public class DeepSeekChatResponse +{ + public List Choices { get; set; } +} + +public class DeepSeekChoice +{ + public DeepSeekMessage Message { get; set; } +} +``` + +## Create a Custom AI Service + +Implement the `IChatInferenceService` interface to connect the Smart TextArea to the DeepSeek service, acting as a bridge for AI-generated responses. + +1. Create a new file named `DeepSeekInferenceService.cs` in the `Services` folder. +2. Add the following implementation: + +```csharp +using Syncfusion.EJ2.AI; +using System.Threading.Tasks; + +public class DeepSeekInferenceService : IChatInferenceService +{ + private readonly DeepSeekAIService _deepSeekService; + + public DeepSeekInferenceService(DeepSeekAIService deepSeekService) + { + _deepSeekService = deepSeekService; + } + + public async Task GenerateResponseAsync(ChatParameters options) + { + return await _deepSeekService.CompleteAsync(options.Messages); + } +} +``` + +## Configure the ASP.NET Core App + +Register the DeepSeek service and `IChatInferenceService` implementation in the dependency injection container. + +Update the **~/Program.cs** file as follows: + +```csharp +using Syncfusion.EJ2; +using Syncfusion.EJ2.AI; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddRazorPages(); +builder.Services.AddSyncfusionSmartComponents(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); + +var app = builder.Build(); +// ... +``` + +## Add ASP.NET Core Smart TextArea Control + +Add the Smart TextArea in the **~/Pages/Index.cshtml** file to test the DeepSeek AI integration. + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +@{ + var presets = new { + userRole = "Maintainer of an open-source project replying to GitHub issues", + userPhrases = new[] { "Thank you for contacting us.", "To investigate, we'll need a repro as a public Git repo.", "Could you please post a screenshot of NEED_INFO?", "This sounds like a usage question. This issue tracker is intended for bugs and feature proposals. Unfortunately, we don't have the capacity to answer general usage questions and would recommend StackOverflow for a faster response.", "We don't accept ZIP files as repros." }, + placeHolder = "Write your response to the GitHub issue..." }; +} + + + +{% endhighlight %} +{% endtabs %} + +Press Ctrl+F5 (Windows) or +F5 (macOS) to run the app. Then, the Syncfusion® ASP.NET Core +Smart TextArea control will be rendered in the default web browser. + +![ASP.NET Core Smart TextArea Control](images/SmartTextArea.gif) + +## Troubleshooting + +If the DeepSeek AI integration does not work, try the following: +- **No Suggestions Displayed**: Verify that the DeepSeek API key and model name are correct in the configuration. Check the `DeepSeekAIService` implementation for errors. +- **HTTP Request Failures**: Ensure a stable internet connection and that the DeepSeek API endpoint (`https://api.deepseek.com/v1/chat/completions`) is accessible. Test with HTTP/2 if compatibility issues arise. +- **Service Registration Errors**: Confirm that `DeepSeekAIService` and `DeepSeekInferenceService` are registered in **Program.cs**. diff --git a/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/features.md b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/features.md new file mode 100644 index 0000000000..2120fa3d33 --- /dev/null +++ b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/features.md @@ -0,0 +1,19 @@ +--- +layout: post +title: Styles and Appearances in ##Platform_Name## Smart TextArea | Syncfusion +description: Checkout and learn here all about Styles and Appearances in ##Platform_Name## Smart TextArea of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: Features +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Inherited Features from TextArea + +The Syncfusion® ASP.NET Core Smart TextArea control fully inherits all the properties, features, and styling options of the Syncfusion® ASP.NET Core TextArea control. This means that you can leverage the existing features of the Syncfusion® ASP.NET Core TextArea while benefiting from the enhanced functionality of the Smart TextArea. + +* [Form Support](https://ej2.syncfusion.com/aspnetcore/documentation/textarea/form-support) +* [Floating Labels](https://ej2.syncfusion.com/aspnetcore/documentation/textarea/floating-label) +* [Events](https://ej2.syncfusion.com/aspnetcore/documentation/textarea/events) +* [Methods](https://ej2.syncfusion.com/aspnetcore/documentation/textarea/methods) +* [Style and Appearance](https://ej2.syncfusion.com/aspnetcore/documentation/textarea/style-appearance) \ No newline at end of file diff --git a/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/gemini-service.md b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/gemini-service.md new file mode 100644 index 0000000000..19984f4ebe --- /dev/null +++ b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/gemini-service.md @@ -0,0 +1,255 @@ +--- +layout: post +title: Gemini AI in ##Platform_Name## Smart TextArea Control | Syncfusion +description: Learn how to implement a custom AI service using Google's Gemini AI with ##Platform_Name## Smart TextArea control of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: Gemini AI +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Gemini AI Integration with ASP.NET Core Smart TextArea + +The Syncfusion ASP.NET Core Smart TextArea control provides AI-powered autocompletion for context-aware text input, typically using OpenAI or Azure OpenAI. This guide explains how to integrate the Google Gemini AI service with the Smart TextArea using the `IChatInferenceService` interface, enabling custom AI-driven responses in a ASP.NET Core Web App. + +## Setting Up Gemini + +1. **Obtain a Gemini API Key** + Visit [Google AI Studio](https://ai.google.dev/gemini-api/docs/api-key), sign in, and generate an API key. +2. **Review Model Specifications** + Refer to [Gemini Models Documentation](https://ai.google.dev/gemini-api/docs/models) for details on available models. + +## Create a Gemini AI Service + +Create a service class to manage interactions with the Gemini API, including authentication, request/response handling, and safety settings for the Smart TextArea. + +1. Create a `Services` folder in your project. +2. Add a new file named `GeminiService.cs` in the `Services` folder. +3. Implement the service as shown below, storing the API key securely in a configuration file or environment variable (e.g., `appsettings.json`). + + +```csharp +using System.Net; +using System.Text; +using System.Text.Json; +using Microsoft.Extensions.AI; + +public class GeminiService +{ + private readonly string _apiKey; + private readonly string _modelName = "gemini-2.0-flash"; // Example model + private readonly string _endpoint = "https://generativelanguage.googleapis.com/v1beta/models/"; + private static readonly HttpClient HttpClient = new(new SocketsHttpHandler + { + PooledConnectionLifetime = TimeSpan.FromMinutes(30), + EnableMultipleHttp2Connections = true + }) + { + DefaultRequestVersion = HttpVersion.Version20 // Fallback to HTTP/2 for compatibility + }; + private static readonly JsonSerializerOptions JsonOptions = new() + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; + + public GeminiService(IConfiguration configuration) + { + _apiKey = configuration["Gemini:ApiKey"] ?? throw new ArgumentNullException("Gemini API key is missing."); + HttpClient.DefaultRequestHeaders.Clear(); + HttpClient.DefaultRequestHeaders.Add("x-goog-api-key", _apiKey); + } + + public async Task CompleteAsync(IList chatMessages) + { + var requestUri = $"{_endpoint}{_modelName}:generateContent"; + var parameters = BuildGeminiChatParameters(chatMessages); + var payload = new StringContent( + JsonSerializer.Serialize(parameters, JsonOptions), + Encoding.UTF8, + "application/json" + ); + + try + { + using var response = await HttpClient.PostAsync(requestUri, payload); + response.EnsureSuccessStatusCode(); + var json = await response.Content.ReadAsStringAsync(); + var result = JsonSerializer.Deserialize(json, JsonOptions); + return result?.Candidates?.FirstOrDefault()?.Content?.Parts?.FirstOrDefault()?.Text + ?? "No response from model."; + } + catch (Exception ex) when (ex is HttpRequestException or JsonException) + { + throw new InvalidOperationException("Gemini API error.", ex); + } + } + + private GeminiChatParameters BuildGeminiChatParameters(IList messages) + { + var contents = messages.Select(m => new ResponseContent( + m.Text, + m.Role == ChatRole.User ? "user" : "model" + )).ToList(); + + return new GeminiChatParameters + { + Contents = contents, + GenerationConfig = new GenerationConfig + { + MaxOutputTokens = 2000, + StopSequences = new List { "END_INSERTION", "NEED_INFO", "END_RESPONSE" } // Configurable stop sequences + }, + SafetySettings = new List + { + new() { Category = "HARM_CATEGORY_HARASSMENT", Threshold = "BLOCK_ONLY_HIGH" }, + new() { Category = "HARM_CATEGORY_HATE_SPEECH", Threshold = "BLOCK_ONLY_HIGH" }, + new() { Category = "HARM_CATEGORY_SEXUALLY_EXPLICIT", Threshold = "BLOCK_ONLY_HIGH" }, + new() { Category = "HARM_CATEGORY_DANGEROUS_CONTENT", Threshold = "BLOCK_ONLY_HIGH" } + } + }; + } +} +``` + +N> Store the Gemini API key in `appsettings.json` (e.g., `{ "Gemini": { "ApiKey": "your-api-key" } }`) or as an environment variable to ensure security. The `SafetySettings` filter harmful content; adjust thresholds based on your application’s needs. + +## Define Request and Response Models + +Define C# classes to match the Gemini API’s JSON request and response format. + +1. Create a new file named `GeminiModels.cs` in the `Services` folder. +2. Add the following model classes: + +```csharp +public class Part +{ + public string Text { get; set; } +} + +public class Content +{ + public Part[] Parts { get; init; } = Array.Empty(); +} + +public class Candidate +{ + public Content Content { get; init; } = new(); +} + +public class GeminiResponseObject +{ + public Candidate[] Candidates { get; init; } = Array.Empty(); +} + +public class ResponseContent +{ + public List Parts { get; init; } + public string Role { get; init; } + + public ResponseContent(string text, string role) + { + Parts = new List { new Part { Text = text } }; + Role = role; + } +} + +public class GenerationConfig +{ + public int Temperature { get; init; } = 0; + public int TopK { get; init; } = 0; + public int TopP { get; init; } = 0; + public int MaxOutputTokens { get; init; } = 2048; + public List StopSequences { get; init; } = new(); +} + +public class SafetySetting +{ + public string Category { get; init; } = string.Empty; + public string Threshold { get; init; } = string.Empty; +} + +public class GeminiChatParameters +{ + public List Contents { get; init; } = new(); + public GenerationConfig GenerationConfig { get; init; } = new(); + public List SafetySettings { get; init; } = new(); +} +``` + +## Create a Custom AI Service + +Implement the `IChatInferenceService` interface to connect the Smart TextArea to the Gemini service, acting as a bridge for AI-generated responses. + +1. Create a new file named `GeminiInferenceService.cs` in the `Services` folder. +2. Add the following implementation: + +```csharp +using Syncfusion.EJ2.AI; +using System.Threading.Tasks; + +public class GeminiInferenceService : IChatInferenceService +{ + private readonly GeminiService _geminiService; + + public GeminiInferenceService(GeminiService geminiService) + { + _geminiService = geminiService; + } + + public async Task GenerateResponseAsync(ChatParameters options) + { + return await _geminiService.CompleteAsync(options.Messages); + } +} +``` + +## Configure the ASP.NET Core App + +Register the Gemini service and `IChatInferenceService` implementation in the dependency injection container. + +Update the **~/Program.cs** file as follows: + +```csharp +using Syncfusion.EJ2; +using Syncfusion.EJ2.AI; + +builder.Services.AddRazorPages(); + +builder.Services.AddSyncfusionSmartComponents(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); + +var app = builder.Build(); +// ... +``` + +## Add ASP.NET Core Smart TextArea Control + +Add the Smart TextArea in the **~/Pages/Index.cshtml** file to test the Gemini AI integration. + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +@{ + var presets = new { + userRole = "Maintainer of an open-source project replying to GitHub issues", + userPhrases = new[] { "Thank you for contacting us.", "To investigate, we'll need a repro as a public Git repo.", "Could you please post a screenshot of NEED_INFO?", "This sounds like a usage question. This issue tracker is intended for bugs and feature proposals. Unfortunately, we don't have the capacity to answer general usage questions and would recommend StackOverflow for a faster response.", "We don't accept ZIP files as repros." }, + placeHolder = "Write your response to the GitHub issue..." }; +} + + + +{% endhighlight %} +{% endtabs %} + +Press Ctrl+F5 (Windows) or +F5 (macOS) to run the app. Then, the Syncfusion® ASP.NET Core +Smart TextArea control will be rendered in the default web browser. + +![ASP.NET Core Smart TextArea Control](images/SmartTextArea.gif) + +## Troubleshooting + +If the Gemini AI integration does not work, try the following: +- **No Suggestions Displayed**: Verify that the Gemini API key and model name are correct in the configuration. Check the `GeminiService` implementation for errors. +- **HTTP Request Failures**: Ensure a stable internet connection and that the Gemini API endpoint (`https://generativelanguage.googleapis.com/v1beta/models/`) is accessible. Test with HTTP/2 if compatibility issues arise. +- **Service Registration Errors**: Confirm that `GeminiService` and `GeminiInferenceService` are registered in **Program.cs**. diff --git a/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/getting-started.md b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/getting-started.md new file mode 100644 index 0000000000..227a08d68d --- /dev/null +++ b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/getting-started.md @@ -0,0 +1,237 @@ +--- +layout: post +title: Getting Started with ##Platform_Name## Smart TextArea Control | Syncfusion +description: Checkout and learn about getting started with ##Platform_Name## Smart TextArea of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: Getting Started +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Getting Started with ASP.NET Core Smart TextArea Control + +This section briefly explains about how to include `ASP.NET Core Smart TextArea` control in your ASP.NET Core application using Visual Studio. + +## Prerequisites + +[System requirements for ASP.NET Core controls](https://ej2.syncfusion.com/aspnetcore/documentation/system-requirements) + +## Create ASP.NET Core web application with Razor pages + +* [Create a Project using Microsoft Templates](https://learn.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/razor-pages-start?view=aspnetcore-8.0&tabs=visual-studio#create-a-razor-pages-web-app) + +* [Create a Project using Syncfusion® ASP.NET Core Extension](https://ej2.syncfusion.com/aspnetcore/documentation/visual-studio-integration/create-project) + +## Install ASP.NET Core package in the application + +To add `ASP.NET Core` controls in the application, open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), search for [Syncfusion.EJ2.AspNet.Core](https://www.nuget.org/packages/Syncfusion.EJ2.AspNet.Core/) and then install it. Alternatively, you can utilize the following package manager command to achieve the same. + +{% tabs %} +{% highlight C# tabtitle="Package Manager" %} + +Install-Package Syncfusion.EJ2.AspNet.Core -Version {{ site.releaseversion }} + +{% endhighlight %} +{% endtabs %} + +N> Syncfusion® ASP.NET Core controls are available in [nuget.org.](https://www.nuget.org/packages?q=syncfusion.EJ2) Refer to [NuGet packages topic](https://ej2.syncfusion.com/aspnetcore/documentation/nuget-packages) to learn more about installing NuGet packages in various OS environments. The Syncfusion.EJ2.AspNet.Core NuGet package has dependencies, [Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json/) for JSON serialization and [Syncfusion.Licensing](https://www.nuget.org/packages/Syncfusion.Licensing/) for validating Syncfusion® license key. + +## Add Syncfusion® ASP.NET Core Tag Helper +Open `~/Pages/_ViewImports.cshtml` file and import the `Syncfusion.EJ2` TagHelper. + +{% tabs %} +{% highlight C# tabtitle="~/_ViewImports.cshtml" %} + +@addTagHelper *, Syncfusion.EJ2 + +{% endhighlight %} +{% endtabs %} + +## Add stylesheet and script resources + +Here, the theme and script is referred using CDN inside the `` of `~/Pages/Shared/_Layout.cshtml` file as follows, + +{% tabs %} +{% highlight cshtml tabtitle="~/_Layout.cshtml" %} + + + ... + + + + + + +{% endhighlight %} +{% endtabs %} + +N> Checkout the [Themes topic](https://ej2.syncfusion.com/aspnetcore/documentation/appearance/theme) to learn different ways ([CDN](https://ej2.syncfusion.com/aspnetcore/documentation/common/adding-script-references#cdn-reference), [NPM package](https://ej2.syncfusion.com/aspnetcore/documentation/common/adding-script-references#node-package-manager-npm), and [CRG](https://ej2.syncfusion.com/aspnetcore/documentation/common/custom-resource-generator)) to refer styles in ASP.NET Core application, and to have the expected appearance for Syncfusion® ASP.NET Core controls. + +N> Checkout the [Adding Script Reference](https://ej2.syncfusion.com/aspnetcore/documentation/common/adding-script-references) topic to learn different approaches for adding script references in your ASP.NET Core application. + +## Register Syncfusion® Script Manager + +Also, register the script manager `` at the end of `` in the ASP.NET Core application as follows. + +{% tabs %} +{% highlight cshtml tabtitle="~/_Layout.cshtml" %} + + + ... + + + + +{% endhighlight %} +{% endtabs %} + +## Configure AI Service + +To enable AI-powered autocompletion in the Smart TextArea, configure an AI model (OpenAI, Azure OpenAI, or Ollama) in your application. Install the required NuGet packages and update the **~/Program.cs** file as described below. + +### Install AI Service NuGet Packages + +Install the following NuGet packages based on your chosen AI provider: + +{% tabs %} +{% highlight c# tabtitle="Package Manager" %} + +Install-Package Microsoft.Extensions.AI +Install-Package Microsoft.Extensions.AI.OpenAI +@* For Azure OpenAI only *@ +Install-Package Azure.AI.OpenAI +@* For Ollama only *@ +Install-Package OllamaSharp + +{% endhighlight %} +{% endtabs %} + +### OpenAI Configuration + +For OpenAI, obtain an API key from [OpenAI](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key) and specify the desired model (e.g., `gpt-3.5-turbo`, `gpt-4`). Store the API key securely in a configuration file or environment variable. + +Add the following to the **~/Program.cs** file: + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +using Microsoft.Extensions.AI; +using OpenAI; +using Syncfusion.EJ2; + + +builder.Services.AddRazorPages(); + +string openAIApiKey = "API-KEY"; +string openAIModel = "OPENAI_MODEL"; +OpenAIClient openAIClient = new OpenAIClient(openAIApiKey); +IChatClient openAIChatClient = openAIClient.GetChatClient(openAIModel).AsIChatClient(); +builder.Services.AddChatClient(openAIChatClient); + +builder.Services.AddSyncfusionSmartComponents() + .InjectOpenAIInference(); + +var app = builder.Build(); +.... + +{% endhighlight %} +{% endtabs %} + +### Azure OpenAI Configuration + +For Azure OpenAI, deploy a resource and model as described in [Azure OpenAI documentation](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource). Obtain the API key, endpoint, and model name from your Azure portal. + +Add the following to the **~/Program.cs** file: + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +using Syncfusion.EJ2; +using Microsoft.Extensions.AI; +using Azure.AI.OpenAI; +using System.ClientModel; + +builder.Services.AddRazorPages(); + +string azureOpenAIKey = "AZURE_OPENAI_KEY"; +string azureOpenAIEndpoint = "AZURE_OPENAI_ENDPOINT"; +string azureOpenAIModel = "AZURE_OPENAI_MODEL"; +AzureOpenAIClient azureOpenAIClient = new AzureOpenAIClient( + new Uri(azureOpenAIEndpoint), + new ApiKeyCredential(azureOpenAIKey) +); +IChatClient azureOpenAIChatClient = azureOpenAIClient.GetChatClient(azureOpenAIModel).AsIChatClient(); +builder.Services.AddChatClient(azureOpenAIChatClient); + +builder.Services.AddSyncfusionSmartComponents() + .InjectOpenAIInference(); + +var app = builder.Build(); +.... + +{% endhighlight %} +{% endtabs %} + +### Ollama Configuration + +To use Ollama for self-hosted models: + +1. Download and install Ollama from [Ollama's official website](https://ollama.com). +2. Install a model from the [Ollama Library](https://ollama.com/library) (e.g., `llama2:13b`, `mistral:7b`). +3. Configure the endpoint URL (e.g., `http://localhost:11434`) and model name. + +Add the following to the **~/Program.cs** file: + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +using Syncfusion.EJ2; +using Microsoft.Extensions.AI; +using OllamaSharp; + +builder.Services.AddRazorPages(); + +string ModelName = "MODEL_NAME"; +IChatClient chatClient = new OllamaApiClient("http://localhost:11434", ModelName); +builder.Services.AddChatClient(chatClient); + +builder.Services.AddSyncfusionSmartComponents() + .InjectOpenAIInference(); + +var app = builder.Build(); +.... + +{% endhighlight %} +{% endtabs %} + +## Add ASP.NET Core Smart TextArea Control + +The **user-role** attribute (required) defines the context for AI autocompletion based on the user's role. The **user-phrases** attribute (optional) provides predefined expressions aligned with the application's tone and common phrases. + +Now, add the Syncfusion® ASP.NET Core Smart TextArea tag helper in `~/Pages/Index.cshtml` page. + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +@{ + var presets = new { + userRole = "Maintainer of an open-source project replying to GitHub issues", + userPhrases = new[] { "Thank you for contacting us.", "To investigate, we'll need a repro as a public Git repo.", "Could you please post a screenshot of NEED_INFO?", "This sounds like a usage question. This issue tracker is intended for bugs and feature proposals. Unfortunately, we don't have the capacity to answer general usage questions and would recommend StackOverflow for a faster response.", "We don't accept ZIP files as repros." }, + placeHolder = "Write your response to the GitHub issue..." }; +} + + + +{% endhighlight %} +{% endtabs %} + +Press Ctrl+F5 (Windows) or +F5 (macOS) to run the app. Then, the Syncfusion® ASP.NET Core +Smart TextArea control will be rendered in the default web browser. + +![ASP.NET Core Smart TextArea Control](images/SmartTextArea.gif) + +## Troubleshooting + +If you encounter issues, try the following: +- **NuGet Installation Errors**: Ensure a stable internet connection and set the NuGet package source to `https://www.nuget.org`. Run `dotnet restore` again. +- **AI Service Configuration Errors**: Verify the API key, endpoint, and model name in **Program.cs**. Check for typos or incorrect values. diff --git a/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/groq-service.md b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/groq-service.md new file mode 100644 index 0000000000..8229b14c71 --- /dev/null +++ b/ej2-asp-core-mvc/smart-textarea/EJ2_ASP.NETCORE/groq-service.md @@ -0,0 +1,207 @@ +--- +layout: post +title: Groq AI in ##Platform_Name## Smart TextArea Control | Syncfusion +description: Learn how to implement a custom AI service using Groq AI with ##Platform_Name## Smart TextArea control of Syncfusion Essential JS 2 and more details. +platform: ej2-asp-core-mvc +control: Groq AI +publishingplatform: ##Platform_Name## +documentation: ug +--- + +# Groq AI Integration with ASP.NET Core Smart TextArea + +The Syncfusion ASP.NET Core Smart TextArea control provides AI-powered autocompletion for context-aware text input, typically using OpenAI or Azure OpenAI. This guide explains how to integrate the Groq AI service with the Smart TextArea using the `IChatInferenceService` interface, enabling custom AI-driven responses in a ASP.NET Core App. + +## Setting Up Groq + +1. **Create a Groq Account** + Visit [Groq Cloud Console](https://console.groq.com), sign up or sign in, and complete the verification process. +2. **Obtain an API Key** + Navigate to [API Keys](https://console.groq.com/keys) in the Groq Console and click "Create API Key." +3. **Review Model Specifications** + Refer to [Groq Models Documentation](https://console.groq.com/docs/models) for details on available models (e.g., `llama3-8b-8192`). + +## Create a Groq AI Service + +Create a service class to manage interactions with the Groq API, including authentication and response processing for the Smart TextArea. + +1. Create a `Services` folder in your project. +2. Add a new file named `GroqService.cs` in the `Services` folder. +3. Implement the service as shown below, storing the API key securely in a configuration file or environment variable (e.g., `appsettings.json` or environment variables). + +```csharp +using Microsoft.Extensions.AI; +using System.Net; +using System.Text; +using System.Text.Json; + +public class GroqService +{ + private readonly string _apiKey; + private readonly string _modelName = "llama-3.3-70b-versatile"; // Example model + private readonly string _endpoint = "https://api.groq.com/openai/v1/chat/completions"; + private static readonly HttpClient HttpClient = new(new SocketsHttpHandler + { + PooledConnectionLifetime = TimeSpan.FromMinutes(30), + EnableMultipleHttp2Connections = true + }) + { + DefaultRequestVersion = HttpVersion.Version20 // Fallback to HTTP/2 for broader compatibility + }; + private static readonly JsonSerializerOptions JsonOptions = new() + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; + + public GroqService(IConfiguration configuration) + { + _apiKey = configuration["Groq:ApiKey"] ?? throw new ArgumentNullException("Groq API key is missing."); + if (!HttpClient.DefaultRequestHeaders.Contains("Authorization")) + { + HttpClient.DefaultRequestHeaders.Clear(); + HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {_apiKey}"); + } + } + + public async Task CompleteAsync(IList chatMessages) + { + var requestPayload = new GroqChatParameters + { + Model = _modelName, + Messages = chatMessages.Select(m => new Message + { + Role = m.Role == ChatRole.User ? "user" : "assistant", + Content = m.Text + }).ToList(), + Stop = new List { "END_INSERTION", "NEED_INFO", "END_RESPONSE" } // Configurable stop sequences + }; + + var content = new StringContent(JsonSerializer.Serialize(requestPayload, JsonOptions), Encoding.UTF8, "application/json"); + + try + { + var response = await HttpClient.PostAsync(_endpoint, content); + response.EnsureSuccessStatusCode(); + var responseString = await response.Content.ReadAsStringAsync(); + var responseObject = JsonSerializer.Deserialize(responseString, JsonOptions); + return responseObject?.Choices?.FirstOrDefault()?.Message?.Content ?? "No response from model."; + } + catch (Exception ex) when (ex is HttpRequestException || ex is JsonException) + { + throw new InvalidOperationException("Failed to communicate with Groq API.", ex); + } + } +} +``` + +N> Store the Groq API key in `appsettings.json` (e.g., `{ "Groq": { "ApiKey": "your-api-key" } }`) or as an environment variable to ensure security. + +## Define Request and Response Models + +Define C# classes to match the Groq API’s request and response format. + +1. Create a new file named `GroqModels.cs` in the `Services` folder. +2. Add the following model classes: + +```csharp +public class Choice +{ + public Message Message { get; set; } +} + +public class Message +{ + public string Role { get; set; } + public string Content { get; set; } +} + +public class GroqChatParameters +{ + public string Model { get; set; } + public List Messages { get; set; } + public List Stop { get; set; } +} + +public class GroqResponseObject +{ + public string Model { get; set; } + public List Choices { get; set; } +} +``` + +## Create a Custom AI Service + +Implement the `IChatInferenceService` interface to connect the Smart TextArea to the Groq service. + +1. Create a new file named `GroqInferenceService.cs` in the `Services` folder. +2. Add the following implementation: + +```csharp +using Syncfusion.EJ2.AI; +using System.Threading.Tasks; + +public class GroqInferenceService : IChatInferenceService +{ + private readonly GroqService _groqService; + + public GroqInferenceService(GroqService groqService) + { + _groqService = groqService; + } + + public async Task GenerateResponseAsync(ChatParameters options) + { + return await _groqService.CompleteAsync(options.Messages); + } +} +``` + +## Configure the ASP.NET Core App + +Register the Groq service and `IChatInferenceService` implementation in the dependency injection container. + +Update the **~/Program.cs** file as follows: + +```csharp +using Syncfusion.EJ2; +using Syncfusion.EJ2.AI; + +builder.Services.AddRazorPages(); +builder.Services.AddSyncfusionSmartComponents(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); + +var app = builder.Build(); +// ... +``` + +## Add ASP.NET Core Smart TextArea Control + +Add the Smart TextArea in the **~/Pages/Index.cshtml** file to test the Groq AI integration. + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} + +@{ + var presets = new { + userRole = "Maintainer of an open-source project replying to GitHub issues", + userPhrases = new[] { "Thank you for contacting us.", "To investigate, we'll need a repro as a public Git repo.", "Could you please post a screenshot of NEED_INFO?", "This sounds like a usage question. This issue tracker is intended for bugs and feature proposals. Unfortunately, we don't have the capacity to answer general usage questions and would recommend StackOverflow for a faster response.", "We don't accept ZIP files as repros." }, + placeHolder = "Write your response to the GitHub issue..." }; +} + + + +{% endhighlight %} +{% endtabs %} + +Press Ctrl+F5 (Windows) or +F5 (macOS) to run the app. Then, the Syncfusion® ASP.NET Core +Smart TextArea control will be rendered in the default web browser. + +![ASP.NET Core Smart TextArea Control](images/SmartTextArea.gif) + +## Troubleshooting + +If the Groq AI integration does not work, try the following: +- **No Suggestions Displayed**: Verify that the Groq API key and model name are correct in the configuration. Check the `GroqService` implementation for errors. +- **HTTP Request Failures**: Ensure a stable internet connection and that the Groq API endpoint (`https://api.groq.com/openai/v1/chat/completions`) is accessible. Test with HTTP/2 instead of HTTP/3 if compatibility issues arise. +- **Service Registration Errors**: Confirm that `GroqService` and `GroqInferenceService` are registered in **Program.cs**. diff --git a/ej2-asp-core-mvc/smart-textarea/images/SmartTextArea-Inline.gif b/ej2-asp-core-mvc/smart-textarea/images/SmartTextArea-Inline.gif new file mode 100644 index 0000000000..8b1ff768fe Binary files /dev/null and b/ej2-asp-core-mvc/smart-textarea/images/SmartTextArea-Inline.gif differ diff --git a/ej2-asp-core-mvc/smart-textarea/images/SmartTextArea-Popup.gif b/ej2-asp-core-mvc/smart-textarea/images/SmartTextArea-Popup.gif new file mode 100644 index 0000000000..efcbf7fbeb Binary files /dev/null and b/ej2-asp-core-mvc/smart-textarea/images/SmartTextArea-Popup.gif differ diff --git a/ej2-asp-core-mvc/smart-textarea/images/SmartTextArea.gif b/ej2-asp-core-mvc/smart-textarea/images/SmartTextArea.gif new file mode 100644 index 0000000000..8b1ff768fe Binary files /dev/null and b/ej2-asp-core-mvc/smart-textarea/images/SmartTextArea.gif differ diff --git a/ej2-asp-core-toc.html b/ej2-asp-core-toc.html index 5bfd04cf54..2ee1cefdb6 100644 --- a/ej2-asp-core-toc.html +++ b/ej2-asp-core-toc.html @@ -606,6 +606,7 @@
  • Header
  • Footer
  • Templates
  • +
  • Speech to Text
  • Appearance
  • Globalization
  • Accessibility
  • @@ -2387,7 +2388,38 @@ - +
  • Smart Paste Button + +
  • +
  • Smart TextArea + +
  • Smith Chart -
  • + +
  • 31.2.9 Service Pack Release
  • 31.2.2 Service Pack Release
  • 31.1.17 Main Release
  • diff --git a/ej2-asp-mvc-toc.html b/ej2-asp-mvc-toc.html index bd44090aad..06616ead4e 100644 --- a/ej2-asp-mvc-toc.html +++ b/ej2-asp-mvc-toc.html @@ -166,7 +166,7 @@ Google Gemini
  • - Azure Open AI + Azure OpenAI
  • @@ -174,6 +174,16 @@
  • Custom views
  • File attachments
  • Templates
  • +
  • Speech + +
  • Appearance
  • Accessibility
  • Methods
  • @@ -582,10 +592,10 @@
  • Chat Bot Integrations
  • @@ -596,6 +606,7 @@
  • Header
  • Footer
  • Templates
  • +
  • Speech to Text
  • Appearance
  • Globalization
  • Accessibility
  • @@ -2964,7 +2975,8 @@
  • 31.1.20
  • 31.1.18
  • - + +
  • 31.2.9 Service Pack Release
  • 31.2.2 Service Pack Release
  • 31.1.17 Main Release