Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed #233

Open
jambudipa opened this issue Dec 29, 2024 · 1 comment
Open

Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed #233

jambudipa opened this issue Dec 29, 2024 · 1 comment

Comments

@jambudipa
Copy link

The following server code from the repo sample produces the subsequent errors:

import type { JobProcess } from '@livekit/agents';
import {
  AutoSubscribe,
  type JobContext,
  WorkerOptions,
  cli,
  defineAgent,
  llm,
  pipeline,
} from '@livekit/agents';
import * as deepgram from '@livekit/agents-plugin-deepgram';
import * as openai from '@livekit/agents-plugin-openai';
import * as silero from '@livekit/agents-plugin-silero';
import dotenv from 'dotenv';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { z } from 'zod';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const envPath = path.join(__dirname, '../.env.local');

dotenv.config({ path: envPath });

export default defineAgent({
  prewarm: async (proc: JobProcess) => {
    proc.userData.vad = await silero.VAD.load();
  },
  entry: async (ctx: JobContext) => {
    const vad = ctx.proc.userData.vad! as silero.VAD;
    const initialContext = new llm.ChatContext().append({
      role: llm.ChatRole.SYSTEM,
      text:
        'You are a voice assistant created by LiveKit. Your interface with users will be voice. ' +
        'You should use short and concise responses, and avoiding usage of unpronounceable ' +
        'punctuation.',
    });

    await ctx.connect(undefined, AutoSubscribe.AUDIO_ONLY);
    console.log('waiting for participant');
    const participant = await ctx.waitForParticipant();
    console.log(`starting assistant example agent for ${participant.identity}`);

    const fncCtx: llm.FunctionContext = {
      weather: {
        description: 'Get the weather in a location',
        parameters: z.object({
          location: z.string().describe('The location to get the weather for'),
        }),
        execute: async ({ location }) => {
          console.debug(`executing weather function for ${location}`);
          const response = await fetch(`https://wttr.in/${location}?format=%C+%t`);
          if (!response.ok) {
            throw new Error(`Weather API returned status: ${response.status}`);
          }
          const weather = await response.text();
          return `The weather in ${location} right now is ${weather}.`;
        },
      },
    };

    const agent = new pipeline.VoicePipelineAgent(
      vad,
      new deepgram.STT(),
      new openai.LLM(),
      new openai.TTS(),
      { chatCtx: initialContext, fncCtx },
    );
    agent.start(ctx.room, participant);

    await agent.say('Hey, how can I help you today', true);
  },
});

cli.runApp(new WorkerOptions({ agent: fileURLToPath(import.meta.url) }));

waiting for participant
starting assistant example agent for voice_assistant_user_1461
file:///Users/****/Desktop/livekit/livekit-node-test/node_modules/@livekit/agents/dist/tts/tts.js:167
charactersCount: this.#text.length,
^

TypeError: Cannot read properties of undefined (reading 'length')
at ChunkedStream.monitorMetrics (file:///Users/****/Desktop/livekit/livekit-node-test/node_modules/@livekit/agents/dist/tts/tts.js:167:35)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.17.0
[10:39:54.476] WARN (63126): job process exited unexpectedly
err: {
"type": "Error",
"message": "Channel closed",
"stack":
Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
at target.send (node:internal/child_process:754:16)
at Timeout._onTimeout (file:///Users/****/Desktop/livekit/livekit-node-test/node_modules/@livekit/agents/dist/ipc/proc_job_executor.js:47:18)
at listOnTimeout (node:internal/timers:581:17)
at process.processTimers (node:internal/timers:519:7)
"code": "ERR_IPC_CHANNEL_CLOSED"
}

@jambudipa
Copy link
Author

Not sure how to apply debugging / logging...why would the text be undefined?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant