mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-23 22:07:29 +00:00
* fix(security): hash the publicly known master key Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: replace weak master key examples and regenerate artifacts Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test: replace weak key fixtures with generated test keys Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ci: generate master keys for proxy startup Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: preserve lens dev key entropy Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: restore proxy key compatibility in scrub examples Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: scrub merged SSO fixture and refresh dashboard bundle Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(ci): stabilize test keys and metadata collection Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * chore: drop the rebuilt dashboard bundle Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: mateo <mateo@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
58 lines
No EOL
1.7 KiB
JavaScript
58 lines
No EOL
1.7 KiB
JavaScript
const { GoogleGenerativeAI, ModelParams, RequestOptions } = require("@google/generative-ai");
|
|
|
|
const masterKey = process.env.LITELLM_MASTER_KEY;
|
|
if (!masterKey) throw new Error("LITELLM_MASTER_KEY must be set");
|
|
|
|
const modelParams = {
|
|
model: 'gemini-3.1-flash-lite',
|
|
};
|
|
|
|
const requestOptions = {
|
|
baseUrl: 'http://127.0.0.1:4000/gemini',
|
|
customHeaders: {
|
|
"tags": "gemini-js-sdk,gemini-3.1-flash-lite"
|
|
}
|
|
};
|
|
|
|
const genAI = new GoogleGenerativeAI(masterKey);
|
|
const model = genAI.getGenerativeModel(modelParams, requestOptions);
|
|
|
|
const testPrompt = "Explain how AI works";
|
|
|
|
async function main() {
|
|
console.log("making request")
|
|
try {
|
|
const result = await model.generateContent(testPrompt);
|
|
console.log(result.response.text());
|
|
} catch (error) {
|
|
console.error('Error details:', {
|
|
name: error.name,
|
|
message: error.message,
|
|
cause: error.cause,
|
|
// Check if there's a network error
|
|
isNetworkError: error instanceof TypeError && error.message === 'fetch failed'
|
|
});
|
|
|
|
// Check if the server is running
|
|
if (error instanceof TypeError && error.message === 'fetch failed') {
|
|
console.error('Make sure your local server is running at http://localhost:4000');
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
async function main_streaming() {
|
|
try {
|
|
const streamingResult = await model.generateContentStream(testPrompt);
|
|
for await (const item of streamingResult.stream) {
|
|
console.log('stream chunk: ', JSON.stringify(item));
|
|
}
|
|
const aggregatedResponse = await streamingResult.response;
|
|
console.log('aggregated response: ', JSON.stringify(aggregatedResponse));
|
|
} catch (error) {
|
|
console.error('Error details:', error);
|
|
}
|
|
}
|
|
|
|
// main();
|
|
main_streaming(); |