langchaingo
langchaingo copied to clipboard
Add metadata fields in OpenAI calls
PR Checklist
- [x] Read the Contributing documentation.
- [x] Read the Code of conduct documentation.
- [x] 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). - [x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
- [x] 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.
There are OpenAI servers (like LiteLLM) that takes in additional metadata in their requests to log additional information. In LiteLLM's case, the metadata field is used to store information like custom tags and trace ids which will be propagated to Langfuse.
In Langchain Python, there are model_kwargs argument to achieve this, however it's difficult to add kwargs to structs for deserialization in Go. Therefore we'll need to hardcode a metadata field here.