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

examples: Update openai chat example #542

Closed
wants to merge 2 commits into from
Closed

examples: Update openai chat example #542

wants to merge 2 commits into from

Conversation

tmc
Copy link
Owner

@tmc tmc commented Jan 23, 2024

This updates the openai chat example to use llms.Model.GenerateContent.

_, err = llm.GenerateContent(ctx, []llms.MessageContent{
{
Role: schema.ChatMessageTypeSystem,
Parts: []llms.ContentPart{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned convenience functions on top of GenerateContent in the email

We can also add helpers on other levels, like one for textual message contents:

llms.TextParts(role ChatMessageType, parts ...string) llms.MessageContent

And then your example would be something like:

_, err := llm.GenereteContent(
  ctx, 
  llms.TextParts(schema.ChatMessageTypeSystem, "Hello, I am ..."),
  llms.TextParts(schema.ChatMessageTypeHuman, "What would a ..."))

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the api suggestions, let me mull these over a bit.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a small PR to add a helper in #549

@eliben
Copy link
Collaborator

eliben commented Jan 27, 2024

LMK if you're going to update this PR now that the helpers landed, or if you want my help updating all the examples!

I'll send a PR to update the vertex example and add a googleai example

...

Sent #572

@tmc
Copy link
Owner Author

tmc commented Jan 27, 2024

Please feel free to open PRs to update the other examples, otherwise I can probably get to it later today.

@eliben
Copy link
Collaborator

eliben commented Jan 27, 2024

Please feel free to open PRs to update the other examples, otherwise I can probably get to it later today.

Since the examples don't build without a go.work file anyway and running go mod tidy in CI fails, I would recommend tagging a new version of langchaingo first, and then updating all the examples once to use the newest released version. Otherwise we'll do a lot of busy work updating them now to work with go.work and then again after the tagging to make sure all the go.mod / go.sum files are updated and everything builds properly in CI.

Happy to do the full examples update after a new version is tagged!

@eliben
Copy link
Collaborator

eliben commented Jan 27, 2024

I went ahead and updated the OpenAI examples here: #573

(figured these will be the most likely to be looked at).

There's still leftover work to do on these after the new version is tagged, so I'd really prefer to only do one examples update - but #573 is a step in the right direction!

@tmc
Copy link
Owner Author

tmc commented Jan 27, 2024

@eliben I went ahead and pushed a v0.1.4-alpha.0 tag that can be targetted here, I figure we can get the examples in order and then barring any issues get v0.1.4 released then point the examples at the release tag.

@tmc
Copy link
Owner Author

tmc commented Jan 27, 2024

Subsumed by #573

@tmc tmc closed this Jan 27, 2024
@eliben
Copy link
Collaborator

eliben commented Jan 27, 2024

@tmc with #576 all examples have now been updated to the new APIs and work with the alpha tag you created. I think it's safe to tag v0.1.4 itself now

Once you do, I can update the examples to point to the final tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants