Reference
Messages

Messages are the actual pieces of information being exchanged in a conversation. Messages get sent and received within conversations. Messages can be of various types, including text, audio, image, and simple UI forms.

See Message.

Send Message

POST /conversations/{{conversation_id}}/messages
curl -L \
-X POST \
-H "Authorization: Bearer 66563d92e59961d11fc67a39" \
https://messaging-api.useproteus.ai/conversations/661174a67e9ce0299b57d280/messages \
-d '{"content": "Describe this image", "type": "TEXT", "attachments": [{"content": "https://fastly.picsum.photos/id/337/200/300.jpg", "type": "IMAGE_URL"}]}'

Listening for New Messages

Clients can implement creative ways of repeatedly sending a GET request to https://messaging-api.useproteus.ai/conversations/{{conversation_id}}/messages in order to fetch the latest messages in the conversation.

curl -L \
-X GET \
-H "Authorization: Bearer 66563d92e59961d11fc67a39" \
https://messaging-api.useproteus.ai/conversations/661174a67e9ce0299b57d280/messages

Message Streams

Messages from AI characters that are of type TEXT get streamed from the API to clients. This means we do not need to wait for the character to construct the entire message before sending it to clients; we continuously stream the message in packets until the entire message has been constructed. This improves user experience as users no longer have to wait a long time just to be hit by the entire message at once.

To know if a message is still being streamed, see if the isStreaming field is true.

To see the content generated in the current packet, see the contentDelta field.

import ProteusAI from '@proteus-ai/sdk';
const proteus = new ProteusAI({ apiKey: '66563d92e59961d11fc67a39' });
try {
    const conversation = await proteus.conversations.create({
        characterId: '659a21168ad10b77542a3587'
    });
    conversation.on('CHARACTER_MESSAGE_SENT', (message) => {
      if (message.isStreaming) {
        console.log('This message is still being streamed');
        console.log(`This portion of the message generated in the current packet is: ${message.contentDelta}`);
        console.log(`This message generated thus far is: ${message.content}`);
      } else {
        console.log('This message has now been fully constructed');
        console.log(`This complete message is: ${message.content}`);
      }
    });
} catch (_) {}

Here is a video of a message from an AI character being streamed to a client.


© 2024 ProteusAI. All rights reserved