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

Add Request Header Exlude Option For Debug logging #1231

Closed

Conversation

case-k-git
Copy link

@case-k-git case-k-git commented Mar 13, 2024

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

Changes being requested

fix this issue
#1082
#1196

Sample code to reproduce

$ export OPENAI_LOG=debug
from openai import OpenAI
import os

client = OpenAI()
response = client.chat.completions.with_raw_response.create(
    messages=[{
        "role": "user",
        "content": "Say this is a test",
    }],
    model="gpt-3.5-turbo",
    extra_headers={"Authorization": f'Bearer {os.environ.get("OPENAI_API_KEY")}'},
)
print(response)
poetry run python openai_lib/sample3.py
[2024-03-13 19:23:39 - httpx:80 - DEBUG] load_ssl_context verify=True cert=None trust_env=True http2=False
[2024-03-13 19:23:39 - httpx:146 - DEBUG] load_verify_locations cafile='/Users/keisuke.taniguchi/Library/Caches/pypoetry/virtualenvs/openai-lib-wrcub86L-py3.11/lib/python3.11/site-packages/certifi/cacert.pem'
[2024-03-13 19:23:39 - openai._base_client:435 - DEBUG] Request options: {'method': 'post', 'url': '/chat/completions', 'headers': {'Authorization': 'Bearer <api-key>', 'X-Stainless-Raw-Response': 'true'}, 'files': None, 'json_data': {'messages': [{'role': 'user', 'content': 'Say this is a test'}], 'model': 'gpt-3.5-turbo'}}
[2024-03-13 19:23:39 - httpx:1026 - INFO] HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"
[2024-03-13 19:23:39 - openai._base_client:887 - DEBUG] HTTP Request: POST https://api.openai.com/v1/chat/completions "200 OK"
<APIResponse [200 OK] type=<class 'openai.types.chat.chat_completion.ChatCompletion'>>

Additional context & links

https://github.com/openai/openai-python/blob/main/src/openai/_models.py#L398
https://github.com/openai/openai-python/blob/main/tests/test_models.py#L510

@case-k-git case-k-git requested a review from a team as a code owner March 13, 2024 10:52
@jkondek1
Copy link

Hi guys, could this be reviewed any time soon? Also, I tried to add a filter to the openai logger and whatever I do the openai logger seems to be ignoring the applied filter/new handler. Would could be the reason?

@RobertCraigie
Copy link
Collaborator

thanks for the PR and sorry for the delay, this was fixed in #1850

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.

3 participants