Reference code: XpertAI SDK Example
Preparation
Before making API calls, you need to prepare the following credentials and information, which can be configured in an environment variables file (XPERTAI_API_URL and XPERTAI_API_KEY):
How to Obtain These Credentials
-
API_URL and API_KEY
- Log in to the XperAI platform’s Digital Expert or Knowledgebase.
- Navigate to the “Settings” -> “API Keys” page.
- Generate or copy your API key.
- The API base URL is typically
https://api.xpertai.cn/api/ai/.
-
Workspace ID
- In the XperAI console, access your workspace.
- The workspace ID can be found in the browser’s address bar.
- The format is typically a UUID (e.g.,
23f2b2ff-9318-43b6-a986-928fcf70d4ea).
-
Copilot ID
- In the XperAI settings page, go to the “AI Copilot” section.
- Select the copilot you want to associate.
- The ID can be found on the copilot provider icon.
- The format is typically a UUID (e.g.,
9ff28c7c-3e63-4ced-b855-2782d79a21b3).
-
Knowledgebase System Integration ID (optional, required only for external knowledgebase)
- If you are using an external knowledgebase integration, find this ID in the integration settings.
Install Required Dependencies
API Call Steps
1. Create a Knowledgebase
First, we need to create a knowledgebase container:2. Upload a File
Upload a local file to the XperAI platform:3. Create a Document Association
Create a document in the knowledgebase from the uploaded file:4. Start Embedding Process
Initiate the vectorization process for the document:5. Check Processing Status
Check the progress of document processing:Complete Usage Example
Notes
- Ensure all ID parameters use the correct values obtained from the XperAI platform.
- Safeguard your API key and do not expose it or commit it to version control systems.
- File uploads have size limits; refer to the official documentation for specific restrictions.
- Document processing time depends on file size and content complexity.
- It is recommended to implement appropriate error handling and retry mechanisms for improved reliability.