Skip to content
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

added cleanObject to defaultHeaders #587

Closed
wants to merge 1 commit into from

Conversation

haouarihk
Copy link

  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

adding cleanObject to defaultHeaders,
this can help if people wants to remove header properties, from the configuration, by setting them to be empty string, or undefined. instead of it sending that useless value.

Additional context & links

in my case, where i need it, is that i'm using a middle tool called langchainjs, which allows for setting defaultHeader as a property, but i can't reach the class to override that getDefaultHeader function.
and i want to delete headers like
X-stainless-* because they get blocked in some openai capable apis

Thanks for all the hardwork you put into this awsome tool

@haouarihk haouarihk requested a review from a team as a code owner December 20, 2023 14:29
@rattrayalex
Copy link
Collaborator

I'm curious for more context here.

  1. Which headers specifically are you trying to block?
  2. Where are they coming from?
  3. Why do you need to block them? What problems do they cause specifically?
  4. Are they being set to empty string or undefined?

@haouarihk
Copy link
Author

haouarihk commented Dec 21, 2023

I'm curious for more context here.

  1. Which headers specifically are you trying to block?
  2. Where are they coming from?
  3. Why do you need to block them? What problems do they cause specifically?
  4. Are they being set to empty string or undefined?

Trying to block the platform headers like.
X-stainless-os and the others.
For the reason of some providers whitelist certain headers but not others like x-stainless. But other than that, they have the same api structure.

One example of that is mistral.ai

If i set them to undefined from the config. I don't want them being sent in the headers as undefined

@rattrayalex
Copy link
Collaborator

Ah, I see – if you do this:

const client = new OpenAI({
  defaultHeaders: {
    'X-Stainless-OS': undefined
  }
})

we should be not sending that header at all, but today in at least some environments we'll send the header X-Stainless-OS: undefined which is not intended behavior.

I'm not sure this is the exact fix we'd want – I'd expect '' to still send the header, for example, and we'd probably want to use our hasOwn helper – but I do expect we'll resolve this shortly.

We also need to address case-sensitivity for our headers, which we may do as part of this change.

Regardless, thank you for raising the issue and for the contribution!

@rattrayalex
Copy link
Collaborator

Note you can work around this for now by setting the default headers to null instead of undefined, which I believe we do filter out today.

I've implemented this fix internally with a different approach, so I'll close this PR, but thank you again!

@haouarihk
Copy link
Author

an easy way to solve that case sensitivity is to turn all header keys to lowercase on the merging step, and in the same step save the casing in a hashmap.
after its done, loop over the hashmap to get the casing back on the headers.

@rattrayalex
Copy link
Collaborator

Yes, that's the approach we're taking.

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.

None yet

2 participants