npm i ai @ai-sdk/azure
import { generateText } from "ai" import { createAzure } from '@ai-sdk/azure'; //Warning - Do not expose your API keys in the client-side code. This is just for demonstration purposes. const azure = createAzure({ resourceName: 'RESOURCE_NAME', apiKey: 'API_KEY', }); // Update the model here. const aiModel = azure('MODEL_NAME'); export async function getChatAIRequest(options: any) { try { const result = await generateText({ model: aiModel, messages: options.messages, topP: options.topP, temperature: options.temperature, maxTokens: options.maxTokens, frequencyPenalty: options.frequencyPenalty, presencePenalty: options.presencePenalty, stopSequences: options.stopSequences }); return result.text; } catch (err) { console.error("Error occurred:", err); return null; } }
npm i @syncfusion/ej2-react-inputs @syncfusion/ej2-react-dropdowns
import { SmartTextAreaComponent, ChatParameters } from "@syncfusion/ej2-react-inputs"; import { DropDownListComponent } from "@syncfusion/ej2-react-dropdowns"; import { getAzureChatAIRequest } from "./ai-model"; function App() { return ( <div className="control-pane"> <div className="control-section"> <div className="content-wrapper smart-text"> <div className="example-label">Select a role</div> <DropDownListComponent type="text" id="user-role" dataSource={rolesData} width="90%" placeholder="Select a role" value="Maintainer of an open-source project replying to GitHub issues" popupHeight="200px" change={onChange} /> <br /> <div className="smart-component"> <SmartTextAreaComponent id="smart-textarea" ref={(textarea) => { textareaObj = textarea as SmartTextAreaComponent; }} placeholder={"Enter your queries here"} floatLabelType={"Auto"} rows={5} userRole={"Employee communicating with internal team"} UserPhrases={phrasesData} aiSuggestionHandler={serverAIRequest} showSuggestionOnPopup="Disable" ></SmartTextAreaComponent> </div> </div> </div> </div> ); } export default App;
let textareaObj: SmartTextAreaComponent; const phrasesData: string[] = [ "Please find the attached report.", "Let's schedule a meeting to discuss this further.", "Can you provide an update on this task?", "I appreciate your prompt response.", "Let's collaborate on this project to ensure timely delivery.", ]; const rolesData: string[] = [ "Maintainer of an open-source project replying to GitHub issues", "Employee communicating with internal team", "Customer support representative responding to customer queries", "Sales representative responding to client inquiries", ]; let presets: any = [ { userRole: "Maintainer of an open-source project replying to GitHub issues", userPhrases: [ "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.", ], }, { userRole: "Customer support representative responding to customer queries", userPhrases: [ "Thank you for reaching out to us.", "Can you please provide your order number?", "We apologize for the inconvenience.", "Our team is looking into this issue and will get back to you shortly.", "For urgent matters, please call our support line.", ], }, { userRole: "Employee communicating with internal team", userPhrases: [ "Please find the attached report.", "Let's schedule a meeting to discuss this further.", "Can you provide an update on this task?", "I appreciate your prompt response.", "Let's collaborate on this project to ensure timely delivery.", ], }, { userRole: "Sales representative responding to client inquiries", userPhrases: [ "Thank you for your interest in our product.", "Can I schedule a demo for you?", "Please find the pricing details attached.", "Our team is excited to work with you.", "Let me know if you have any further questions.", ], }, ]; function onChange(args: any) { let selectedRole: string = args.value; let selectedPreset: any = presets.find( (preset: any) => preset.userRole === selectedRole ); textareaObj.userRole = selectedRole; textareaObj.UserPhrases = selectedPreset.userPhrases; }
const serverAIRequest = async (settings: ChatParameters) => { let output = ""; try { const response = (await getAzureChatAIRequest(settings)) as string; output = response; } catch (error) { console.error("Error:", error); } return output; };
Explore the endless possibilities with Syncfusion’s outstanding React UI components.
Meet the Author
Mydeen S NMydeen S. N. is a product manager of the web platform team at Syncfusion. He is passionate about front-end JavaScript and NodeJS technologies and has been active in web development since 2014.