diff --git a/docs/concepts/logging.md b/docs/concepts/logging.md index f06a1c4..9b13de2 100644 --- a/docs/concepts/logging.md +++ b/docs/concepts/logging.md @@ -1,4 +1,4 @@ -In order to see the requests made to OpenAI and the responses, you can set logging to DEBUG. This will show the requests and responses made to OpenAI. This can be useful for debugging and understanding the requests and responses made to OpenAI. +In order to see the requests made to OpenAI and the responses, you can set logging to DEBUG. This will show the requests and responses made to OpenAI. This can be useful for debugging and understanding the requests and responses made to OpenAI. I would love some contributions that make this a lot cleaner, but for now this is the fastest way to see the prompts. ```python import instructor @@ -7,6 +7,7 @@ import logging from pydantic import BaseModel + # Set logging to DEBUG logging.basicConfig(level=logging.DEBUG) @@ -24,5 +25,31 @@ user = client.chat.completions.create( messages=[ {"role": "user", "content": "Extract Jason is 25 years old"}, ], -) -``` +) # type: ignore + +""" +DEBUG:httpx:load_ssl_context verify=True cert=None trust_env=True http2=False +DEBUG:httpx:load_verify_locations cafile='/Users/jasonliu/dev/instructor/.venv/lib/python3.11/site-packages/certifi/cacert.pem' +DEBUG:instructor:Patching `client.chat.completions.create` with mode= +DEBUG:instructor:max_retries: 1 +DEBUG:openai._base_client:Request options: {'method': 'post', 'url': '/chat/completions', 'files': None, 'json_data': {'messages': [{'role': 'user', 'content': 'Extract Jason is 25 years old'}], 'model': 'gpt-3.5-turbo', 'function_call': {'name': 'UserDetail'}, 'functions': [{'name': 'UserDetail', 'description': 'Correctly extracted `UserDetail` with all the required parameters with correct types', 'parameters': {'properties': {'name': {'title': 'Name', 'type': 'string'}, 'age': {'title': 'Age', 'type': 'integer'}}, 'required': ['age', 'name'], 'type': 'object'}}]}} +DEBUG:httpcore.connection:connect_tcp.started host='api.openai.com' port=443 local_address=None timeout=5.0 socket_options=None +DEBUG:httpcore.connection:connect_tcp.complete return_value= +DEBUG:httpcore.connection:start_tls.started ssl_context= server_hostname='api.openai.com' timeout=5.0 +DEBUG:httpcore.connection:start_tls.complete return_value= +DEBUG:httpcore.http11:send_request_headers.started request= +DEBUG:httpcore.http11:send_request_headers.complete +DEBUG:httpcore.http11:send_request_body.started request= +DEBUG:httpcore.http11:send_request_body.complete +DEBUG:httpcore.http11:receive_response_headers.started request= +DEBUG:httpcore.http11:receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Mon, 12 Feb 2024 14:55:45 GMT'), (b'Content-Type', b'application/json'), (b'Transfer-Encoding', b'chunked'), (b'Connection', b'keep-alive'), (b'access-control-allow-origin', b'*'), (b'Cache-Control', b'no-cache, must-revalidate'), (b'openai-model', b'gpt-3.5-turbo-0613'), (b'openai-organization', b'scribe-ai'), (b'openai-processing-ms', b'483'), (b'openai-version', b'2020-10-01'), (b'strict-transport-security', b'max-age=15724800; includeSubDomains'), (b'x-ratelimit-limit-requests', b'10000'), (b'x-ratelimit-limit-tokens', b'2000000'), (b'x-ratelimit-remaining-requests', b'9999'), (b'x-ratelimit-remaining-tokens', b'1999975'), (b'x-ratelimit-reset-requests', b'6ms'), (b'x-ratelimit-reset-tokens', b'0s'), (b'x-request-id', b'req_f0fa476897ae165fc50fa90b7968595b'), (b'CF-Cache-Status', b'DYNAMIC'), (b'Set-Cookie', b'__cf_bm=e2_yCrwo4frh6Oq4ZufCEhNJ4lSGJ2.MMtk45X8lrMM-1707749745-1-AfWk8CyACc7aZo6GpCI82FBfI/wmPEFZLNO/Cr3eavTW3xKVFCS7G9jvwYTFLXjJr0cttYsXeLAnjwipw18R0Vo=; path=/; expires=Mon, 12-Feb-24 15:25:45 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None'), (b'Set-Cookie', b'_cfuvid=PyVVCGSMxTg1p.woYvHVVC9E3n69faOs5FOxaDdjXOM-1707749745711-0-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None'), (b'Server', b'cloudflare'), (b'CF-RAY', b'8545aca30c1fa22f-YYZ'), (b'Content-Encoding', b'gzip'), (b'alt-svc', b'h3=":443"; ma=86400')]) +INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK" +DEBUG:httpcore.http11:receive_response_body.started request= +DEBUG:httpcore.http11:receive_response_body.complete +DEBUG:httpcore.http11:response_closed.started +DEBUG:httpcore.http11:response_closed.complete +DEBUG:openai._base_client:HTTP Request: POST https://api.openai.com/v1/chat/completions "200 OK" +DEBUG:httpcore.connection:close.started +DEBUG:httpcore.connection:close.complete +""" +``` \ No newline at end of file diff --git a/examples/logging/run.py b/examples/logging/run.py index 3803533..01b5ace 100644 --- a/examples/logging/run.py +++ b/examples/logging/run.py @@ -22,7 +22,7 @@ user = client.chat.completions.create( messages=[ {"role": "user", "content": "Extract Jason is 25 years old"}, ], -) +) # type: ignore """ DEBUG:httpx:load_ssl_context verify=True cert=None trust_env=True http2=False diff --git a/mkdocs.yml b/mkdocs.yml index bec14f6..117e8a5 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -140,6 +140,7 @@ nav: - Raw Response: 'concepts/raw_response.md' - FastAPI: 'concepts/fastapi.md' - Caching: 'concepts/caching.md' + - Logging: 'concepts/logging.md' - Distillation: "concepts/distillation.md" - Union: 'concepts/union.md' - Alias: 'concepts/alias.md'