Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ Free [plan](https://github.com/features/copilot#pricing) includes up to 2,000 co

### Auth Command Help

```

```bash
$ llm github_copilot auth --help
Usage: llm github_copilot auth [OPTIONS] COMMAND [ARGS]...

Expand Down Expand Up @@ -54,6 +53,7 @@ When you run the login command, the plugin will:
Example login output:

```
$ llm github_copilot auth login --help
Usage: llm github_copilot auth login [OPTIONS]

Authenticate with GitHub Copilot to generate a new access token.
Expand All @@ -80,11 +80,10 @@ llm github_copilot auth login --force
```

You can also perform the login process and display the obtained access token and API key without saving them to the LLM keystore or the API key file. This is useful if you want to manually manage these tokens or use them in environment variables:

```bash
llm github_copilot auth login --show-only
```
This will output something like:
```
$ llm github_copilot auth login --show-only

GitHub Copilot: ✓ Authenticated
User: your_github_username
AccessToken: Valid
Expand All @@ -96,14 +95,11 @@ You can set GH_COPILOT_TOKEN or GITHUB_COPILOT_TOKEN to the token value above.
Note: These tokens have NOT been saved to the LLM keystore or API key file.
```

### Authentication Status
```

### Authentication Status

You can check your authentication status with:

```
```bash
$ llm github_copilot auth status
GitHub Copilot: ✓ Authenticated
API Key: Valid, expires 2025-07-15 10:30:00
Expand All @@ -112,14 +108,15 @@ GitHub Copilot: ✓ Authenticated

For more detailed information, use the verbose flag:

```
```bash
$ llm github_copilot auth status --verbose
GitHub Copilot: ✓ Authenticated
User: testuser
AccessToken: Valid, via keystore github_copilot_access_token
AccessToken: ghu_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
API Key: Valid, expires 2025-07-15 10:30:00
API key: abcdef1234567890abcdef1234567890

```

## Usage
Expand Down
17 changes: 14 additions & 3 deletions llm_github_copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ def _fetch_models_data(authenticator: "GitHubCopilotAuthenticator") -> dict:
response.raise_for_status()
return response.json()
except httpx.HTTPStatusError as e:
# Ensure the response body is read before accessing .text,
# in case of chunked error responses.
e.response.read()
error_body_text = e.response.text
print(
f"Error fetching models data (HTTP {e.response.status_code}): {e.response.text}"
f"Error fetching models data (HTTP {e.response.status_code}): {error_body_text}"
)
raise
except httpx.RequestError as e:
Expand Down Expand Up @@ -743,7 +747,10 @@ def _non_streaming_request(
yield api_response.text

except httpx.HTTPStatusError as e:
error_text = f"HTTP error {e.response.status_code}: {e.response.text}"
# Ensure the response body is read before accessing .text
e.response.read()
error_body_text = e.response.text
error_text = f"HTTP error {e.response.status_code}: {error_body_text}"
print(error_text)

yield error_text
Expand Down Expand Up @@ -970,7 +977,11 @@ def _handle_streaming_request(
yield data

except httpx.HTTPStatusError as e:
error_msg = f"HTTP error {e.response.status_code}: {e.response.text}"
# Read the response body before trying to access .text
# This is crucial for streaming responses that error out
e.response.read()
error_body_text = e.response.text
error_msg = f"HTTP error {e.response.status_code}: {error_body_text}"
print(error_msg)
# Print more detailed error information
print(f"Request headers: {headers}")
Expand Down