feat(sync): Update xAI collection file addition endpoint and improve documentation

This commit is contained in:
bsiggel
2026-03-26 13:22:14 +00:00
parent 459fa41033
commit 1e202a6233
2 changed files with 440 additions and 14 deletions

View File

@@ -112,12 +112,9 @@ class XAIService:
async def add_to_collection(self, collection_id: str, file_id: str) -> None:
"""
Fügt eine Datei einer xAI-Collection (Vector Store) hinzu.
Fügt eine Datei einer xAI-Collection hinzu.
POST https://api.x.ai/v1/vector_stores/{vector_store_id}/files
Uses the OpenAI-compatible API pattern for adding files to vector stores.
This triggers proper indexing and processing.
POST https://management-api.x.ai/v1/collections/{collection_id}/documents/{file_id}
Raises:
RuntimeError: bei HTTP-Fehler
@@ -125,16 +122,10 @@ class XAIService:
self._log(f"📚 Adding file {file_id} to collection {collection_id}")
session = await self._get_session()
# Use the OpenAI-compatible endpoint (not management API)
url = f"{XAI_FILES_URL}/v1/vector_stores/{collection_id}/files"
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json",
}
url = f"{XAI_MANAGEMENT_URL}/v1/collections/{collection_id}/documents/{file_id}"
headers = {"Authorization": f"Bearer {self.management_key}"}
payload = {"file_id": file_id}
async with session.post(url, json=payload, headers=headers) as response:
async with session.post(url, headers=headers) as response:
if response.status not in (200, 201):
raw = await response.text()
raise RuntimeError(