Skip to content

Commit 62c7f0d

Browse files
committed
fix: satisfy mypy and ruff for chat completions API usage
Use ChatCompletionMessageParam and ResponseFormat for OpenAI client calls; apply ruff formatting to tests/test_pipeline.py for CI. Made-with: Cursor
1 parent dfb95c2 commit 62c7f0d

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/regbot/compliance.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
OpenAI,
1212
RateLimitError,
1313
)
14+
from openai.types.chat import ChatCompletionMessageParam
15+
from openai.types.chat.completion_create_params import ResponseFormat
1416

1517
from src.regbot.config import (
1618
DEFAULT_LLM_MODEL,
@@ -237,16 +239,17 @@ def analyze_compliance(
237239
while attempts < max_attempts:
238240
attempts += 1
239241
user = base_user + suffix
240-
messages = [
242+
messages: list[ChatCompletionMessageParam] = [
241243
{"role": "system", "content": system},
242244
{"role": "user", "content": user},
243245
]
246+
json_mode: ResponseFormat = {"type": "json_object"}
244247
try:
245248
try:
246249
resp = client.chat.completions.create(
247250
model=model_name,
248251
messages=messages,
249-
response_format={"type": "json_object"},
252+
response_format=json_mode,
250253
temperature=0.2,
251254
)
252255
except BadRequestError:

tests/test_pipeline.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ def tearDown(self) -> None:
4343

4444
@patch("src.regbot.retrieval.load_sentence_transformer")
4545
@patch("src.regbot.ingestion.load_sentence_transformer")
46-
def test_ingest_retrieve_check_smoke(
47-
self, mock_ingest_load, mock_retrieve_load
48-
) -> None:
46+
def test_ingest_retrieve_check_smoke(self, mock_ingest_load, mock_retrieve_load) -> None:
4947
fake = _FakeSentenceTransformer()
5048
mock_ingest_load.return_value = fake
5149
mock_retrieve_load.return_value = fake

0 commit comments

Comments
 (0)