Robert Sinclair

Results 132 comments of Robert Sinclair

this also works: ``` const url = `https://generativelanguage.googleapis.com/v1beta/models?key=${apiKey}`; fetch(url, { method: 'GET', }) .then(response => response.json()) .then(data => { console.log(data); }) .catch(error => { console.error('Error:', error); }); ```

and also this: ```const url = `https://generativelanguage.googleapis.com/v1beta/files?key=${apiKey}`;```

hmm I see the problem.. when doing a POST to upload the file it seems there is a problem: No 'Access-Control-Allow-Origin' header is present on the requested resource. but that...

Yep.. it must be done in the back-end.. in nodejs: https://ai.google.dev/api/files#files_create_text-JAVASCRIPT ``` // Make sure to include these imports: // import { GoogleAIFileManager } from "@google/generative-ai/server"; // import { GoogleGenerativeAI...

an alternative is the inlining: ``` "parts":[ { "inline_data": { "mime_type":"text/plain", "data": "'$(base64 $B64FLAGS a11.txt)'" } } ], ``` the are many mime types accepted including: pdf, png, text, mp3,...

The real problem with the web api is that every time you prompt the model you are forced to send everything (all the history etc). I opened a bug report...

memory? gemini flash has 1M token context! and the base64 inlining works. subsequently (chatting) the image can be removed leaving its answers on the image.. this works perfectly also on...

I just found out that it's even simpler!!! "parts":[{"text": "BASE64DATA"}] it automaticalyy analyze them!! ``` > "contents": [{ > "parts":[{"text": "ewogICJkZXBlbmRlbmNpZXMiOiB7CiAgICAiQGdvb2dsZS1haS9nZW5lcmF0aXZlbGFuZ3VhZ2UiOiAiXjIuNS4wIiwKICAgICJAZ29vZ2xlL2dlbmVyYXRpdmUtYWkiOiAiXjAuMTEuMyIsCiAgICAiY3J5cHRvLWpzIjogIl40LjIuMCIsCiAgICAid3MiOiAiXjguMTcuMCIKICB9Cn0K"},{"text": "Analyze this."}] > }] > }' 2> /dev/null {...

> Awesome @0wwafa I'll test passing the base64 inside the content this weekend, I'll let you know how it goes! after a few more tests (I passed an image) It...

here is how to do it: ```javascript async function fileToGenerativePart(file) { const base64EncodedDataPromise = new Promise((resolve) => { const reader = new FileReader(); reader.onloadend = () => resolve(reader.result.split(',')[1]); reader.readAsDataURL(file); });...