ai small program build, how to quickly develop an AI weibo small program

In this AI era, combined with AI to make new products or based on your first business to join the AI capabilities, this is where the trend is, so how to access the AI capabilities faster? Next to share with you the integration method of cloud development AI+.

move

Log in to the WeChat Cloud development backend
https://tcb.cloud.tencent.com/cloud-admin?_tcbProviderId=mp

ai small program build, how to quickly develop an AI weibo small program

Then find the AI+ menu

ai small program build, how to quickly develop an AI weibo small program

There are two pieces in total:

1.AI Big Model: basic AI dialog capability suitable for quick access to big models

2. Customized AI capabilities: AI intelligences applicable to specific businesses are built to support the knowledge base

Access to AI Big Models

Let's start our experience with the AI Big Model by going to the AI Big Model module

ai small program build, how to quickly develop an AI weibo small program

Support access to a number of large domestic models, just fill in the Key can be, each large model service background access to the way you can go to see the documentation of each.

The big model I use here is Wisdom Spectrum, after inputting the key and clicking save in the upper right corner, then the relevant model on the left will have an "enabled" status, and it is configured at this time.

I'll take it from here.Mini ProgramsSDK as an example:

Step 1: Install the npm package first

Execute the command install command in the directory where the applet package.json is located (usually the miniprogram directory):

npm i @cloudbase/js-sdk@2.8.3-beta.0

Step 2: Initialize the ai object

const env = "Fill in your environment ID";
registerAuth(cloudbase);
registerAi(cloudbase);
const app = cloudbase.init({ env });
const auth = app.auth({ persistence: "local" }); await auth.signInWith(cloudbase); registerAi(cloudbase); registerAi(cloudbase)
await auth.signInWithOpenId(); // or use another login method
const ai = await app.ai(); // Next you can call ai.
// Next, you can call the methods provided by the ai module to create the model and so on.

Then you'll see the console report an error

ai small program build, how to quickly develop an AI weibo small program

Because the SDK has a request for the domain name need to be configured in the background of the small program can be or can be in the local settings to check the non-check.

ai small program build, how to quickly develop an AI weibo small program

Note: Check the box does not check the purpose is to be able to experience the use, if you want to publish online or to configure the domain name configuration in the background

Step 3: Use AI Big Models to Recommend Streaming Calls

 const aiModel = ai.createModel("zhipu"); // create the model
    const res = await aiModel.streamText({
      model: "glm-4-plus",
      messages: [{
        role: "user",
        content: "Hello, please introduce Li Bai"
      }, ]
    }); for await (let str of res.textStream)
    for await (let str of res.textStream) {
      console.log(str);
    }

The call succeeded.

ai small program build, how to quickly develop an AI weibo small program

Access to AI Agent

The first step is to create an Agent Intelligence

ai small program build, how to quickly develop an AI weibo small program

There are some Agent templates built-in by default, you can directly use the templates or innovate a new Agent, enter the name and introduction on the right side and click "New" on the bottom right corner.

ai small program build, how to quickly develop an AI weibo small program

You will then be taken to the edit details page, which is divided into three areas, from left to right

  1. Agent list area, showing all Agents and the ability to switch between them
  2. Orchestrate Agent area, support setting up persona and response logic as well as adding knowledge base, openers, questions, question suggestions
  3. Agent preview debugging area, you can debug the effect in this area after setting up the Agent.

ai small program build, how to quickly develop an AI weibo small program

Let's take a look at the Choreography Agent area, "Persona and Response Constraints", where you can click the "Generate" button on the right to automatically generate prompts.

ai small program build, how to quickly develop an AI weibo small program

Click on the use of the application can be applied, after the completion of the setup can be in the right area of the dialog test effect

ai small program build, how to quickly develop an AI weibo small program

You can also add a knowledge base for this intelligence, click [Manage Knowledge Base].

ai small program build, how to quickly develop an AI weibo small program

Go to New to enter a title and description

ai small program build, how to quickly develop an AI weibo small program

A folder will appear after success

ai small program build, how to quickly develop an AI weibo small program

Then add the file

ai small program build, how to quickly develop an AI weibo small program

Support for single/multiple add files

ai small program build, how to quickly develop an AI weibo small program

Let's say I add a document on common car trouble problems

ai small program build, how to quickly develop an AI weibo small program

After adding the file, the status will change from "File Parsing in Progress" to "File Parsing and Writing Completed".

ai small program build, how to quickly develop an AI weibo small program

Then just go back to the edit page to add the knowledge base folder, and all that's left is some basic configuration of openers and preset questions.

ai small program build, how to quickly develop an AI weibo small program

Next, let's test the effect of the knowledge base after the completion of the setup, when I sent in the document just mentioned the "open the door creaking noise" problem.

ai small program build, how to quickly develop an AI weibo small program

It will give the source of the cited knowledge base at the end of the answer, which will go a long way towards avoiding the problem of the big model's hallucination on specific content.

