mhawksey / GeminiApp

GeminiApp is a library that allows integration to Google's Gemini API in your Google Apps Script projects. It allows for mutli-modal prompts, structured conversations and function calling
Apache License 2.0
67 stars 4 forks source link

multimodal call with an drive id file and text throws error #3

Closed fwermus closed 7 months ago

fwermus commented 7 months ago

I am able to use gemini ai rest api, but when I try library it fails

code: GeminiApp.init(LOCATION_ID, PROJECT_ID); const file = DriveApp.getFileById(fileId); var resp = GeminiApp.newChat() .addContent(prompt) .addDriveData("pdf file: ", file) .run();

Request to Gemini failed with response code 400 - [{ "error": { "code": 400, "message": "Please ensure that multiturn requests alternate between user and model.", "status": "INVALID_ARGUMENT" } } ]

but It works with

GeminiApp.init(LOCATION_ID, PROJECT_ID); const file = DriveApp.getFileById(fileId); var resp = GeminiApp.newChat() .addDriveData(prompt, file) .run();

need some information why the first option throws error

My escenario is that I have more than one file and a prompt. Then, I am confused where to put prompt for all those files.

thanks in advance.

mhawksey commented 7 months ago

Hi,

Gemini expects a very rigid turn based approach alternating between user and model response. Currently looking for a better way for the library to handle this so that any user content is combined in the payload. For now you can include as much prompt information into the prompt using .addDriveData(prompt, file). Let me know if still unclear

Thanks