GoogleCloudPlatform / generative-ai

Sample code and notebooks for Generative AI on Google Cloud, with Gemini on Vertex AI
https://cloud.google.com/vertex-ai/docs/generative-ai/learn/overview
Apache License 2.0
7.33k stars 1.99k forks source link

base nodejs,Need to be able to pass in the agent, thx #301

Closed lbjfish closed 8 months ago

lbjfish commented 10 months ago

base nodejs,Need to be able to pass in the agent, thx The current interface uses fetch, and I hope to provide agent proxy parameters.

async function makeRequest(url, body) {
    let response;
    try {
        response = await fetch(url, {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                "x-goog-api-client": getClientHeaders(),
            },
            body,
        });
        if (!response.ok) {
            let message = "";
            try {
                const json = await response.json();
                message = json.error.message;
                if (json.error.details) {
                    message += ` ${JSON.stringify(json.error.details)}`;
                }
            }
            catch (e) {
                // ignored
            }
            throw new Error(`[${response.status} ${response.statusText}] ${message}`);
        }
    }
    catch (e) {
        const err = new GoogleGenerativeAIError(`Error fetching from ${url}: ${e.message}`);
        err.stack = e.stack;
        throw err;
    }
    return response;
}
holtskinner commented 10 months ago

@lbjfish Can you provide more context on this issue?

Is this part of a Notebook from this repository, or some other kind of code sample?

holtskinner commented 8 months ago

This repository is for Generative AI with Vertex AI on Google Cloud, not the Google AI Gemini/PaLM APIs.

This looks like it could be the JavaScript client library, so you can try filing an issue in this repository:

https://github.com/google/generative-ai-js

or ask in the Google Developers Community Discord #gemini-api channel.