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

de87306dj00sn0tz70023d000qm012cm

Then find the AI+ menu

2be293aej00sn0tz7000dd000u00058m

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

a77f1713j00sn0tz7000xd000u000gxm

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

dd1f2812j00sn0tzt001ed000u0009qm

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.

421162cbj00sn0tzt002id000m00152m

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.

39a60027j00sn0tzt001fd000u000dkm

Access to AI Agent

The first step is to create an Agent Intelligence

5ee00e0fj00sn0tzt000fd000u000dgm

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.

f6384344j00sn0tzt002kd000u000n6m

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.

a3a070fej00sn0tzt000td000u000frm

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.

598a1fefj00sn0tzt0029d000u000ukm

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

a1df7882j00sn0tzt001gd000u000ftm

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

9cc145aaj00sn0tzt000gd000u000d5m

Go to New to enter a title and description

68d001c6j00sn0tzt000od000u000i0m

A folder will appear after success

aaaf6b1dj00sn0tzt000qd000u000i1m

Then add the file

012af30fj00sn0tzt000ed000u0007tm

Support for single/multiple add files

d5a8261dj00sn0tzt0008d000aa0086m

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

8ca99fc3j00sn0tzt004ed000u0010rm

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

239b1845j00sn0tzt000fd000u0006um

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.

e0281396j00sn0tzt000ud000u000gem

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.

efee6e69j00sn0tzt001qd000ke00m8m

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.

ea6aabb5j00sn0tzt001id000kc00l4m

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

9c4b0bc1j00sn0tzt0022d000po014mm

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

36f2653dj00sn0tzt000xd000k000kkm

4ab97486j00sn0tzt000zd000u000ejm

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

7861e790j00sn0tzt000rd000u000eqm

Configure ID after choosing to play AgentUI

28e36dbaj00sn0tzt0013d000u000fam

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

1dfc37c8j00sn0tzt000rd000u000a3m

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

97b94f50j00sn0tzt0013d000u000eim

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

fea2001dj00sn0tzt000wd000u000b8m

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

5e24ac9dj00sn0tzt002md000u000zbm

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 of the source of public various media platforms, if the inclusion of the content violates your rights and interests, please contact the mailbox, this site will be the first time to deal with.
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

Zenium
Search