File size: 943 Bytes
66e3a81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const axios = require('axios');
require('dotenv').config();

const API_KEY = process.env.LLM_API_KEY;
const MODEL = 'gemini-flash-latest';
const URL = `https://generativelanguage.googleapis.com/v1beta/models/${MODEL}:generateContent?key=${API_KEY}`;

async function test() {
    console.log(`Testing LLM with Model: ${MODEL}`);
    console.log(`URL: ${URL.replace(API_KEY, 'HIDDEN_KEY')}`);

    const payload = {
        contents: [{
            parts: [{ text: "Hello, tell me a joke." }]
        }]
    };

    try {
        const response = await axios.post(URL, payload, {
            headers: { 'Content-Type': 'application/json' }
        });
        console.log("Success!");
        console.log(response.data.candidates[0].content.parts[0].text);
    } catch (error) {
        console.error("Error Status:", error.response?.status);
        console.error("Error Data:", JSON.stringify(error.response?.data, null, 2));
    }
}

test();