google / generative-ai-go

Go SDK for Google Generative AI
Apache License 2.0
487 stars 47 forks source link

session.SendMessage without any parts. #158

Open LGXerxes opened 1 week ago

LGXerxes commented 1 week ago

Description of the feature request:

Ability to "complete" a history/session without needing to specify the last message.

What problem are you trying to solve with this feature?

Now you would need to specify the last message and insert it into in SendMessage(). Seems pointless if you already have the entire history set. And SendMessage appends it to the history in the end anyway.

unsure how the api handles the requests as any message in the SendMessage gets given the user role. But you are expected to pass the result of function calls through here. Have not seen it impacted.

Any other information you'd like to share?

adding a check if any parts are send with seems to "resolve" the issue. Normally it returns a 400 when no parts are send, possibly due to an empty user part in the request.

// SendMessage sends a request to the model as part of a chat session.
func (cs *ChatSession) SendMessage(ctx context.Context, parts ...Part) (*GenerateContentResponse, error) {
    // Call the underlying client with the entire history plus the argument Content.

        // ! adding check before adding new content
    if len(parts) > 0 {
        cs.History = append(cs.History, newUserContent(parts))
    }
    req, err := cs.m.newGenerateContentRequest(cs.History...)
jba commented 1 week ago

I'm not sure I understand what you're asking. What do you mean by the last message?

LGXerxes commented 6 days ago

Last message just means what you would pass to SendMessag.

currently if you have a history with all messages already, or would want to replay a history. You need to extract the last message from the history and send it to SendMessage.

other sdk's allow you to complete a history without explicitly sending a new message.

Did not know that the response of the llm is added to the history. My current system does not re-use the session, as I have my own "history/conversation" due to multiple llm integrations.

My request/comment was just if it would make sense to be able to complete a created history, instead of needing to send a user message. ^ from documentation the response of a function call should also be passed to SendMessage, but doesn't it matter that the message will have the user role? (any parts passed to SendMessage become a userContent?)

jba commented 6 days ago

I still don't understand what you mean by "complete." The history is always the complete record of the session. Just use it however you want, whenever you want.

Can you give an example?