It is currently 21 April 2025, 13:05 Advanced search

TEST CON GEMINI AI STUDIO vs INDE

Domande e risposte su come utilizzare Instant Developer Foundation al meglio

TEST CON GEMINI AI STUDIO vs INDE

Postby Thema » 3 April 2025, 11:48

buongiorno,
sto testando un semplice interrogazione IA da INDE
passando IDMAP (map) sembra che le coppie chiave valore nei dati POST in GETHTTP non venga riconosciuto correttamente già in compilazione
ho provato a passargli una stringa formattata (headerString), ma ricevo errore 400 bad request in esecuzione.

Come possiamo risolvere il passaggio corretto degli ID_HEADERS a GETHTTP ?

il codice sottostante può essere utile a tutti coloro che vogliono cimentarsi :)

Code: Select all
string prompt //
// se avete una vostra chiave da GEMINI AI STUDIO
string apiKey = "YOUR _API_KEY"
string url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-pro-exp-03-25:generateContent"

string baseURL = url

IDMap data = new()
IDArray contents = new()
IDArray parts = new()
IDMap textPart = new()

textPart.setValue("text", prompt)
int partSize = 0
parts.setObject(partSize, textPart)
partSize = partSize + 1

IDMap content = new()
content.setObject("parts", parts)
int contentSize = 0
contents.setObject(contentSize, content)
contentSize = contentSize + 1

data.setObject("contents", contents)
string requestBody = JSON.stringify(data)
int contentLength = length(requestBody)


IDMap headers = new()
headers.setValue("Content-Type", "application/json")
headers.setValue("x-goog-api-key", apiKey)
headers.setValue("Content-Length", toString(contentLength))

//// HO PROVATO A CONCATENARE MA SE METTO headerstring al posto di headers nell'ID_HEADERS ricevo errore 400 BAD REQUEST
//string headerString = "Content-Type: application/json\n" + "x-goog-api-key:" + apiKey + "\n" + toString(contentLength)

// COMPILANDO da errore in compilazione il GETHTTP si aspetta altro
IDMap map = new()
map.setValue("ID_TYPE", "POST")
map.setValue("ID_BODY", requestBody)
map.setValue("ID_HEADERS", headers)

string res = getHTTP(baseURL, map, ...)

return res
Antonio Avitabile (freelance)
User avatar
Thema
 
Posts: 770
Joined: 6 February 2013, 13:46
Location: Parma

Re: TEST CON GEMINI AI STUDIO vs INDE

Postby eurekapv » 4 April 2025, 17:16

Gli Header da passare a ID_HEADERS io li ho sempre concatenati con chr(10) come vedi in figura
e ha sempre funzionato

Screenshot 2025-04-04 191320.png
Screenshot 2025-04-04 191320.png (15.74 KiB) Viewed 193 times


Forse c'e' un errore in questo punto ?

textPart.setValue("text", prompt)
int partSize = 0
parts.setObject(partSize, textPart)
partSize = partSize + 1

..... quale è il JSON del Body che si aspetta ?
Alchimisti Lab by Cavallini Pietro
https://www.alchimistilab.it

Image
User avatar
eurekapv
 
Posts: 2450
Joined: 2 November 2010, 22:16
Location: Vigevano


Return to Tips & Tricks - Foundation

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 54 guests

cron