inspect-ai 0.3.72__py3-none-any.whl → 0.3.73__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 (103) hide show
  1. inspect_ai/_cli/eval.py +14 -3
  2. inspect_ai/_cli/sandbox.py +3 -3
  3. inspect_ai/_cli/score.py +6 -4
  4. inspect_ai/_cli/trace.py +53 -6
  5. inspect_ai/_display/core/config.py +1 -1
  6. inspect_ai/_display/core/display.py +2 -1
  7. inspect_ai/_display/core/footer.py +6 -6
  8. inspect_ai/_display/plain/display.py +11 -6
  9. inspect_ai/_display/rich/display.py +23 -13
  10. inspect_ai/_display/textual/app.py +10 -9
  11. inspect_ai/_display/textual/display.py +2 -2
  12. inspect_ai/_display/textual/widgets/footer.py +4 -0
  13. inspect_ai/_display/textual/widgets/samples.py +14 -5
  14. inspect_ai/_eval/context.py +1 -2
  15. inspect_ai/_eval/eval.py +54 -41
  16. inspect_ai/_eval/loader.py +9 -2
  17. inspect_ai/_eval/run.py +148 -81
  18. inspect_ai/_eval/score.py +13 -8
  19. inspect_ai/_eval/task/images.py +31 -21
  20. inspect_ai/_eval/task/run.py +62 -59
  21. inspect_ai/_eval/task/rundir.py +16 -9
  22. inspect_ai/_eval/task/sandbox.py +7 -8
  23. inspect_ai/_eval/task/util.py +7 -0
  24. inspect_ai/_util/_async.py +118 -10
  25. inspect_ai/_util/constants.py +0 -2
  26. inspect_ai/_util/file.py +15 -29
  27. inspect_ai/_util/future.py +37 -0
  28. inspect_ai/_util/http.py +3 -99
  29. inspect_ai/_util/httpx.py +60 -0
  30. inspect_ai/_util/interrupt.py +2 -2
  31. inspect_ai/_util/json.py +5 -52
  32. inspect_ai/_util/logger.py +30 -86
  33. inspect_ai/_util/retry.py +10 -61
  34. inspect_ai/_util/trace.py +2 -2
  35. inspect_ai/_view/server.py +86 -3
  36. inspect_ai/_view/www/dist/assets/index.js +25837 -13269
  37. inspect_ai/_view/www/log-schema.json +253 -186
  38. inspect_ai/_view/www/package.json +2 -2
  39. inspect_ai/_view/www/src/plan/PlanDetailView.tsx +8 -3
  40. inspect_ai/_view/www/src/samples/transcript/StepEventView.tsx +2 -3
  41. inspect_ai/_view/www/src/types/log.d.ts +122 -94
  42. inspect_ai/approval/_human/manager.py +6 -10
  43. inspect_ai/approval/_human/panel.py +2 -2
  44. inspect_ai/dataset/_sources/util.py +7 -6
  45. inspect_ai/log/__init__.py +4 -0
  46. inspect_ai/log/_file.py +35 -61
  47. inspect_ai/log/_log.py +18 -1
  48. inspect_ai/log/_recorders/eval.py +14 -23
  49. inspect_ai/log/_recorders/json.py +3 -18
  50. inspect_ai/log/_samples.py +27 -2
  51. inspect_ai/log/_transcript.py +8 -8
  52. inspect_ai/model/__init__.py +2 -1
  53. inspect_ai/model/_call_tools.py +60 -40
  54. inspect_ai/model/_chat_message.py +3 -2
  55. inspect_ai/model/_generate_config.py +25 -0
  56. inspect_ai/model/_model.py +74 -36
  57. inspect_ai/model/_openai.py +9 -1
  58. inspect_ai/model/_providers/anthropic.py +24 -26
  59. inspect_ai/model/_providers/azureai.py +11 -9
  60. inspect_ai/model/_providers/bedrock.py +33 -24
  61. inspect_ai/model/_providers/cloudflare.py +8 -9
  62. inspect_ai/model/_providers/goodfire.py +7 -3
  63. inspect_ai/model/_providers/google.py +47 -13
  64. inspect_ai/model/_providers/groq.py +15 -15
  65. inspect_ai/model/_providers/hf.py +24 -17
  66. inspect_ai/model/_providers/mistral.py +36 -20
  67. inspect_ai/model/_providers/openai.py +30 -25
  68. inspect_ai/model/_providers/openai_o1.py +1 -1
  69. inspect_ai/model/_providers/providers.py +1 -1
  70. inspect_ai/model/_providers/together.py +3 -4
  71. inspect_ai/model/_providers/util/__init__.py +2 -2
  72. inspect_ai/model/_providers/util/chatapi.py +6 -19
  73. inspect_ai/model/_providers/util/hooks.py +165 -0
  74. inspect_ai/model/_providers/vertex.py +20 -3
  75. inspect_ai/model/_providers/vllm.py +16 -19
  76. inspect_ai/scorer/_multi.py +5 -2
  77. inspect_ai/solver/_bridge/patch.py +31 -1
  78. inspect_ai/solver/_fork.py +5 -3
  79. inspect_ai/solver/_human_agent/agent.py +3 -2
  80. inspect_ai/tool/__init__.py +8 -2
  81. inspect_ai/tool/_tool_info.py +4 -90
  82. inspect_ai/tool/_tool_params.py +4 -34
  83. inspect_ai/tool/_tools/_web_search.py +30 -24
  84. inspect_ai/util/__init__.py +4 -0
  85. inspect_ai/util/_concurrency.py +5 -6
  86. inspect_ai/util/_display.py +6 -0
  87. inspect_ai/util/_json.py +170 -0
  88. inspect_ai/util/_sandbox/docker/cleanup.py +13 -9
  89. inspect_ai/util/_sandbox/docker/docker.py +5 -0
  90. inspect_ai/util/_sandbox/environment.py +56 -9
  91. inspect_ai/util/_sandbox/service.py +12 -5
  92. inspect_ai/util/_subprocess.py +94 -113
  93. inspect_ai/util/_subtask.py +2 -4
  94. {inspect_ai-0.3.72.dist-info → inspect_ai-0.3.73.dist-info}/METADATA +6 -2
  95. {inspect_ai-0.3.72.dist-info → inspect_ai-0.3.73.dist-info}/RECORD +99 -99
  96. {inspect_ai-0.3.72.dist-info → inspect_ai-0.3.73.dist-info}/WHEEL +1 -1
  97. inspect_ai/_util/timeouts.py +0 -160
  98. inspect_ai/_view/www/node_modules/flatted/python/flatted.py +0 -149
  99. inspect_ai/_view/www/node_modules/flatted/python/test.py +0 -63
  100. inspect_ai/model/_providers/util/tracker.py +0 -92
  101. {inspect_ai-0.3.72.dist-info → inspect_ai-0.3.73.dist-info}/LICENSE +0 -0
  102. {inspect_ai-0.3.72.dist-info → inspect_ai-0.3.73.dist-info}/entry_points.txt +0 -0
  103. {inspect_ai-0.3.72.dist-info → inspect_ai-0.3.73.dist-info}/top_level.txt +0 -0
