Skip to main content

AI+

In $w.ai, you can access Cloud Development AI+ capabilities, enabling rapid integration with large models and Agent.

$w.ai.LLM

Aggregates methods related to large models.

$w.ai.LLM.chat

Use this interface to converse with large models, supporting both streaming and non-streaming conversations.

When the stream parameter is set to true, a streaming conversation is initiated, returning text streams and SSE event streams.

async function doStreamChat() {
const res = await $w.ai.LLM.chat({
provider: 'hunyuan',
model: 'hunyuan-lite',
messages: [{role: 'user', content: "Hello"}],
stream: true
});

const textStream = res.textStream; // Text stream
for await (let text of textStream) {
console.log(text);
}

const eventStream = res.eventStream; // SSE event stream
for await (let event of eventStream) {
console.log(event);
}
}

When the stream parameter is not passed or set to false, a non-streaming conversation is conducted, and the API returns the large model's response.

async function doChat() {
const res = await $w.ai.LLM.chat({
provider: 'hunyuan',
model: 'hunyuan-lite',
messages: [{role: 'user', content: "Hello"}]
});
console.log(res);
}

Parameters

ParameterTypeDescriptionExampleRequired
props.providerstringModel provider'hunyuan'Yes
props.modelstringModel specification used. Refer to the specific large model in use for the list of available models.'hunyuan-lite'Yes
props.messagesArray<{role: string, content: string}>Conversation message list[{role: "user", content: 'Hello'}]Yes
props.streambooleanWhether to use streaming requeststrueNo
props.temperaturenumberTemperature parameter that affects the diversity of the large model's generated results. Refer to the documentation of the specific large model used and configure as needed.1No
props.top_pnumberNucleus sampling parameter that affects the diversity of the large model's generated results. Refer to the documentation of the specific large model used and configure as needed.1No

$w.ai.bot

Aggregates methods related to Agent.

$w.ai.bot.sendMessage

Use this interface to conduct streaming dialogue with Agent, returning text streams and SSE event streams.

async function sendMessageToAgent() {
const res = await $w.ai.bot.sendMessage({
botId: 'bot-xxx',
msg: 'Hello',
history: []
});

const textStream = res.textStream; // Text stream
for await (let text of textStream) {
console.log(text);
}

const eventStream = res.eventStream; // SSE event stream
for await (let event of eventStream) {
console.log(event);
}
}

Parameters

The parameters of this interface are consistent with Bot.sendMessage in @cloudbase/js-sdk.

$w.ai.bot.getRecommendQuestions

Use this interface to obtain Agent-recommended problem suggestions, returning text streams and SSE event streams.

async function getRecommendQuestionsFromAgent() {
const res = await $w.ai.bot.getRecommendQuestions({
botId: "bot-xxx",
introduction: "A highly conversational robot",
name: "Chatbot",
});

const textStream = res.textStream; // Text stream
for await (let text of textStream) {
console.log(text);
}

const eventStream = res.eventStream; // SSE event stream
for await (let event of eventStream) {
console.log(event);
}
}

Parameters

The parameters of this interface are consistent with Bot.getRecommendQuestions in @cloudbase/js-sdk.

$w.ai.bot.get

Get information about a specific Agent.

The input and output parameters of this interface are consistent with Bot.get in @cloudbase/js-sdk.

$w.ai.bot.list

Retrieve information for multiple Agents in batch.

The input and output parameters of this interface are consistent with Bot.list in @cloudbase/js-sdk.

$w.ai.bot.getChatRecords

Get chat history.

The input and output parameters of this interface are consistent with Bot.getChatRecords in @cloudbase/js-sdk.

$w.ai.bot.sendFeedback

Send feedback on a specific chat history.

The input and output parameters of this interface are consistent with Bot.sendFeedback in @cloudbase/js-sdk.

$w.ai.bot.getFeedback

Get existing feedback information.

The input and output parameters of this interface are consistent with Bot.getFeedback in @cloudbase/js-sdk.

$w.ai.bot.uploadFiles

Upload files from cloud storage to the Agent for document-based chatting.

The input and output parameters of this interface are consistent with Bot.uploadFiles in @cloudbase/js-sdk.

$w.ai.bot.createConversation

Create a new conversation with the Agent.

Parameters

The parameters of this interface are consistent with Bot.createConversation in @cloudbase/js-sdk.

$w.ai.bot.getConversation

Get conversation list.

Parameters

The parameters of this interface are consistent with Bot.getConversation in @cloudbase/js-sdk.

$w.ai.bot.deleteConversation

Delete specified conversation.

Parameters

The parameters of this interface are consistent with Bot.deleteConversation in @cloudbase/js-sdk.

$w.ai.bot.speechToText

Speech to text.

Parameters

The parameters of this interface are consistent with Bot.speechToText in @cloudbase/js-sdk.

$w.ai.bot.textToSpeech

Text to speech.

Parameters

The parameters of this interface are consistent with Bot.textToSpeech in @cloudbase/js-sdk.

$w.ai.bot.getTextToSpeechResult

Get the text-to-speech result.

Parameters

The parameters of this interface are consistent with Bot.getTextToSpeechResult in @cloudbase/js-sdk.