Skip to content

Support arbitrary extra keyword arguments in requests. - #600

Closed
q-x-iao wants to merge 1 commit into
openai:mainfrom
q-x-iao:main
Closed

q-x-iao wants to merge 1 commit into
openai:mainfrom
q-x-iao:main

Conversation

@q-x-iao

@q-x-iao q-x-iao commented Sep 4, 2023

Copy link
Copy Markdown

Hi! I'm working on a project that requires proxied access to OpenAI APIs. For that to work correctly, we need to customize both the auth and verify arguments in (synchronous) requests, which isn't possible with the current client library.

This pull request introduces a fairly general mechanism to pass arbitrary extra keyword arguments in requests. Since synchronous and asynchronous requests use different libraries under the hood (requests vs aiohttp), they have separate sets of arguments. For the project I'm working on we'd do something like:

openai.request_extra_kwargs = {
  'auth': ...,
  'verify': ...,
}

An alternative to this is to provide the same API to customize auth and verify for both synchronous and asynchronou requests. However, the API of requests and aiohttp are quite different, so I'd like to propose this simpler alternative first.

This is similar to #562, but is more general and uses module-level variables - the idea is that a certain user will use the same set of extra arguments for all OpenAI requests, in much the same way as they may customize openai.api_base for all their OpenAI requests.

This fixes #561.

Thanks!

@q-x-iao

q-x-iao commented Sep 5, 2023

Copy link
Copy Markdown
Author

Just found out that what I'm trying to do is already possible with openai.requestssession:

import openai
import requests
def make_session():
  s = requests.Session()
  s.auth = ...
  s.verify = ...
openai.requestssession = make_session

For async requests, there's similarly openai.aiosession.

So I'll close this PR now.

@q-x-iao q-x-iao closed this Sep 5, 2023
stainless-app Bot pushed a commit that referenced this pull request Mar 27, 2025
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.

Hope support choose if SSL verify on ChatCompletion.create

1 participant