Il devkit di CX Insights è un'API di alto livello progettata per estendere il client Python di Google per CX Insights. In qualità di sviluppatore o di persona che gestisce il codice, puoi utilizzare il devkit di CX Insights per scalare un'ampia gamma di attività.
Casi d'uso
Le azioni che puoi eseguire includono:
- Importare singole conversazioni con i metadati.
- Importare molte conversazioni in blocco con i metadati.
- Trascrivere file audio mono utilizzando Speech-to-Text (STT) V1.
- Creare riconoscitori utilizzando STT V2.
- Configurare BigQuery Export.
- Modificare le impostazioni globali di CX Insights.
- Trasformare il formato dei dati di trascrizione da Genesys Cloud a CX Insights.
- Trasformare il formato dei dati di trascrizione da AWS a CX Insights.
Inizia
Per iniziare a utilizzare il devkit, segui questi passaggi per la configurazione dell'ambiente e l'autenticazione.
Passaggio 1: configura un ambiente virtuale
Prima di utilizzare il devkit, segui questi passaggi per configurare le tue Google Cloud credenziali e installare le dipendenze necessarie.
- Utilizza il seguente codice per autenticare il tuo account con Google Cloud CLI.
gcloud auth login gcloud auth application-default login
- Imposta il tuo Google Cloud progetto con il seguente codice. Sostituisci project name con l'ID progetto effettivo Google Cloud .
gcloud config set project
- Crea e attiva un ambiente virtuale Python con il seguente codice. Devi utilizzare un ambiente virtuale per gestire le dipendenze del progetto.
python3 -m venv venv source ./venv/bin/activate
- Installa le dipendenze. Nella directory del progetto, controlla se è presente un file
requirements.txtcontenente le dipendenze del devkit e installale eseguendo il seguente codice.pip install -r requirements.txt
Passaggio 2: autenticazione dell'account
I metodi di autenticazione per il devkit Python variano a seconda dell'ambiente.
Google Colaboratory
Se utilizzi il devkit di CX Insights in un notebook di Google Colaboratory, puoi eseguire l'autenticazione aggiungendo il seguente codice all'inizio dei notebook gestiti dall'utente:
project_id = '
' In questo modo viene avviato un prompt interattivo che ti consente di eseguire l'autenticazione con Google Cloud in un browser.
!gcloud auth application-default login --no-launch-browser
L'autenticazione imposta il progetto attivo su
project_id.!gcloud auth application-default set-quota-project $project_id
Cloud Run Functions
Quando utilizzi il devkit di CX Insights con Cloud Run Functions, il devkit rileva automaticamente le credenziali dell'ambiente predefinito utilizzate da questi servizi.
- Aggiungi il devkit al file TXT dei requisiti: verifica che sia elencato nel file
requirements.txtdel servizio Cloud Run Functions. - Ruolo Identity and Access Management: verifica che al account di servizio di Cloud Run Functions sia assegnato il ruolo IAM di Dialogflow appropriato.
Ambiente Python locale
Analogamente a Cloud Run Functions, questo devkit rileva le credenziali di autenticazione locali se utilizzi gcloud CLI.
- Installa gcloud CLI. Se non l'hai ancora fatto, installa Google Cloud SDK. Include gcloud CLI.
- Inizializza gcloud CLI con il seguente codice.
gcloud init
- Accedi con il seguente codice. Google Cloud
gcloud auth login
- Verifica un account attivo con il seguente codice. Questo comando autentica il tuo account principale Google Cloud con gcloud CLI. Il devkit di CX Insights può quindi recuperare le credenziali dalla configurazione.
gcloud auth list
Contenuti del devkit
Il devkit di CX Insights contiene le seguenti risorse.
Cartella principale
La cartella principale è sinonimo dei tipi di risorse principali presenti nella maggior parte delle classi. Contiene i blocchi predefiniti di alto livello del devkit e funzionalità generali come l'autenticazione e le configurazioni globali. Queste classi e questi metodi vengono utilizzati per creare metodi di livello superiore o strumenti e applicazioni personalizzati.
Cartella comune
La cartella comune contiene wrapper creati intorno ai metodi implementati in Google Cloud SDK. L'idea è di aggiungere un nuovo livello di semplicità alle implementazioni esistenti. Puoi eseguire le seguenti azioni con la cartella Comune.
- Manipolare le configurazioni globali da CX Insights.
- Importare conversazioni (singole e in blocco) con i metadati.
- Creare o elencare i blob in un bucket Cloud Storage.
- Creare trascrizioni da audio utilizzando STT V1 e V2.
- Trascrivere file audio mono con STT V1.
Cartella dei Workflows
La cartella dei workflow contiene classi e metodi progettati per eseguire azioni non supportate da CX Insights, ad esempio le seguenti.
- Formattare le trascrizioni da Genesys Cloud a CX Insights.
- Formattare le trascrizioni da AWS a Customer Experience Insights.
- Riconoscere i ruoli in una trascrizione utilizzando Gemini.
Annotare una conversazione audio
Il seguente script Python trascrive un file audio, assegna i ruoli degli oratori e poi invia i dati della conversazione arricchiti a CX Insights per l'analisi.
def audio_with_role_recognition():
# 1. Reset Insights Settings
reset_insights_settings()
# Verifies a clean state for CX Insights settings before starting the test.
# This function is assumed to be defined elsewhere and handles resetting global configurations.
# 2. Initialize Speech-to-Text V2 Client
sp = speech.V2(
project_id = _PROBER_PROJECT_ID
)
# Initializes a client for interacting with the Google Cloud Speech-to-Text API (V2).
# _PROBER_PROJECT_ID: The Google Cloud Project ID where the STT recognizer resides.
# 3. Create Transcription
transcript = sp.create_transcription(
audio_file_path = _MONO_SHORT_AUDIO_LOCATION,
recognizer_path = 'projects/<project_id>/locations/<region>/recognizers/<recognizer_id>'
)
# Sends an audio file for transcription using a specific STT V2 recognizer.
# audio_file_path: Local path to the mono audio file to be transcribed.
# recognizer_path: Full resource path to the STT V2 recognizer to be used for transcription.
# Example: 'projects/YOUR_PROJECT_NUMBER/locations/global/recognizers/YOUR_RECOGNIZER_ID'
# Verifies that the returned 'transcript' object is of the expected type from the Speech-to-Text V2 API.
# 4. Format Transcription
ft = format.Speech()
# Initializes a formatting utility for speech-related data.
transcript = ft.v2_recognizer_to_dict(transcript)
# Transforms the STT V2 `RecognizeResponse` object into a more manageable Python dictionary format,
# which is often easier to work with for subsequent processing steps like role recognition.
# 5. Initialize Google Cloud Storage Client
gcs = storage.Gcs(
project_name = _PROBER_PROJECT_ID,
bucket_name = _TMP_PROBER_BUCKET
)
# Initializes a Google Cloud Storage client.
# project_name: The Google Cloud Project ID.
# bucket_name: The name of the Google Cloud Storage bucket where the processed transcript will be temporarily stored.
# 6. Generate Unique File Name
file_name = f'{uuid.uuid4()}.json'
# Creates a unique file name for the JSON transcript using a UUID (Universally Unique Identifier).
# This prevents naming conflicts when uploading multiple transcripts to the same Google Cloud Storage bucket.
# 7. Perform Role Recognition
role_recognizer = rr.RoleRecognizer()
# Initializes the RoleRecognizer component, likely part of the Customer Experience Insights DevKit,
# responsible for identifying speaker roles (e.g., agent, customer) within a conversation.
roles = role_recognizer.predict_roles(conversation=transcript)
# Predicts the roles of speakers in the transcribed conversation.
# conversation: The transcribed conversation in a dictionary format.
transcript = role_recognizer.combine(transcript, roles)
# Integrates the recognized roles back into the original transcript data structure.
# This step enriches the transcript with speaker role metadata.
# 9. Upload Processed Transcript to Google Cloud Storage
gcs.upload_blob(
file_name = file_name,
data = transcript
)
# Uploads the enriched transcript (as JSON data) to the specified Google Cloud Storage bucket with the generated unique file name.
# This Google Cloud Storage path will be used as the source for Customer Experience Insights ingestion.
# 10. Construct Google Cloud Storage Path
gcs_path = f"gs://{_TMP_PROBER_BUCKET}/{file_name}"
# Forms the full Google Cloud Storage URI for the uploaded transcript, which is required by the Customer Experience Insights Ingestion API.
# 11. Initialize CX Insights Ingestion
ingestion = insights.Ingestion(
parent = _PARENT,
transcript_path = gcs_path
)
# Initializes an Ingestion client for CX Insights.
# parent: The parent resource path for CX Insights, typically in the format:
# 'projects/YOUR_PROJECT_NUMBER/locations/YOUR_LOCATION'
# transcript_path: The Google Cloud Storage URI where the conversation transcript is stored.
# 12. Ingest Single Conversation
operation = ingestion.single()
# Initiates the ingestion of the single conversation into CX Insights.
# This returns an operation object, which can be used to monitor the status of the ingestion.
Contributi e richieste di funzionalità
Per inviare contributi o richieste di funzionalità:
- Crea un fork del repository su GitHub.
- Crea il ramo della funzionalità con il seguente codice.
git checkout -b feature/AmazingFeature
- Esegui il commit delle modifiche con il seguente codice.
git commit -m 'Add some AmazingFeature'
- Esegui il push delle modifiche al ramo con il seguente codice.
git push origin feature/AmazingFeature
- Apri una richiesta di pull e inviala dal ramo della funzionalità al repository principale.
Licenza
La distribuzione del devkit di CX Insights è soggetta alla licenza Apache 2.0. Per maggiori dettagli, consulta il file LICENSE nel repository del progetto.