The @squiz/dxp-ai-conversation-client
is an auto-generated SDK designed to simplify integration with the DXP AI Service for handling chat interactions and conversation rating.
- Abstract the complexity of HTTP requests and OpenAPI interactions, enabling developers to easily integrate AI functionalities related to chat message processing and conversation rating.
- Provide a consistent, strongly-typed TypeScript interface for seamless integration with the DXP AI Service.
- Support both CommonJS (CJS) and ECMAScript Module (ESM) variants for flexible usage in various JavaScript environments.
Install the SDK package using your preferred package manager:
npm install @squiz/dxp-ai-conversation-client
Create an instance of the SDK client by providing the necessary configuration such as the base URL and authentication/session information.
import { DxpAiConversationClient } from '@squiz/dxp-ai-conversation-client';
const client = new DxpAiConversationClient();
Use the processChatMessage
method to start or continue a conversation by sending chat messages.
const aiId = 'your-ai-id';
client.processChatMessage(aiId, {
message: 'Hello, how can I get help?'
})
.then(response => {
console.log('Chat response:', response);
})
.catch(error => {
console.error('Error processing chat message:', error);
});
Use the rateConversation
method to submit user feedback on whether a conversation was helpful.
const aiId = 'your-ai-id';
const threadId = 'conversation-thread-id';
client.rateConversation(aiId, threadId, {
rating: 'positive', # positive | negative
})
.then(response => {
console.log('Rating submitted:', response);
})
.catch(error => {
console.error('Error submitting rating:', error);
});
-
processChatMessage(aiId: string, payload: ProcessChatMessagePayload): Promise<ProcessChatMessageResponse>
Handles processing or starting a new conversation and sending messages in ongoing conversations. Requires an active DXP Session. -
rateConversation(aiId: string, threadId?: string, payload: RateConversationPayload): Promise<RateConversationResponse>
Allows users to rate if a conversation was helpful.
If you need to extend or modify the SDK, please refer to the Contribution Guidelines in the DXP AI service repository.
The SDK source code and OpenAPI specification are located in the DXP AI service repository at:
packages/dxp-ai-conversation-client
This SDK uses Changesets for versioning and release management, integrated into the release pipeline to publish both CommonJS (CJS) and ECMAScript Module (ESM) variants to NPM.