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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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
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

1 participant