langchaingo icon indicating copy to clipboard operation
langchaingo copied to clipboard

llms: add watsonx

Open h0rv opened this issue 2 years ago • 14 comments

This is using https://github.com/h0rv/go-watsonx to keep the Langchain and API client development seperate (was going to add the logic in llms/watsonx/internal/watsonxclient).

Resolves: https://github.com/tmc/langchaingo/issues/567

PR Checklist

  • [ ] Read the Contributing documentation.
  • [ ] Read the Code of conduct documentation.
  • [ ] Name your Pull Request title clearly, concisely, and prefixed with the name of the primarily affected package you changed according to Good commit messages (such as memory: add interfaces for X, Y or util: add whizzbang helpers).
  • [ ] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • [ ] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. Fixes #123).
  • [ ] Describes the source of new concepts.
  • [ ] References existing implementations as appropriate.
  • [ ] Contains test coverage for new functions.
  • [ ] Passes all golangci-lint checks.

h0rv avatar Jan 28 '24 19:01 h0rv

I have a concern: the watsonx docs are not great yet and do not have the default generation parameter values documented. However, if you don't include them in the payload, they will be defaulted. So, in the options struct for the generation parameters, I had to use pointers (ex *float64 for temperature), with omitempty, to omit it from the payload if it is not specified.

What I need to do now is convert llms.CallOptions to []wx.GenerationOption, but it is difficult because I can check which options are not their default zero values, but for something like Temperature, its range is 0-1 inclusive, so I won't be able to distinguish if the user set it to 0, or if the user did not specify, and it defaulted to 0.

Any thoughts on how to approach this? Thanks!

h0rv avatar Jan 28 '24 20:01 h0rv

I can set the Temperature and similar options to -1, since they are not uint's.

h0rv avatar Jan 28 '24 21:01 h0rv

can you resolve the conflicts here please?

tmc avatar Feb 04 '24 00:02 tmc

How do I fix the CI that is failing? @tmc

h0rv avatar Feb 04 '24 15:02 h0rv

Hi @tmc, I think this is a chicken and the egg problem b/c its pulling the package in each example directory. Should I add it in a separate PR or is there a way to fix? Thanks

go: github.com/tmc/langchaingo/examples/watsonx-llm-example imports
	github.com/tmc/langchaingo/llms/watsonx: module github.com/tmc/langchaingo@latest found (v0.1.4), but does not contain package github.com/tmc/langchaingo/llms/watsonx
go: updates to go.mod needed; to update it:
	go mod tidy
make: *** [Makefile:53: build-examples] Error 1

h0rv avatar Feb 22 '24 02:02 h0rv

A few more conflicts came up -- regarding the example -- in the short term you could include a go.work file in the examples directory and once merged I can clean up the go.work file.

I'd liek to get 0.1.6 tagged today and would love to include this!

tmc avatar Mar 18 '24 23:03 tmc

I rebased this to main and pushed to your branch. Futher, I pushed this to the main repository as the add-watsonx branch which you could reference in your example. I don't belive these lint/build failures are a rebase snafu but please examine.

tmc avatar Mar 18 '24 23:03 tmc

@h0rv Do you need help?

devalexandre avatar Apr 03 '24 13:04 devalexandre

Hi @tmc, I had to bump the version of the watsonx package. Can you push the latest on this branch to the add-watsonx branch on this repo? Then I can update the go.mod in the example, which should fix the CI!

h0rv avatar Apr 03 '24 23:04 h0rv

@devalexandre Do you know how to help fix the CI issue?

h0rv avatar Apr 05 '24 20:04 h0rv

@devalexandre Do you know how to help fix the CI issue?

I yes , can I do PR for you branch?

devalexandre avatar Apr 07 '24 18:04 devalexandre

This is pushed as add-watsonx and I have pointed the example's go.mod at that branch.

tmc avatar Apr 07 '24 19:04 tmc

Great that fixed it - thanks for the help!

h0rv avatar Apr 07 '24 20:04 h0rv

@tmc @devalexandre Ready for a review now, thanks!

h0rv avatar Apr 08 '24 22:04 h0rv

Thanks!

tmc avatar May 10 '24 21:05 tmc