@@ -1,149 +0,0 @@
1
- # ISC License
2
- #
3
- # Copyright (c) 2018-2021, Andrea Giammarchi, @WebReflection
4
- #
5
- # Permission to use, copy, modify, and/or distribute this software for any
6
- # purpose with or without fee is hereby granted, provided that the above
7
- # copyright notice and this permission notice appear in all copies.
8
- #
9
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- # AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14
- # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- # PERFORMANCE OF THIS SOFTWARE.
16
-
17
- import json as _json
18
-
19
- class _Known:
20
- def __init__(self):
21
- self.key = []
22
- self.value = []
23
-
24
- class _String:
25
- def __init__(self, value):
26
- self.value = value
27
-
28
-
29
- def _array_keys(value):
30
- keys = []
31
- i = 0
32
- for _ in value:
33
- keys.append(i)
34
- i += 1
35
- return keys
36
-
37
- def _object_keys(value):
38
- keys = []
39
- for key in value:
40
- keys.append(key)
41
- return keys
42
-
43
- def _is_array(value):
44
- return isinstance(value, list) or isinstance(value, tuple)
45
-
46
- def _is_object(value):
47
- return isinstance(value, dict)
48
-
49
- def _is_string(value):
50
- return isinstance(value, str)
51
-
52
- def _index(known, input, value):
53
- input.append(value)
54
- index = str(len(input) - 1)
55
- known.key.append(value)
56
- known.value.append(index)
57
- return index
58
-
59
- def _loop(keys, input, known, output):
60
- for key in keys:
61
- value = output[key]
62
- if isinstance(value, _String):
63
- _ref(key, input[int(value.value)], input, known, output)
64
-
65
- return output
66
-
67
- def _ref(key, value, input, known, output):
68
- if _is_array(value) and not value in known:
69
- known.append(value)
70
- value = _loop(_array_keys(value), input, known, value)
71
- elif _is_object(value) and not value in known:
72
- known.append(value)
73
- value = _loop(_object_keys(value), input, known, value)
74
-
75
- output[key] = value
76
-
77
- def _relate(known, input, value):
78
- if _is_string(value) or _is_array(value) or _is_object(value):
79
- try:
80
- return known.value[known.key.index(value)]
81
- except:
82
- return _index(known, input, value)
83
-
84
- return value
85
-
86
- def _transform(known, input, value):
87
- if _is_array(value):
88
- output = []
89
- for val in value:
90
- output.append(_relate(known, input, val))
91
- return output
92
-
93
- if _is_object(value):
94
- obj = {}
95
- for key in value:
96
- obj[key] = _relate(known, input, value[key])
97
- return obj
98
-
99
- return value
100
-
101
- def _wrap(value):
102
- if _is_string(value):
103
- return _String(value)
104
-
105
- if _is_array(value):
106
- i = 0
107
- for val in value:
108
- value[i] = _wrap(val)
109
- i += 1
110
-
111
- elif _is_object(value):
112
- for key in value:
113
- value[key] = _wrap(value[key])
114
-
115
- return value
116
-
117
- def parse(value, *args, **kwargs):
118
- json = _json.loads(value, *args, **kwargs)
119
- wrapped = []
120
- for value in json:
121
- wrapped.append(_wrap(value))
122
-
123
- input = []
124
- for value in wrapped:
125
- if isinstance(value, _String):
126
- input.append(value.value)
127
- else:
128
- input.append(value)
129
-
130
- value = input[0]
131
-
132
- if _is_array(value):
133
- return _loop(_array_keys(value), input, [value], value)
134
-
135
- if _is_object(value):
136
- return _loop(_object_keys(value), input, [value], value)
137
-
138
- return value
139
-
140
-
141
- def stringify(value, *args, **kwargs):
142
- known = _Known()
143
- input = []
144
- output = []
145
- i = int(_index(known, input, value))
146
- while i < len(input):
147
- output.append(_transform(known, input, input[i]))
148
- i += 1
149
- return _json.dumps(output, *args, **kwargs)
@@ -1,63 +0,0 @@
1
- from flatted import stringify as _stringify, parse
2
-
3
- def stringify(value):
4
- return _stringify(value, separators=(',', ':'))
5
-
6
- assert stringify([None, None]) == '[[null,null]]'
7
-
8
- a = []
9
- o = {}
10
-
11
- assert stringify(a) == '[[]]'
12
- assert stringify(o) == '[{}]'
13
-
14
- a.append(a)
15
- o['o'] = o
16
-
17
- assert stringify(a) == '[["0"]]'
18
- assert stringify(o) == '[{"o":"0"}]'
19
-
20
- b = parse(stringify(a))
21
- assert isinstance(b, list) and b[0] == b
22
-
23
- a.append(1)
24
- a.append('two')
25
- a.append(True)
26
- o['one'] = 1
27
- o['two'] = 'two'
28
- o['three'] = True
29
-
30
- assert stringify(a) == '[["0",1,"1",true],"two"]'
31
- assert stringify(o) == '[{"o":"0","one":1,"two":"1","three":true},"two"]'
32
-
33
- a.append(o)
34
- o['a'] = a
35
-
36
- assert stringify(a) == '[["0",1,"1",true,"2"],"two",{"o":"2","one":1,"two":"1","three":true,"a":"0"}]'
37
- assert stringify(o) == '[{"o":"0","one":1,"two":"1","three":true,"a":"2"},"two",["2",1,"1",true,"0"]]'
38
-
39
- a.append({'test': 'OK'})
40
- a.append([1, 2, 3])
41
-
42
- o['test'] = {'test': 'OK'}
43
- o['array'] = [1, 2, 3]
44
-
45
- assert stringify(a) == '[["0",1,"1",true,"2","3","4"],"two",{"o":"2","one":1,"two":"1","three":true,"a":"0","test":"3","array":"4"},{"test":"5"},[1,2,3],"OK"]'
46
- assert stringify(o) == '[{"o":"0","one":1,"two":"1","three":true,"a":"2","test":"3","array":"4"},"two",["2",1,"1",true,"0","3","4"],{"test":"5"},[1,2,3],"OK"]'
47
-
48
- a2 = parse(stringify(a));
49
- o2 = parse(stringify(o));
50
-
51
- assert a2[0] == a2
52
- assert o2['o'] == o2
53
-
54
- assert a2[1] == 1 and a2[2] == 'two' and a2[3] == True and isinstance(a2[4], dict)
55
- assert a2[4] == a2[4]['o'] and a2 == a2[4]['o']['a']
56
-
57
- str = parse('[{"prop":"1","a":"2","b":"3"},{"value":123},["4","5"],{"e":"6","t":"7","p":4},{},{"b":"8"},"f",{"a":"9"},["10"],"sup",{"a":1,"d":2,"c":"7","z":"11","h":1},{"g":2,"a":"7","b":"12","f":6},{"r":4,"u":"7","c":5}]')
58
- assert str['b']['t']['a'] == 'sup' and str['a'][1]['b'][0]['c'] == str['b']['t']
59
-
60
- oo = parse('[{"a":"1","b":"0","c":"2"},{"aa":"3"},{"ca":"4","cb":"5","cc":"6","cd":"7","ce":"8","cf":"9"},{"aaa":"10"},{"caa":"4"},{"cba":"5"},{"cca":"2"},{"cda":"4"},"value2","value3","value1"]');
61
- assert oo['a']['aa']['aaa'] == 'value1' and oo == oo['b'] and oo['c']['ca']['caa'] == oo['c']['ca']
62
-
63
- print('OK')
@@ -1,92 +0,0 @@
1
- import re
2
- import time
3
- from typing import Any, cast
4
-
5
- import httpx
6
- from shortuuid import uuid
7
-
8
-
9
- class HttpTimeTracker:
10
- def __init__(self) -> None:
11
- # track request start times
12
- self._requests: dict[str, float] = {}
13
-
14
- def start_request(self) -> str:
15
- request_id = uuid()
16
- self._requests[request_id] = time.monotonic()
17
- return request_id
18
-
19
- def end_request(self, request_id: str) -> float:
20
- # read the request time if (if available) and purge from dict
21
- request_time = self._requests.pop(request_id, None)
22
- if request_time is None:
23
- raise RuntimeError(f"request_id not registered: {request_id}")
24
-
25
- # return elapsed time
26
- return time.monotonic() - request_time
27
-
28
- def update_request_time(self, request_id: str) -> None:
29
- request_time = self._requests.get(request_id, None)
30
- if not request_time:
31
- raise RuntimeError(f"No request registered for request_id: {request_id}")
32
-
33
- # update the request time
34
- self._requests[request_id] = time.monotonic()
35
-
36
-
37
- class BotoTimeTracker(HttpTimeTracker):
38
- def __init__(self, session: Any) -> None:
39
- from aiobotocore.session import AioSession
40
-
41
- super().__init__()
42
-
43
- # register hook
44
- session = cast(AioSession, session._session)
45
- session.register(
46
- "before-send.bedrock-runtime.Converse", self.converse_before_send
47
- )
48
-
49
- def converse_before_send(self, **kwargs: Any) -> None:
50
- user_agent = kwargs["request"].headers["User-Agent"].decode()
51
- match = re.search(rf"{self.USER_AGENT_PREFIX}(\w+)", user_agent)
52
- if match:
53
- request_id = match.group(1)
54
- self.update_request_time(request_id)
55
-
56
- def user_agent_extra(self, request_id: str) -> str:
57
- return f"{self.USER_AGENT_PREFIX}{request_id}"
58
-
59
- USER_AGENT_PREFIX = "ins/rid#"
60
-
61
-
62
- class HttpxTimeTracker(HttpTimeTracker):
63
- """Class which tracks the duration of successful (200 status) http requests.
64
-
65
- A special header is injected into requests which is then read from
66
- an httpx 'request' event hook -- this creates a record of when the request
67
- started. Note that with retries a single request id could be started
68
- several times; our request hook makes sure we always track the time of
69
- the last request.
70
-
71
- To determine the total time, we also install an httpx response hook. In
72
- this hook we look for 200 responses which have a registered request id.
73
- When we find one, we update the end time of the request.
74
-
75
- There is an 'end_request()' method which gets the total requeset time
76
- for a request_id and then purges the request_id from our tracking (so
77
- the dict doesn't grow unbounded)
78
- """
79
-
80
- REQUEST_ID_HEADER = "x-irid"
81
-
82
- def __init__(self, client: httpx.AsyncClient):
83
- super().__init__()
84
-
85
- # install httpx request hook
86
- client.event_hooks["request"].append(self.request_hook)
87
-
88
- async def request_hook(self, request: httpx.Request) -> None:
89
- # update the last request time for this request id (as there could be retries)
90
- request_id = request.headers.get(self.REQUEST_ID_HEADER, None)
91
- if request_id:
92
- self.update_request_time(request_id)