Add an AI assistant to your website

Updated at:

On Alibaba Cloud, you can quickly add a highly customizable AI assistant to your website. This assistant can respond to customer inquiries 24/7, improving user experience and strengthening your business's competitive edge.

Solution overview

c8ac5d01471a4cda8935c678d9462613

Adding an AI assistant to your website involves just four steps:

  1. Create an LLM Q&A application: First, create a Large Language Model (LLM) application using Alibaba Cloud Model Studio and obtain the credentials needed to call the application's API.
  2. Create an AI assistant: Next, create and configure an AI assistant using AppFlow.
  3. Integrate the AI assistant: Then, modify a few lines of code to integrate the AI assistant into your website.
  4. Add private knowledge: Finally, add private knowledge to enable the AI assistant to accurately answer specialized questions.
image

1. Create an LLM Q&A application

First, create a Model Studio application to obtain the LLM inference API service.

The AppFlow AI assistant feature itself is free of charge. However, the underlying resources used by this feature may incur charges, including Model Studio model calls, knowledge base instance runtime, and Function Compute (FC) resources if you deploy the sample website with FC. Each charge follows the billing rules of the corresponding cloud service. See Model pricing, Knowledge base billing, and Function Compute billing overview. The eligible models, eligibility requirements, and validity period of the free quota for new users are subject to the applicable rules. The quota does not mean that all resources used in this tutorial are free.

1.1 Create the application

  1. Open the agent creation form, enter an Application Name, keep the default settings, and click Create Now. The application configuration page opens automatically after creation.

    The new agent application (Agent 2.0) is created by default. The steps in this tutorial have been verified in the new console. To create a legacy application, click Legacy Agent Creation Entry at the bottom of the dialog box.

  2. In the Planning area of the application configuration page, select a model. The default is Smart Mode (AUTO), where the platform automatically balances cost and effectiveness, which is recommended for beginners. You can also click the model selector to specify a model (such as Qwen-Plus), or click More Models to select other models. Keep the default settings for other parameters.

    You can enter a prompt in the prompt input box in the Planning area to set a role and guide the model in responding to customer inquiries.

Your name is Xiaozhu. You can help users with questions about product selection and usage.
  1. In the dialog box on the right side of the page, ask questions to test the model's performance. However, it cannot yet accurately answer questions about your company's products. Click Publish in the upper-right corner, confirm the version information in the Publish Version window, and click Confirm Publish. We will address this issue in a later step.

1.2 Get the application ID and API key for API calls

To call the LLM application's API later, you need to obtain the Model Studio API key and the application ID.

  1. On the Application Management page, view and copy the application ID on the application card. Save the application ID locally for later configuration.
  2. Go to the API Key page and click Create API Key. In the dialog box, keep the default settings and click OK. After the API key is created, copy it immediately and save it locally. The complete key is displayed only once upon creation. For more information, see Obtain and configure an API key.

2. Create an AI assistant

AppFlow connects web pages to model service platforms without requiring code.

2.1 Create the AI assistant

  1. Log on to the AppFlow console.
  2. In the navigation pane on the left, choose Model Service > AI Assistant.
  3. On the AI Assistant page, click Create AI Assistant to configure basic information.
  4. On the Create AI Assistant page, select Agent for AI Assistant Type, and customize the AI assistant's icon, AI Assistant Name, and AI Assistant Description. After you complete the configuration, click Submit to go to the AI assistant details page.

2.2 Import and configure your model

  1. Click the Import Model button. Select Alibaba Cloud Model Studio as the model service platform and click OK. You can also choose other platforms as your model service provider based on your business needs.
  2. In the Select Connection Credential step of the configuration wizard, click the drop-down box and select Add New Credential. After you create the credential, you can reuse it when selecting connection credentials in the future.
  3. Enter a credential name and the API key you obtained earlier. This allows AppFlow to perform credential authentication.
  4. Click Next Step to go to the Parameter Configuration step. Enter the Application Id you obtained earlier, keep Public Cloud China Site for Site Selection, and enter the Model Studio workspace ID for Workspace ID (AgentKey). You can view the workspace ID on the Workspace Management page of the Model Studio console. Click Save to associate the Model Studio application you created with the AI assistant.

2.3 Create a web page integration for the AI assistant

  1. On the AI Assistant Details page, click Integration and select Web Page Integration to create or configure the page integration.
  2. On the web page integration configuration page, click the Create Integration button. Enter an Integration Name and click OK to go to the details configuration page.
  3. Using the visualization interface on the right, you can customize the integration's appearance, such as the font color, background color, embedded interface size, profile picture icon, and preset questions.
  4. After you finish the configuration, click the Submit button to save.

3. Add the AI assistant to your website

Adding the AI assistant to your website is simple. You just need to insert a few lines of code into your website's HTML file.

3.1 Set up a sample website

Before you make the AI assistant answer questions accurately, you can first try to quickly integrate it into a website.

To quickly see the effect of embedding the AI assistant, you can use the simple HTML template that we provide. Download the template and open it in a browser for a local preview. This is a good way to simulate a corporate website or other pages. The procedure is as follows:

  1. Download the HTML file: index.html.
  2. Open the HTML file in a browser or double-click the file to see the sample website without the embedded AI assistant.

