Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't introduce too many helper types for input and output #5

Closed
rakyll opened this issue Dec 13, 2024 · 6 comments
Closed

Don't introduce too many helper types for input and output #5

rakyll opened this issue Dec 13, 2024 · 6 comments
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@rakyll
Copy link

rakyll commented Dec 13, 2024

The current API surface is extremely confusing for GenerateContent because it introduces a wide range of indirection with helper types such as:

- Contents
- Texts
- PartSlice
- ContentSlice

As a user, it's hard for me to understand what's actually supported here without reading the library implementation. Remove all of these types and stick to []Content as inputs and outputs. The following code isn't very hard to write:

GenerateContentStream(ctx, "model", []genai.Content{{Parts: parts}}, nil)

The helper types don't help the average Go user because we like orthogonality and less magic. A little bit verbosity is ok to remove indirection.

@rakyll rakyll added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 13, 2024
@happy-qiao
Copy link
Collaborator

Thanks for the feedback. I'd also like to hear what @eliben and @jba think.

@happy-qiao
Copy link
Collaborator

happy-qiao commented Dec 13, 2024

GenerateContentStream(ctx, "model", []genai.Content{{Parts: parts}}, nil)
GenerateContentStream(ctx, "model", genai.Text("hello").ToContents(), nil)

We can support both. @rakyll What do you think?

@jba
Copy link
Collaborator

jba commented Dec 13, 2024

Is there any Content that's not a list of Parts?
In github.com/google/generative-ai-go/genai, we just use a []Part. What can you do with this API that you can't with that?

@happy-qiao
Copy link
Collaborator

happy-qiao commented Dec 13, 2024

There is Role field in the Content. If we use []Part, how to pass the Role field in? And how to ensure future proof.

@jba
Copy link
Collaborator

jba commented Dec 13, 2024

OK. That isn't really clear from the doc. For example, here is the doc for Text:
image
I wouldn't guess from that that I can only use Text for the user role. If I'm doing a session and want to send a model response back to the model (roleModel), it would be wrong to use Text.

Separately from that, would it simplify things if the argument to GenerateContent was []Content, and you got rid of the XXXSlice types?

@happy-qiao
Copy link
Collaborator

happy-qiao commented Dec 18, 2024

https://pkg.go.dev/google.golang.org/genai#Models.GenerateContent

func (m Models) GenerateContent(ctx context.Context, model string, contents []*Content, config GenerateContentConfig) (GenerateContentResponse, error)

We have changed the API surface change to []*Content type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants