Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 24, 2025

Summary

This PR adds a new --http-log CLI flag to all commands that use LLM inference (run, eval, generate) and removes the dependency on the DEBUG environment variable for HTTP request logging.

Changes Made

Interface Updates

  • Updated azuremodels.Client interface to accept an optional httpLogFile parameter in GetChatCompletionStream
  • Modified AzureClient, MockClient, and UnauthenticatedClient implementations to match the new interface

CLI Flag Addition

Added --http-log flag to three commands:

  • gh models run --http-log /path/to/logfile.log
  • gh models eval --http-log /path/to/logfile.log
  • gh models generate --http-log /path/to/logfile.log

Implementation Details

  • Threaded the HTTP log filename parameter through all command handlers to client calls
  • Replaced os.Getenv("DEBUG") check with httpLogFile != "" condition in HTTP logging code
  • Updated all existing tests to handle the new interface signature
  • Added comprehensive tests to verify the feature works correctly

Backward Compatibility

  • When --http-log flag is not provided, no HTTP logging occurs (same as before when DEBUG was not set)
  • All existing functionality remains unchanged
  • No breaking changes for users

Usage Examples

# Log HTTP requests to a specific file during inference
gh models run --http-log requests.log openai/gpt-4o-mini "Hello world"

# Log HTTP requests during prompt evaluation
gh models eval --http-log eval_requests.log my_prompt.yml

# Log HTTP requests during test generation
gh models generate --http-log generate_requests.log --effort medium prompt.yml

Testing

  • All existing tests pass
  • Added new tests to verify HTTP log parameter passing
  • Added tests to confirm DEBUG environment variable is no longer used
  • Verified CLI flag appears in help output for all three commands

Fixes the issue by providing explicit control over HTTP logging through CLI flags instead of relying on environment variables.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Add a cli flag to take the http logging file name (optional). This file name should be passed all the way to the chat completion streamer and use to log LLM requets. Remove the use the DEBUG environment variable, and instead just check that the filename... Add --http-log CLI flag to replace DEBUG environment variable for HTTP request logging Jul 24, 2025
Copilot AI requested a review from pelikhan July 24, 2025 05:54
@pelikhan
Copy link
Contributor

Add the httpLog flag to the Context instead of arguments

Copy link
Contributor Author

Copilot AI commented Jul 24, 2025

Add the httpLog flag to the Context instead of arguments

Done! I've refactored the HTTP logging to use Context instead of function parameters as requested.

The changes include:

  • Added WithHTTPLogFile() and HTTPLogFileFromContext() helper functions
  • Updated the Client interface to remove the httpLogFile parameter
  • All implementations now extract the HTTP log filename from context
  • All callers set the context value instead of passing the parameter
  • All tests updated and passing

The functionality remains the same for users - the --http-log flag works exactly as before, but the internal implementation is now more Go-idiomatic using context for request-scoped values.

Commit: a46680e

fmt.Fprintf(httpFile, "x-ms-user-agent: github-cli-models\n")
fmt.Fprintf(httpFile, "\n%s\n\n", string(bodyBytes))
defer logFile.Close()
fmt.Fprintf(logFile, "### %s\n", time.Now().Format(time.RFC3339))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Group all writes into a single Fprintf call to execute a single file write operation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Consolidated all the individual fmt.Fprintf calls into a single call to perform one file write operation instead of six separate writes. This improves performance by reducing the number of I/O operations.

Commit: e5e5b8f

Copilot AI requested a review from pelikhan July 24, 2025 07:42
@@ -0,0 +1,50 @@
package run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the file as requested. Commit: d19f533

@@ -0,0 +1,34 @@
package azuremodels
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the file as requested. Commit: d19f533

@pelikhan pelikhan marked this pull request as ready for review July 24, 2025 07:47
Copilot AI review requested due to automatic review settings July 24, 2025 07:47
@pelikhan pelikhan requested a review from a team as a code owner July 24, 2025 07:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces the DEBUG environment variable with explicit --http-log CLI flags for controlling HTTP request logging in LLM inference commands. The implementation moves HTTP log configuration from environment variables to command-line parameters and uses context to pass this configuration through the call chain.

  • Adds --http-log flag to run, eval, and generate commands for explicit HTTP logging control
  • Updates the azuremodels.Client interface to use context-based HTTP log configuration instead of environment variables
  • Replaces os.Getenv("DEBUG") checks with context-based HTTP log file retrieval

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/azuremodels/client.go Adds context helper functions for HTTP log file management
internal/azuremodels/azure_client.go Updates HTTP logging logic to use context instead of DEBUG environment variable
cmd/run/run.go Adds --http-log flag and context integration
cmd/eval/eval.go Adds --http-log flag and context integration
cmd/generate/generate.go Adds --http-log flag and context integration
internal/azuremodels/debug_removal_test.go Tests context-based HTTP logging functionality
cmd/run/http_log_test.go Tests HTTP log parameter passing through the run command

@pelikhan pelikhan merged commit 6dda3c5 into pelikhan/promptpex Jul 24, 2025
0 of 2 checks passed
@pelikhan pelikhan deleted the copilot/fix-0d68a403-cf43-4d99-9fbb-14250f0675fc branch July 24, 2025 07:49
Copilot AI requested a review from pelikhan July 24, 2025 07:49
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.

2 participants