getzep / zep

Zep: Long-Term Memory for ‍AI Assistants.
https://docs.getzep.com
Apache License 2.0
2.15k stars 321 forks source link

Add Support for Custom Headers in LLM Requests #169

Open k1ng opened 10 months ago

k1ng commented 10 months ago

Feature Description

To integrate and proxy requests from Zep through Portkey.ai, we need the ability to add custom headers to our requests to the LLM. Please note that Portkey.ai already has an integration with Langchain.

Portkey.ai requires certain specific headers to be passed in every API call, which can be found in their documentation: https://docs.portkey.ai/how-portkey-works/portkey-headers

Value of Feature

This feature will allow logging Zep's requests to LLM and calculating the cost of LLM calls as a part of Zep-Portkey.ai integration. Custom headers support could also be useful for other potential integrations and use-cases.

Possible Implementation

We could provide the ability to set custom headers through environment variables, a .env file, or the config.yaml file. This provides flexibility in choosing how to supply custom headers, depending on user preferences or security requirements.

Thank You.

danielchalef commented 10 months ago

Hey @k1ng , cool idea. Would you be open to contributing this functionality to the project? If so, I suggest the following approach:

Config

  1. Add the custom header option to ServerConfig: https://github.com/getzep/zep/blob/90cd50d73995f2bcf8fa8493cd0a03aca3d15f7e/config/models.go#L44
  2. Add an example and comment to the config.yaml file. Comment out the config option as a default. https://github.com/getzep/zep/blob/90cd50d73995f2bcf8fa8493cd0a03aca3d15f7e/config.yaml#L41
  3. OR if the header will include a secret, it should not be in the config file. Remove (2) above, and add the option to https://github.com/getzep/zep/blob/90cd50d73995f2bcf8fa8493cd0a03aca3d15f7e/config/config.go#L17

You may want to add two config options: One the header name and the other a secret, with the first being added in two above, but the secret kept to an environment variable only.

Add the header middleware

Create a new middleware function that pulls the header from appState.Config and adds it to the HTTP Header. See this example: https://github.com/getzep/zep/blob/90cd50d73995f2bcf8fa8493cd0a03aca3d15f7e/pkg/server/middleware.go#L12

Add the middleware to the Router

See here: https://github.com/getzep/zep/blob/90cd50d73995f2bcf8fa8493cd0a03aca3d15f7e/pkg/server/routes.go#L44

Happy to answer any questions. Also, happy to review a rough PR and work with you to finalize it.

k1ng commented 10 months ago

Hi @danielchalef,

Thank you very much for your detailed explanation, it is appreciated. I'd like to contribute, but unfortunately, I lack the necessary experience with Go to make a pull request at this time. I will definitely keep your guidance in mind and hopefully, in the future, I will be able to make more substantial contributions to the project.

SpencerWightman commented 3 months ago

I'd like to work on this issue. Could you please assign it to me?