llms: add watsonx
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, Yorutil: 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-lintchecks.
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!
I can set the Temperature and similar options to -1, since they are not uint's.
can you resolve the conflicts here please?
How do I fix the CI that is failing? @tmc
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
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!
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.
@h0rv Do you need help?
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!
@devalexandre Do you know how to help fix the CI issue?
@devalexandre Do you know how to help fix the CI issue?
I yes , can I do PR for you branch?
This is pushed as add-watsonx and I have pointed the example's go.mod at that branch.
Great that fixed it - thanks for the help!
@tmc @devalexandre Ready for a review now, thanks!
Thanks!