generative-ai-go
generative-ai-go copied to clipboard
ChatSession enforces last message to be user content
Description of the bug:
GenerateContent RPC allows a list of contents to generate a new response. In this package, ChatSession limits this API by enforcing using to provide a history (a list of contents) and a user parts.
chat := model.StartChat()
chat.History = contents
model.StartChat().SendMessage(r.Context(), parts...) // where parts will have a user role
This situation is breaking major use cases such as a third party assistant to participate into the conversation with a different role, or replaying an existing conversation for evaluation reasons, or translating an incoming chat payload into a Gemini API call (e.g. writing an OpenAI to Gemini proxy).
Additionally, SendMessage introduces new semantics to the API even though it's a GenerateContent call.
Actual vs expected behavior:
Instead of creating intermediate concepts and adding new semantics that will eventually cause confusion, provide a thin implementation of GenerateContent and GenerateContentStream identical to the proto. The majority of the developers will be spending time in their prompting pipeline and making these calls and the end of a very long chain. We shouldn't try to over-optimize the looks and ergonomics of these calls.
I'll file a similar issue on the other language clients, e.g. Python, to ensure that we are spending a lot of cycles on these intermediate convinces.
Any other information you'd like to share?
No response
We discussed that this kind of change will require cross-language decisions to be made. Let's not take any immediate actions right now. I'll update this issues as soon as I can.
push, The parts parameter length check in the chat.go file is not properly implemented https://github.com/google/generative-ai-go/blob/274f56b82ee2d788fe2db398ce0bc8cc4aed64c6/genai/chat.go#L51
We recommend switching to the new client, google.golang.org/genai, and filing bugs on its issue tracker.