kaggle_benchmarks 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. kaggle_benchmarks/__init__.py +44 -0
  2. kaggle_benchmarks/_config.py +129 -0
  3. kaggle_benchmarks/actors/__init__.py +16 -0
  4. kaggle_benchmarks/actors/base.py +75 -0
  5. kaggle_benchmarks/actors/llms.py +465 -0
  6. kaggle_benchmarks/assertions.py +399 -0
  7. kaggle_benchmarks/chats.py +146 -0
  8. kaggle_benchmarks/clients.py +81 -0
  9. kaggle_benchmarks/content_types/__init__.py +15 -0
  10. kaggle_benchmarks/content_types/images.py +135 -0
  11. kaggle_benchmarks/contexts.py +114 -0
  12. kaggle_benchmarks/envs/__init__.py +23 -0
  13. kaggle_benchmarks/envs/docker.py +109 -0
  14. kaggle_benchmarks/envs/environment.py +42 -0
  15. kaggle_benchmarks/envs/local.py +53 -0
  16. kaggle_benchmarks/envs/mixins.py +48 -0
  17. kaggle_benchmarks/events.py +51 -0
  18. kaggle_benchmarks/kaggle/__init__.py +27 -0
  19. kaggle_benchmarks/kaggle/benchmark_types_pb2.py +66 -0
  20. kaggle_benchmarks/kaggle/benchmark_types_pb2.pyi +1214 -0
  21. kaggle_benchmarks/kaggle/client.py +147 -0
  22. kaggle_benchmarks/kaggle/model_proxy.py +71 -0
  23. kaggle_benchmarks/kaggle/models.py +62 -0
  24. kaggle_benchmarks/kaggle/serialization.py +579 -0
  25. kaggle_benchmarks/messages.py +148 -0
  26. kaggle_benchmarks/orchestration/__init__.py +20 -0
  27. kaggle_benchmarks/orchestration/scheduling.py +105 -0
  28. kaggle_benchmarks/orchestration/task_queue.py +77 -0
  29. kaggle_benchmarks/prompting.py +173 -0
  30. kaggle_benchmarks/results.py +121 -0
  31. kaggle_benchmarks/runs.py +226 -0
  32. kaggle_benchmarks/tasks.py +343 -0
  33. kaggle_benchmarks/tools/__init__.py +15 -0
  34. kaggle_benchmarks/tools/python.py +199 -0
  35. kaggle_benchmarks/tools/search.py +138 -0
  36. kaggle_benchmarks/tools/web.py +126 -0
  37. kaggle_benchmarks/ui/__init__.py +15 -0
  38. kaggle_benchmarks/ui/console.py +42 -0
  39. kaggle_benchmarks/ui/ipython_magics.py +206 -0
  40. kaggle_benchmarks/ui/panel.py +389 -0
  41. kaggle_benchmarks/ui/setup_panel.py +92 -0
  42. kaggle_benchmarks/utils.py +188 -0
  43. kaggle_benchmarks-0.2.0.dist-info/METADATA +142 -0
  44. kaggle_benchmarks-0.2.0.dist-info/RECORD +46 -0
  45. kaggle_benchmarks-0.2.0.dist-info/WHEEL +4 -0
  46. kaggle_benchmarks-0.2.0.dist-info/licenses/LICENSE +202 -0
