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