Skip to content

Commit 16f1304

Browse files
committed
tidy up
1 parent ba59d64 commit 16f1304

2 files changed

Lines changed: 6 additions & 15 deletions

File tree

src/kaggle_benchmarks/actors/openai.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import itertools
1616
import json
17-
import logging
1817
from typing import Any, TypeVar
1918

2019
import openai
@@ -77,19 +76,7 @@ def _invoke(
7776
if system:
7877
api_kwargs["instructions"] = system
7978

80-
try:
81-
return self._call_api(raw_messages, **api_kwargs)
82-
except openai.BadRequestError as e:
83-
logging.warning(f"encounter {e}. Trying out disabling structured output.")
84-
raise e
85-
return self._simulate_structured_response(
86-
messages=messages,
87-
system=system,
88-
schema_instructions=system,
89-
temperature=temperature,
90-
seed=seed,
91-
tools=tools,
92-
)
79+
return self._call_api(raw_messages, **api_kwargs)
9380

9481
def dump_image(self, image: images.ImageContent) -> list[dict]:
9582
"""Serializes an image content object into an API-compatible format."""
@@ -304,7 +291,7 @@ def __init__(self, client: openai.OpenAI, model: str, **kwargs):
304291
}
305292
elif "deepseek" in model:
306293
kwargs["support_vision"] = False
307-
kwargs["support_structured_outputs"] = False
294+
kwargs["support_structured_outputs"] = True
308295
kwargs.setdefault("support_tool_calling", False)
309296
super().__init__(client, model, **kwargs)
310297

src/kaggle_benchmarks/messages.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import warnings
1818
from typing import TYPE_CHECKING, Any, Generic, Iterable, TypeVar
1919

20+
import pydantic
21+
2022
from kaggle_benchmarks import events, utils
2123

2224
if TYPE_CHECKING:
@@ -75,6 +77,8 @@ def usage(self):
7577
def payload(self) -> str | list[dict]:
7678
if hasattr(self.content, "get_payload"):
7779
return self.content.get_payload()
80+
if isinstance(self.content, pydantic.BaseModel):
81+
return self.content.model_dump_json()
7882
if dataclasses.is_dataclass(self.content) and not isinstance(
7983
self.content, type
8084
):

0 commit comments

Comments
 (0)