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

[Feature]: Azure, OpenAI - Log Response Headers #1724

Closed
ishaan-jaff opened this issue Jan 31, 2024 · 10 comments
Closed

[Feature]: Azure, OpenAI - Log Response Headers #1724

ishaan-jaff opened this issue Jan 31, 2024 · 10 comments
Labels
enhancement New feature or request

Comments

@ishaan-jaff
Copy link
Contributor

The Feature

User request

Motivation, pitch

cc @Manouchehri

Twitter / LinkedIn details

No response

@ishaan-jaff ishaan-jaff added the enhancement New feature or request label Jan 31, 2024
@Manouchehri
Copy link
Collaborator

Probably wouldn't hurt to do for other providers as well. Off the top of my head, I don't think any popular LLM API is returning private/sensitive content in their response headers.

@ishaan-jaff
Copy link
Contributor Author

Starting with just OpenAI/Azure because we're going to need to move all OpenAI python calls

from chat.completions.create
to chat.completions.with_raw_response.create

@ishaan-jaff
Copy link
Contributor Author

Tradeoffs of this move: openai/openai-python#416 (comment) It looks like with_raw_response will currently return an object with only sync methods

@ishaan-jaff
Copy link
Contributor Author

another approach is using: https://www.python-httpx.org/advanced/#event-hooks

@ishaan-jaff
Copy link
Contributor Author

Useful details here: langchain-ai/langchain#9601

@Manouchehri
Copy link
Collaborator

Feedback from Langfuse's Marc (when I asked if he thought it was a good idea to also feed upstream traces to a different project):

I'd suggest to add it to the metadata on the same generation in Langfuse though. Splitting the data into two projects makes this a kind of "exotic" setting that not many users will benefit from

I'm inclined to agree with him, not a good idea if it's just me asking.

For logging the request and response metadata, can we do it like this?

https://github.com/orgs/langfuse/discussions/1070#discussioncomment-8369918

{
  "request": {
    "headers": {
      "host": "example.com"
    },
    "url": "https://api.openai.com/v1/chat/completions"
  },
  "response": {
    "headers": {
      "age": "1337"
    },
    "status": 200
  }
}

@ishaan-jaff
Copy link
Contributor Author

Attempt 1 PR: #1873
TLDR: we can't use chat.completions.with_raw_response.create it's not async and impacts throughput

@Manouchehri
Copy link
Collaborator

Hmm, I noticed that Sentry is able to log the response object/headers. Maybe we can steal/borrow their method of doing it?

@Manouchehri
Copy link
Collaborator

Manouchehri commented May 16, 2024

This is possible to do with: https://til.simonwillison.net/httpx/openai-log-requests-responses

@ishaan-jaff
Copy link
Contributor Author

we do this now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants