googleapis / nodejs-vertexai

Apache License 2.0
112 stars 39 forks source link

The timeout setting is ineffective #420

Closed qingfengmy closed 2 weeks ago

qingfengmy commented 2 weeks ago
const vertexAI = new VertexAI({
      project: project,
      location: location,
      googleAuthOptions: { credentials: serviceAccount },
    });
    this.generativeModel = vertexAI.preview.getGenerativeModel(
      {
        model: model,
        generationConfig: {
          maxOutputTokens: 8192,
          temperature: 1,
          topP: 0.95,
        },
      },
      {
        timeout: 1000 * 60 * 10, // 10mins
      },
    );
const video1_1 = {
      fileData: {
        mimeType: 'video/mp4',
        fileUri: `gs://xxx.mp4`,
      },
    };
    const text1_1 = {
      text: `introduce  the video`,
    };

    const chat = this.generativeModel.startChat({});
    const streamResult = await chat.sendMessage([video1_1, text1_1]);

When I set the timeout to 10 minutes, it didn't take effect; it threw an error after just 1 minute.

If the response is returned within 1 minute, then it is the correct result

happy-qiao commented 2 weeks ago

Hi @qingfengmy

I tried this code snippet and it doesn't exit in 1 minute

import { VertexAI } from '@google-cloud/vertexai';

console.log("start");

(async function () {
    console.log("in function")
    const vertexAI = new VertexAI({
        project: 'project',
        location: 'us-central1',
        // googleAuthOptions: { credentials: serviceAccount },
    });
    const generativeModel = vertexAI.preview.getGenerativeModel(
        {
            model: 'gemini-1.5-pro',
            generationConfig: {
                maxOutputTokens: 8192,
                temperature: 1,
                topP: 0.95,
            },
        }
        ,
        {
            timeout: 1000 * 60 * 10, // 10mins
        },
    );
    const video1_1 = {
        fileData: {
            mimeType: 'video/mp4',
            fileUri: `gs://project/test_video.mp4`,
        },
    };
    const text1_1 = {
        text: `Introduce the video.`,
    };

    const chat = generativeModel.startChat({});
    console.log("start chat", new Date())
    const streamResult = await chat.sendMessage([video1_1, text1_1]);
    const result = await streamResult;

    console.log("end chat", new Date(), JSON.stringify(result));

})();

stdout

[2024-08-29 15:35:25] ➜  nodejs-playground node build/src/test_timeout.js
start
in function
start chat 2024-08-29T22:35:28.089Z
(node:27626) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
end chat 2024-08-29T22:37:27.707Z {"response":{"candidates":[{"content":{"role":"model","parts":[{"text":"The video is about
qingfengmy commented 2 weeks ago
import { bootstrap } from 'global-agent';
import { setGlobalDispatcher, ProxyAgent } from 'undici';

// global-agent:google-cloud-token
// undici: vertexai
process.env.GLOBAL_AGENT_HTTP_PROXY = 'http://127.0.0.1:7890';
process.env.GLOBAL_AGENT_HTTPS_PROXY = 'http://127.0.0.1:7890';

const timeout = 10 * 60 * 1000; // 10mins
export function proxy() {
  bootstrap({
    socketConnectionTimeout: timeout,
  });
  const dispatcher = new ProxyAgent({
    uri: new URL(process.env.GLOBAL_AGENT_HTTP_PROXY).toString(),
    requestTls: { timeout },
    proxyTls: { timeout },
  });

  setGlobalDispatcher(dispatcher);
}

i use the proxy code,and the error is below like that

start
in function
start chat 2024-08-30T02:43:00.722Z
end chat 2024-08-30T02:44:01.304Z
GoogleGenerativeAIError: [VertexAI.GoogleGenerativeAIError]: exception posting request to model
    at /Users/demo-test/node_modules/@google-cloud/vertexai/build/src/functions/generate_content.js:55:15
    at async generateContent (/Users/demo-test/node_modules/@google-cloud/vertexai/build/src/functions/generate_content.js:45:22)
    at async ChatSessionPreview.sendMessage (/Users/demo-test/node_modules/@google-cloud/vertexai/build/src/models/chat_session.js:240:39)
    at async file:///Users/demo-test/test1.js:83:26 {
  stackTrace: TypeError: fetch failed
      at node:internal/deps/undici/undici:12502:13
      at async generateContent (/Users/demo-test/node_modules/@google-cloud/vertexai/build/src/functions/generate_content.js:45:22)
      at async ChatSessionPreview.sendMessage (/Users/demo-test/node_modules/@google-cloud/vertexai/build/src/models/chat_session.js:240:39)
      at async file:///Users/demo-test/test1.js:83:26 {
    [cause]: SocketError: other side closed
        at TLSSocket.<anonymous> (/Users/demo-test/node_modules/undici/lib/dispatcher/client-h1.js:681:24)
        at TLSSocket.emit (node:events:531:35)
        at TLSSocket.emit (node:domain:488:12)
        at endReadableNT (node:internal/streams/readable:1696:12)
        at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
      code: 'UND_ERR_SOCKET',
      socket: [Object]
    }
  },
  [cause]: TypeError: fetch failed
      at node:internal/deps/undici/undici:12502:13
      at async generateContent (/Users/demo-test/node_modules/@google-cloud/vertexai/build/src/functions/generate_content.js:45:22)
      at async ChatSessionPreview.sendMessage (/Users/demo-test/node_modules/@google-cloud/vertexai/build/src/models/chat_session.js:240:39)
      at async file:///Users/demo-test/test1.js:83:26 {
    [cause]: SocketError: other side closed
        at TLSSocket.<anonymous> (/Users/demo-test/node_modules/undici/lib/dispatcher/client-h1.js:681:24)
        at TLSSocket.emit (node:events:531:35)
        at TLSSocket.emit (node:domain:488:12)
        at endReadableNT (node:internal/streams/readable:1696:12)
        at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
      code: 'UND_ERR_SOCKET',
      socket: [Object]
    }
  }
}