Documentation Index Fetch the complete documentation index at: https://docs.sf-voice.sh/llms.txt
Use this file to discover all available pages before exploring further.
Ce guide vous mène de la clé API au premier résultat de recherche avec le SDK TypeScript.
Installation
pnpm add @sf-voice/media@latest
1. Créer un client
import { SfVoiceMedia } from "@sf-voice/media" ;
const client = new SfVoiceMedia ({
baseUrl: "https://api.sf-voice.com" ,
apiKey: process . env . SF_VOICE_API_KEY ! ,
});
2. Ingérer un actif
Utilisez un asset_id provenant de votre propre système. Utilisez asset_class pour regrouper les actifs
qui doivent être recherchés ensemble, comme tous les médias d’un même client.
const ingest = await client . ingest ({
source: "url" ,
asset_id: "video_123" ,
asset_class: "customer_acme" ,
url: "https://example.com/recording.mp4" ,
media_type: "video" ,
types: [ "video" , "audio" , "transcript" ],
metadata: {
title: "product demo" ,
customer_id: "acme" ,
},
});
La réponse inclut un task_id pour l’indexation.
{
"asset_id" : "video_123" ,
"task_id" : "task_abc123" ,
"status" : "pending"
}
3. Attendre l’indexation
const task = await client . pollTask ( ingest . task_id , {
intervalMs: 2_000 ,
timeoutMs: 120_000 ,
});
if ( task . status === "failed" ) {
throw new Error ( task . error ?? "ingest task failed" );
}
4. Rechercher
Effectuez la recherche au sein du même asset_class afin que les résultats restent cadrés au client ou
au groupe visé.
const search = await client . search ({
query: "where does the customer mention pricing?" ,
asset_class: "customer_acme" ,
types: [ "transcript" ],
threshold: 0.7 ,
limit: 10 ,
});
console . log ( search . results );
Exemple complet
import { SfVoiceMedia , SfVoiceMediaError } from "@sf-voice/media" ;
const client = new SfVoiceMedia ({
baseUrl: "https://api.sf-voice.com" ,
apiKey: process . env . SF_VOICE_API_KEY ! ,
});
try {
const ingest = await client . ingest ({
source: "url" ,
asset_id: "video_123" ,
asset_class: "customer_acme" ,
url: "https://example.com/recording.mp4" ,
media_type: "video" ,
types: [ "video" , "audio" , "transcript" ],
});
const task = await client . pollTask ( ingest . task_id );
if ( task . status === "failed" ) {
throw new Error ( task . error ?? "ingest task failed" );
}
const search = await client . search ({
query: "pricing" ,
asset_class: "customer_acme" ,
types: [ "transcript" ],
});
console . log ( search . results );
} catch ( error ) {
if ( error instanceof SfVoiceMediaError ) {
console . error ( error . code , error . status , error . message );
}
throw error ;
}
Étapes suivantes
Comment ça fonctionne Découvrez comment l’ingestion, l’indexation, l’interrogation de tâches et la recherche cadrée s’articulent.
SDK TypeScript Consultez toutes les formes d’entrée et de sortie exposées par le SDK.