If you want to build a more complete sample website that includes a temporary endpoint, you can use the one-click deployment template based on Function Compute (FC). This lets you experience an accessible website with AI assistant capabilities without manually configuring the environment. The procedure is as follows:

  1. Click here to open the Function Compute application template we provide.

    If this is your first time using Function Compute, you must activate the service as instructed on the page.

  2. Select Deploy Directly.

  3. Keep the default settings for the other form items. In the lower-left corner of the page, click Create and Deploy Default Environment and wait for the project deployment to complete (estimated time: 1 minute).

  4. After the application is deployed, you can find the endpoint for the sample website in the Environment Context section of the application details. Click it to view the site and confirm that the deployment was successful.

NoteIf this is your first time using Alibaba Cloud Function Compute, you must grant the required permissions to the "AliyunFCServerlessDevsRole" role as instructed on the page.

3.2 Add the AI assistant code

The sample code includes commented-out code and instructions for integrating the AI assistant. You must find your unique floating widget deployment script and paste it below the comment. The procedure is as follows:

  1. Return to the AI Assistant Web Integration page. At the bottom, find Logon Configuration, click Anonymity, and copy the Floating Widget Deployment script.

  2. Use a code editor to paste the floating widget deployment script below the comment in the HTML file.

    If you used the one-click deployment with FC to set up the sample website, you can go to the bottom of the Environment Details page and click the function name to enter the function details. In the code editor, switch to index.html and paste the floating widget deployment script in the specified location, following the comments in the file.

    You can also follow the comment instructions to enable or disable the drag-and-drop feature for the AI assistant icon.

  3. Reopen the HTML file or click the Deploy Code button in the code view and access the endpoint again. You will see the web page with the AI assistant.

3.3 Verify the AI assistant on the website

Now, you can revisit the sample website page to see the latest result. You will find the AI assistant icon image in the lower-right corner of the website. Click it to open the AI assistant.

The website provided in this solution is a sample. The content is for styling purposes only. The result is shown in the following figure.

image

FAQ

What do I do if a request error occurs after I embed the AI assistant?

If a request error occurs during a conversation after you embed the AI assistant in your website, troubleshoot the issue as follows:

  1. Check whether the API key is valid: On the AI assistant details page in the AppFlow console, click the edit icon next to the imported model. In the Select Connection Credential step, view the API key. Go to the API Key page in the Model Studio console to verify its status.
  2. Confirm that the agent and the API key belong to the same workspace: In the Parameter Configuration step, check the Workspace ID (AgentKey). If the agent and the API key belong to different workspaces, authentication fails.
  3. Verify that the application ID is correct: In the Parameter Configuration step, check the value of the Application Id field. Go to the Application Management page in Model Studio and compare the value with the one on the application card.

After you confirm that all three items are configured correctly, the AI assistant can converse normally.

4. Add private knowledge to the AI assistant

By following the previous steps, you now have an AI assistant that can converse with customers. However, to make the AI assistant answer product-related questions as accurately and professionally as a company employee, you need to configure a knowledge base for the LLM application.

Suppose you work for a company that sells smartphones. Your website contains a lot of information related to smartphones, such as support for Dual SIM Dual Standby, screen details, battery capacity, and memory. For a detailed configuration list of different models, see Alibaba Cloud Model Studio Series Smartphone Product Introduction.docx.

4.1 Configure the knowledge base

Next, you can configure the LLM to reference this document when answering customer questions to produce more accurate answers and suggestions.

  1. Create the knowledge base: Open Knowledge, and click Create. Enter the Name and Description, set the knowledge base type to Document Search, set the use case to Basic Document Q&A, and click Next.

  2. Upload the file: Select Upload File as the data source, follow the on-screen instructions to upload the fictional Alibaba Cloud Model Studio series smartphone product introduction document, keep the default Index Settings, and click Create Knowledge Base. The system automatically completes parsing, chunking, vectorization, and index building. The knowledge base can be used for retrieval after its status changes to Ready.

    Depending on the size of the document you upload, Alibaba Cloud Model Studio needs some time to parse it. This process usually takes 1 to 6 minutes. Please wait patiently.

  3. Create and publish a knowledge retrieval service: The new agent application uses knowledge bases by associating a knowledge retrieval service. In the left-side navigation pane, choose Knowledge Service > Knowledge Retrieval to go to the Knowledge Retrieval page, and click Create. Enter a Service Name and click Confirm. On the configuration page, click + Add to bind the knowledge base you just created, and then click Publish in the upper-right corner. The retrieval service can be associated with an application only after it is published.

  4. Reference knowledge: Go to the Application Management page, find the application you created earlier, and click Configure to go to the application configuration page. In the Retrieval Strategy area under Knowledge Base, click Configure Now. In the Configure Retrieval Service panel, select the published retrieval service and click Link. After you test and verify the results in the dialog box on the right, click Publish in the upper-right corner and then click Confirm Publish.

4.2 Check the results

With reference knowledge, the AI assistant can now accurately answer questions about your company's products.

image

Summary

By following this tutorial, you have built an LLM retrieval-augmented generation (RAG) application and deployed it to your website to handle customer inquiries. Actual charges depend on the models and underlying resources used. See the billing explanation earlier in this tutorial.

Application evaluation

Before the AI assistant goes live, have business personnel perform a manual evaluation to ensure that the LLM application's responses meet expectations. If the responses do not meet expectations, you can improve them by optimizing prompts, enhancing private knowledge, or adjusting the document chunking strategy.

Continuous improvement

LLM course

Improving and optimizing the system is an ongoing process. You can study for and pass the Alibaba Cloud LLM ACA Certification. The free courses that accompany this certification can help you better understand the capabilities and application scenarios of LLMs, and how to optimize their performance.