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

Trace raw request and response #50

Merged
merged 4 commits into from
Jan 14, 2024
Merged

Trace raw request and response #50

merged 4 commits into from
Jan 14, 2024

Conversation

wkok
Copy link
Owner

@wkok wkok commented Jan 12, 2024

Closes #49

This PR ads the ability to supply a trace function in :options that will be called with the raw maps of the request and response for allowing capturing tracing information for example:

(create-chat-completion {:model    "gpt-3.5-turbo"
                         :messages [{:role "system" :content "You are a helpful assistant."}
                                    {:role "user" :content "Who won the world series in 2020?"}
                                    {:role "assistant" :content "The Los Angeles Dodgers won the World Series in 2020."}
                                    {:role "user" :content "Where was it played?"}]}
                        {:trace (fn [request response]
                                   (println (:body response)))})

prints:

{
  "id": "chatcmpl-8gHB7Il500UxZPChGAZHtklLWTS8T",
  "object": "chat.completion",
  "created": 1705086501,
  "model": "gpt-3.5-turbo-0613",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The 2020 World Series was played at Globe Life Field in Arlington, Texas."
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 53,
    "completion_tokens": 17,
    "total_tokens": 70
  },
  "system_fingerprint": null
}


@wkok wkok changed the title Logger Trace raw request and response Jan 12, 2024
@aviflax
Copy link

aviflax commented Jan 14, 2024

This looks great. Thank you!

BTW what about accessing the response status line and headers? I don’t know if I personally need them right now, but I’d think it’d be intuitive and reasonable for the entire response to be provided to the trace function, rather than just the body.

@wkok
Copy link
Owner Author

wkok commented Jan 14, 2024

Good suggestion, I've updated the trace function (& PR description) accordingly

@wkok wkok merged commit 72ceba6 into main Jan 14, 2024
1 check passed
@wkok wkok deleted the logger branch January 14, 2024 18:58
@aviflax
Copy link

aviflax commented Jan 14, 2024

Looks great — thank you!

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.

A way to get the raw response?
2 participants