Skip to content

Commit 6dd0919

Browse files
committed
Remove tracing functionality and simplify voice pipeline imports
1 parent b99e353 commit 6dd0919

File tree

1 file changed

+20
-59
lines changed

1 file changed

+20
-59
lines changed

examples/voice/server.js

Lines changed: 20 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
import OpenAI from 'openai';
33
import {
44
Agent,
5-
VoicePipeline,
6-
VoicePipelineConfig,
7-
OpenAITTSModel,
8-
OpenAISTTModel,
9-
SingleAgentVoiceWorkflow,
10-
tracing
5+
Voice
116
} from '../../src/index';
127
import { serve } from 'bun';
138
import { join } from 'path';
@@ -43,90 +38,57 @@ class WorkflowCallbacks {
4338
}
4439

4540
// Configurando o workflow de voz
46-
const workflow = new SingleAgentVoiceWorkflow(agent, {
41+
const workflow = new Voice.SingleAgentVoiceWorkflow(agent, {
4742
callbacks: new WorkflowCallbacks()
4843
});
4944

50-
// Configurando o processador de tracing
51-
const tracingProcessor = new tracing.OpenAITracingProcessor();
52-
tracing.addTraceProcessor(tracingProcessor);
53-
5445
// Criando os modelos de STT e TTS
55-
const sttModel = new OpenAISTTModel(client);
56-
const ttsModel = new OpenAITTSModel(client);
46+
const sttModel = new Voice.OpenAISTTModel(client);
47+
const ttsModel = new Voice.OpenAITTSModel(client);
5748

5849
// Configurando o pipeline
59-
const config = new VoicePipelineConfig({
50+
const config = new Voice.VoicePipelineConfig({
6051
workflowName: "Exemplo de Voz",
61-
tracingDisabled: false,
6252
sttSettings: {
6353
voice: 'coral'
6454
},
6555
ttsSettings: {
6656
voice: 'coral'
67-
},
68-
traceMetadata: {
69-
environment: "development",
70-
application: "voice-demo"
7157
}
7258
});
7359

7460

75-
const pipeline = new VoicePipeline({
61+
const pipeline = new Voice.VoicePipeline({
7662
workflow,
7763
sttModel,
7864
ttsModel,
7965
config
8066
});
8167

82-
// Envolver as operações principais em traces
8368
async function handleAudioRequest(audio) {
84-
8569
console.log(`[debug] handleAudioRequest called with audio: ${audio}`);
8670
const size = audio.size;
8771
const type = audio.type;
8872
console.log(`[debug] handleAudioRequest called with audio: ${size}, ${type}`);
89-
90-
return await tracing.withTrace("voice_interaction", async (trace) => {
91-
const spanData = new tracing.CustomSpanData("process_audio", {
92-
id: "voice_stream_event_" + Date.now().toString(),
93-
type: "voice_stream_event_audio",
94-
input_size: size,
95-
content_type: type
96-
});
97-
return await tracing.withSpan("process_audio", async (span) => {
98-
// Processar o áudio com o pipeline
99-
const result = await pipeline.processAudio(audio);
100-
return result;
101-
}, spanData);
102-
}, {
103-
metadata: {
104-
environment: "development",
105-
application: "voice-demo"
106-
}
107-
});
73+
// Processar o áudio com o pipeline diretamente
74+
const result = await pipeline.processAudio(audio);
75+
return result;
10876
}
10977

11078
// Função para processar áudio
11179
async function processAudio(audioBlob) {
112-
const spanData = new tracing.CustomSpanData("audio_processing", {
113-
type: "voice_stream_event_lifecycle",
114-
event: "turn_started"
115-
});
116-
return await tracing.withSpan("audio_processing", async (span) => {
117-
// Ensure the blob is in the correct format
118-
if (!(audioBlob instanceof Blob)) {
119-
throw new Error('Input must be a Blob');
120-
}
80+
// Ensure the blob is in the correct format
81+
if (!(audioBlob instanceof Blob)) {
82+
throw new Error('Input must be a Blob');
83+
}
12184

122-
const audioChunks = [];
123-
for await (const chunk of await handleAudioRequest(audioBlob)) {
124-
audioChunks.push(chunk);
125-
}
85+
const audioChunks = [];
86+
for await (const chunk of await handleAudioRequest(audioBlob)) {
87+
audioChunks.push(chunk);
88+
}
12689

127-
// Keep the webm format as it's supported by OpenAI
128-
return new Blob(audioChunks, { type: 'audio/webm' });
129-
}, spanData);
90+
// Keep the webm format as it's supported by OpenAI
91+
return new Blob(audioChunks, { type: 'audio/webm' });
13092
}
13193

13294
// Servidor Bun
@@ -176,8 +138,7 @@ const server = serve({
176138
headers: { 'Content-Type': 'text/plain' }
177139
});
178140
} finally {
179-
// Garante que o processador de tracing seja desligado corretamente
180-
tracingProcessor.shutdown();
141+
// Nenhuma ação de tracing necessária
181142
}
182143
}
183144
});

0 commit comments

Comments
 (0)