8000 feat: add extra_headers to GenerateInputs by markstur · Pull Request #85 · ibm-granite/granite-io · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add extra_headers to GenerateInputs #85

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

Merged
merged 2 commits into from
Apr 3, 2025

Conversation

markstur
Copy link
Collaborator
@markstur markstur commented Mar 20, 2025
  • default_headers is a config setting that openai can use
  • extra_headers works for openai and litellm
  • either of these can be used to get rid of some code specific to an internal provider header and also useful for testing various providers
  • Test is skipped, but can be used for manual testing against alternate server to prove effectiveness
  • Env vars that are used in the test are the standard ones already recognized by the client.

Closes: #39


extra_headers = {"RITS_API_KEY": os.environ.get("OPENAI_API_KEY")}
ret = await be(
GenerateInputs(prompt="what is up?", n=3, extra_headers=extra_headers)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This pattern does not make sense to me. How would this extra_headers value get into the GenerateInputs object? Are we expecting user code to add these headers to the generate_inputs field of every ChatCompletionInputs that this code creates? Why not pass the extra headers to the constructor for the backend object?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

extra_headers is a supported litellm and openai parameter just like the rest of our GenerateInputs:

https://github.com/BerriAI/litellm/blob/main/litellm/llms/openai/completion/transformation.py#L143
https://github.com/openai/openai-python/blob/main/src/openai/resources/completions.py#L75

So based on the design of GenerationInputs starting with LiteLLM params, I think this fits. I added it here:

https://github.com/ibm-granite/granite-io/pull/85/files#diff-5cf58a09d2dc142379084a9c674f83bd44df730d801f25216ef397938967b564R172

When **inputs is applied to the completion calls, it just works for both openai and litellm completions.

I don't have a use case that requires yet another param for backend construction (although I can see why this could have been). The extra_headers support in the litellm and openai adds another useful param for granite-io users and also cleans up this issue where I had some special-case code for RITS. Now that can be done as part of extra_headers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@frreiss Oh I see. I'm doing this all from the backend perspective and not from an I/O processor. I'll take another look at that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@frreiss I made the openai backend forward a default_headers client contructor param. This is only applicable for openai but fits the pattern you mentioned.

Litellm doesn't follow that pattern. No construct-time params are used -- just generate time. This still works as the original approach I followed using generate params that are openai+litellm (defacto standard).

Not planning to make either of these work where they are not wanted (e.g. transformers or stuff default_headers into liteLLM) but we could backlog that if you think we should be doing that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a big deal, I just won't use this parameter if it isn't an argument of the constructor for the various subclasses of Backend. If I need such functionality, I'll add it as an argument of the constructor for the appropriate subclass.

* extra_headers works for openai and litellm and can be
  used to get rid of some code specific to an internal
  provider header.

* Test is skipped, but can be used for manual testing
  against altenate server to prove effectiveness

* Env vars that are used in the test are the standard ones already
  recognized by the client.

Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
* openai users can use aConfig to pass default_headers to
  the openai client as would be expected
* default_headers does not apply to other backend
* extra_headers as a generate param works for both openai and litellm

These are normal params for these clients.  No renaming or swizzling.

Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
Copy link
Collaborator
@frreiss frreiss left a comment

Choose a reason for hiding this comment

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

LGTM

@frreiss frreiss merged commit 2710572 into ibm-granite:main Apr 3, 2025
10 checks passed
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.

Add extra_headers support for OpenAI for specific variants of that API
2 participants
0