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: 14 additions & 5 deletions openqa-llm-investigate
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def _perform_investigation(
llm_url: str,
llm_model: str,
timeout: int,
llm_token: str | None,
) -> None:
# Check for existing LLM investigation comments
comments = fetch_json(client, f"{base_url}/api/v1/jobs/{job_id}/comments", default=[])
Expand Down Expand Up @@ -306,8 +307,10 @@ Provide exactly 3 sentences answering:
"temperature": 0.3,
}

headers = {"Authorization": f"Bearer {llm_token}"} if llm_token else {}

try:
res = client.post(llm_url, json=req, timeout=timeout)
res = client.post(llm_url, json=req, headers=headers, timeout=timeout)
res.raise_for_status()
res_json = res.json()
llm_response = res_json["choices"][0]["message"]["content"]
Expand Down Expand Up @@ -357,6 +360,15 @@ def investigate(
retries: Annotated[int, typer.Option("--retries", help="Number of retries on retry-worthy HTTP responses")] = int(
os.environ.get("LLM_RETRIES", "7")
),
llm_url: Annotated[
str, typer.Option("--llm-url", envvar="LLM_API_URL", help="URL for the LLM API endpoint")
] = os.environ.get("LLM_API_URL", "http://localhost:8080/v1/chat/completions"),
llm_model: Annotated[
str, typer.Option("--llm-model", envvar="LLM_MODEL", help="The LLM model to use")
] = os.environ.get("LLM_MODEL", "gemma-4-26B-A4B-it"),
llm_token: Annotated[
str | None, typer.Option("--llm-token", envvar="LLM_API_TOKEN", help="API token for authentication")
] = os.environ.get("LLM_API_TOKEN"),
) -> None:
setup_logging(verbose, quiet)
base_url, job_id = parse_job_url(job_url)
Expand All @@ -365,12 +377,9 @@ def investigate(
log.error("Invalid job ID: %s", job_id)
sys.exit(1)

llm_url = os.environ.get("LLM_API_URL", "http://localhost:8080/v1/chat/completions")
llm_model = os.environ.get("LLM_MODEL", "gemma-4-26B-A4B-it")

transport = RetryTransport(retries=retries)
with httpx.Client(transport=transport, headers={"User-Agent": USER_AGENT}) as client:
_perform_investigation(client, base_url, job_id, force, dry, llm_url, llm_model, timeout)
_perform_investigation(client, base_url, job_id, force, dry, llm_url, llm_model, timeout, llm_token)


if __name__ == "__main__":
Expand Down
13 changes: 13 additions & 0 deletions tests/test_openqa_llm_investigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,19 @@ def test_investigate_cmd(mocker: MockerFixture) -> None:
assert "BISECT: YES" in mock_post.call_args[0][2]


def test_investigate_cmd_with_token(mocker: MockerFixture) -> None:
mock_post = mocker.patch("llm_investigate.post_comment")
mocker.patch("builtins.print")
mocker.patch.dict("os.environ", {"LLM_API_TOKEN": "my-secret-token"})
client = setup_mock_client(mocker)

llm_investigate.investigate("123", llm_token="my-secret-token")

client.post.assert_called_once()
assert client.post.call_args[1]["headers"] == {"Authorization": "Bearer my-secret-token"}
mock_post.assert_called_once()


def test_investigate_cmd_passed_job(mocker: MockerFixture) -> None:
mock_print = mocker.patch("builtins.print")
setup_mock_client(mocker, overrides={"api/v1/jobs": {"job": {"id": 123, "result": "passed"}}})
Expand Down
Loading