ai small program build, how to quickly develop an AI weibo small program

Once we're all configured then we can go ahead and use it, clicking on the Access Guidelines in the upper right hand corner will call out the release document.

release

There are three ways to do this:
1. Docking WeChat platform
2. Small program block components
3.SDK call

Recommended to use these two ways to docking WeChat platform and SDK calls, docking WeChat platform completely no code is more simple, SDK calls pure code way to call more flexible, if your application scenario is not a dialog mode then you can use the code of the way to implant your business flow.

Docking WeChat platform
Support small program customer service, WeChat customer service, WeChat service number, WeChat subscription number

ai small program build, how to quickly develop an AI weibo small program

The configuration process is very simple, just follow the steps to set the AppID and then scan the code for authorization.

Applet Block Components
Need to switch to My Apps from the main menu to create a blank app

ai small program build, how to quickly develop an AI weibo small program

ai small program build, how to quickly develop an AI weibo small program

Then you'll be taken to the microtransmitter edit page, select the right-hand block and search for "Agent".

ai small program build, how to quickly develop an AI weibo small program

Configure ID after choosing to play AgentUI

ai small program build, how to quickly develop an AI weibo small program

ID has a copy ID function in the Agent detail name.

ai small program build, how to quickly develop an AI weibo small program

Once the ID is configured the data will be synchronized to this UI component and you can modify its properties, events, styles, etc.

ai small program build, how to quickly develop an AI weibo small program

After all the modifications are completed we can select the Agent-UI component and switch to the configuration where we can directly download the code package

ai small program build, how to quickly develop an AI weibo small program

Then you can integrate it into your applet according to the follow up documentation

ai small program build, how to quickly develop an AI weibo small program

SDK calls:

  1. Start by establishing a connection.
// Before you start, make sure you have configured your miniprogram request with a legitimate domain name, see https://docs.cloudbase.net/quick-start/baas/wx-mini for details.
// Install the npm package by running the command in the directory where the applet package.json is located (usually the miniprogram directory):
// npm i @cloudbase/js-sdk@2.8.3-beta.0
// After installation, click "Tools -> Build npm" in the menu bar of WeChat Developer Tools.

// Introduce the SDK. Here, we've introduced cloudbase-js-sdk in modules as needed, or in its entirety
import cloudbase from "@cloudbase/js-sdk/app";
import { registerAuth } from "@cloudbase/js-sdk/auth";
import { registerAi } from "@cloudbase/js-sdk/ai";

registerAuth(cloudbase).
registerAi(cloudbase); const app = cloudbase.init
const app = cloudbase.init({
  env: "your-env", // need to be replaced by the actual environment id
}); const auth = app.
const auth = app.auth({ persistence: "local" }); await auth.signInWith
await auth.signInWithOpenId(); // Or use another login method
const ai = await app.ai(); // Next you can call ai.
// You can then call the methods provided by the ai module
  1. Specify a specific Agent dialog
const res = await ai.bot.sendMessage({
  botId: "botId-xxx",
  msg: "Give me an idiom." ,
});

for await (let str of res.textStream) {
  console.log(str); }
}
// Of course
// Yes, you can!
// !
// Here
// Here's one
// Idioms
  1. View Chat Logs
const res = await ai.bot.getChatRecords({
  botId: "botId-xxx", pageNumber: 1, pageNumber.getChatRecords({
  botId: "botId-xxx", pageNumber: 1,
  pageNumber: 1, pageSize: 10,
  sort: "asc", }); { botId: "botId-xxx
});
// {
// "recordList": [
// {
// "botId": "bot-809d4ad1", // "recordId": "record-96617446", // "recordList": [ // {

// "role": "user", // "content": "user", // "content": "user", "user", "user", "user", "user".

// "conversation": "r3Hjz3qgms3UG7z9lwSYbA", // "type": "text".

// "triggerSrc": "TCB"
// }, // { "triggerSrc": "TCB", // "triggerSrc".
// {
// "botId": "bot-809d4ad1", // "recordId": "bot-809d4ad1", {


// "content": "Hello! It looks like you may be experiencing some technical issues, or just want to say hello. In either case, I'm here to help. If you have any specific questions or need assistance, please feel free to let me know!" ,
// "conversation": "r3Hjz3qgms3UG7z9lwSYbA",
// "type": "text", // "triggerSrc".
// "triggerSrc": "TCB"
// }
// ], // "total": 2
// "total": 2
// }

 

Here the whole process of accessing AI is all over.

at last

I hope you can keep up with the AI era and make your own AI applets.

statement:The content is collected from various media platforms such as public websites. If the included content infringes on your rights, please contact us by email and we will deal with it as soon as possible.
TutorialEncyclopedia

How to build your own WeChat AI assistant? Quickly build your personal AI assistant without writing code

2024-11-15 10:09:19

Encyclopedia

AI face-swap tool great recommendation, 7 good AI face-swap software allows you to realize live video face-swap

2024-11-17 9:29:34

Search