@@ -0,0 +1,44 @@
1
+ # Copyright 2025 Kaggle Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from kaggle_benchmarks import (
16
+ actors,
17
+ assertions,
18
+ chats,
19
+ clients,
20
+ content_types,
21
+ envs,
22
+ kaggle,
23
+ orchestration,
24
+ prompting,
25
+ tasks,
26
+ tools,
27
+ ui,
28
+ utils,
29
+ )
30
+ from kaggle_benchmarks._config import ExecutionMode, config
31
+ from kaggle_benchmarks.actors import Actor, LLMChat, system, user
32
+ from kaggle_benchmarks.runs import Run, Runs
33
+ from kaggle_benchmarks.tasks import benchmark, task
34
+
35
+ llm = kaggle.load_default_model()
36
+ judge_llm = kaggle.load_judge_model()
37
+ llms = kaggle.load_available_models()
38
+
39
+
40
+ client: clients.Client = clients.resolve_client()
41
+ config.apply()
42
+
43
+
44
+ __version__ = "0.2.0"
@@ -0,0 +1,129 @@
1
+ # Copyright 2025 Kaggle Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import dataclasses
16
+ import enum
17
+ import logging
18
+ import os
19
+ from pathlib import Path
20
+ from typing import Any, Self
21
+
22
+ import dotenv
23
+ import panel as pn
24
+
25
+ base_dir = Path(__file__).parent.parent.parent
26
+ dotenv.load_dotenv(override=True)
27
+
28
+
29
+ def string_to_bool(s: str) -> bool:
30
+ """Converts a string to a boolean, handling various truthy values."""
31
+ return s.lower() in ("true", "1", "t", "y", "yes")
32
+
33
+
34
+ class ExecutionMode(enum.Enum):
35
+ NOTEBOOK = 0
36
+ INTERACTIVE = 0
37
+ RUN = 1
38
+ TRIAL = 1
39
+ TESTING = 2
40
+ DEV = 3
41
+ DOC = 4
42
+
43
+
44
+ @dataclasses.dataclass()
45
+ class Config:
46
+ execution_mode: ExecutionMode = dataclasses.field(
47
+ default_factory=lambda: ExecutionMode[os.getenv("BENCHMARK_MODE", "NOTEBOOK")]
48
+ )
49
+
50
+ disable_caching: bool = dataclasses.field(
51
+ default_factory=lambda: string_to_bool(
52
+ os.environ.get("DISABLE_LOCAL_CACHE", "True")
53
+ )
54
+ )
55
+
56
+ cache_directory: Path = dataclasses.field(
57
+ default_factory=lambda: Path(
58
+ os.environ.get("CACHE_DIRECTORY", base_dir / ".cache")
59
+ )
60
+ )
61
+
62
+ interactive_mode: bool = dataclasses.field(
63
+ default_factory=lambda: string_to_bool(
64
+ os.environ.get("INTERACTIVE_UI", "False")
65
+ )
66
+ )
67
+ ui_handler: Any = None
68
+
69
+ _ui_theme: str = dataclasses.field(
70
+ default_factory=lambda: os.environ.get("UI_THEME", "default")
71
+ )
72
+ suppress_ui_warnings: bool = dataclasses.field(
73
+ default_factory=lambda: string_to_bool(
74
+ os.environ.get("SUPPRESS_UI_WARNINGS", "true")
75
+ )
76
+ )
77
+ continue_with_exceptions: bool = dataclasses.field(
78
+ default_factory=lambda: (
79
+ os.environ.get("KAGGLE_KERNEL_RUN_TYPE", "").lower() == "batch"
80
+ or string_to_bool(os.environ.get("CONTINUE_WITH_EXCEPTIONS", "False"))
81
+ )
82
+ )
83
+ render_subruns: bool = dataclasses.field(
84
+ default_factory=lambda: (
85
+ string_to_bool(os.environ.get("RENDER_SUBRUNS", "True"))
86
+ )
87
+ )
88
+
89
+ show_message_details: bool = False
90
+
91
+ def apply(self) -> Self:
92
+ pn.config.theme = self.ui_theme # type: ignore
93
+
94
+ if self.suppress_ui_warnings:
95
+ logger = logging.getLogger("bokeh")
96
+ logger.setLevel(logging.ERROR)
97
+ if self.interactive_mode:
98
+ from kaggle_benchmarks import events, ui
99
+
100
+ if self.ui_handler is None:
101
+ self.ui_handler = ui.panel.PanelUI()
102
+ events.manager.bind(self.ui_handler)
103
+
104
+ return self
105
+
106
+ @property
107
+ def ui_theme(self):
108
+ return self._ui_theme
109
+
110
+ @ui_theme.setter
111
+ def ui_theme(self, value):
112
+ self._ui_theme = value
113
+ self.apply()
114
+
115
+ def enable_dark_mode(self):
116
+ self.ui_theme = "dark"
117
+
118
+ def disable_dark_mode(self):
119
+ self.ui_theme = "default"
120
+
121
+ def enable_interactive_mode(self):
122
+ self.interactive_mode = True
123
+ self.apply()
124
+
125
+ def disable_tqdm(self):
126
+ return self.execution_mode != ExecutionMode.NOTEBOOK
127
+
128
+
129
+ config = Config()
@@ -0,0 +1,16 @@
1
+ # Copyright 2025 Kaggle Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from kaggle_benchmarks.actors.base import Actor, assertion, system, user
16
+ from kaggle_benchmarks.actors.llms import LLMChat
@@ -0,0 +1,75 @@
1
+ # Copyright 2025 Kaggle Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from typing import Iterable, Literal, TypeVar
16
+
17
+ from kaggle_benchmarks import utils
18
+ from kaggle_benchmarks.messages import Message
19
+
20
+ T = TypeVar("T")
21
+
22
+
23
+ class Actor:
24
+ def __init__(
25
+ self,
26
+ name: str | None = None,
27
+ role: Literal["system", "user", "assistant", "developer", "tool"] = "assistant",
28
+ avatar: str = "",
29
+ id: str | None = None,
30
+ ):
31
+ self.name = type(self).__name__ if name is None else name
32
+ self.id = id or name
33
+ self.role = role
34
+ self.avatar = avatar
35
+
36
+ def send(
37
+ self, message: T | Message[T], is_visible_to_llm: bool = True
38
+ ) -> Message[T]:
39
+ return self._send(message, is_visible_to_llm)
40
+
41
+ def _send(self, message: T | Message[T], is_visible_to_llm: bool) -> Message[T]:
42
+ from kaggle_benchmarks import chats
43
+
44
+ if isinstance(message, Message):
45
+ message.is_visible_to_llm = is_visible_to_llm
46
+ else:
47
+ message = Message(
48
+ sender=self, content=message, is_visible_to_llm=is_visible_to_llm
49
+ )
50
+
51
+ chats.send(message)
52
+ return message
53
+
54
+ def stream(self, content: Iterable[str]) -> Message[str]:
55
+ msg = Message(content="", sender=self, _status=utils.Status.RUNNING)
56
+ self.send(msg)
57
+ msg.stream(content)
58
+ msg.status = utils.Status.SUCCESS
59
+ return msg
60
+
61
+ def as_dict(self) -> dict[str, str]:
62
+ """Returns a dictionary representation of the agent."""
63
+ return dict(id=self.id, name=self.name, role=self.role, avatar=self.avatar)
64
+
65
+ def __repr__(self) -> str:
66
+ cls = type(self)
67
+ return f"{cls.__name__}(name={self.name!r}, avatar={self.avatar!r})"
68
+
69
+ def __str__(self) -> str:
70
+ return f"{self.avatar} {self.name}"
71
+
72
+
73
+ system = Actor(name="System", role="system", avatar="⚙️")
74
+ assertion = Actor(name="Assertion", role="system", avatar="🚨️")
75
+ user = Actor(name="User", role="user", avatar="👤")