mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-25 00:02:25 +02:00
bind directory completion to output descendants
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
|||||||
0.20.14
|
0.20.15
|
||||||
|
|||||||
+17
-10
@@ -1549,17 +1549,24 @@ def artifact_completion_tool_schemas(offered_schemas, required_artifacts):
|
|||||||
bound = copy.deepcopy(offered_schemas)
|
bound = copy.deepcopy(offered_schemas)
|
||||||
for schema in bound:
|
for schema in bound:
|
||||||
function = schema.get('function') or {}
|
function = schema.get('function') or {}
|
||||||
if canonical(function.get('name')) != 'write_file':
|
|
||||||
continue
|
|
||||||
properties = (function.get('parameters') or {}).get('properties') or {}
|
properties = (function.get('parameters') or {}).get('properties') or {}
|
||||||
path_schema = properties.get('path')
|
if canonical(function.get('name')) == 'write_file':
|
||||||
if not isinstance(path_schema, dict):
|
path_schema = properties.get('path')
|
||||||
continue
|
if isinstance(path_schema, dict):
|
||||||
path_schema['pattern'] = '^' + re.escape(target + '/') + '.+'
|
path_schema['pattern'] = '^' + re.escape(target + '/') + '.+'
|
||||||
path_schema['description'] = (
|
path_schema['description'] = (
|
||||||
f'Write a new file inside the required directory {target}; '
|
f'Write a new file inside the required directory {target}; '
|
||||||
'do not use the directory path itself.'
|
'do not use the directory path itself.'
|
||||||
)
|
)
|
||||||
|
elif canonical(function.get('name')) == 'python':
|
||||||
|
code_schema = properties.get('code')
|
||||||
|
if isinstance(code_schema, dict):
|
||||||
|
code_schema['pattern'] = re.escape(target + '/')
|
||||||
|
code_schema['description'] = (
|
||||||
|
'Python code that creates one or more non-empty files inside '
|
||||||
|
f'the required directory {target}. The code must reference a '
|
||||||
|
'descendant path; do not only inspect or delete source files.'
|
||||||
|
)
|
||||||
return bound
|
return bound
|
||||||
if Path(target).suffix.lower() in _NON_TEXT_ARTIFACT_SUFFIXES:
|
if Path(target).suffix.lower() in _NON_TEXT_ARTIFACT_SUFFIXES:
|
||||||
# ``write_file`` deliberately accepts UTF-8 text only. Keeping it in
|
# ``write_file`` deliberately accepts UTF-8 text only. Keeping it in
|
||||||
|
|||||||
@@ -625,16 +625,28 @@ def test_artifact_completion_schema_binds_single_required_file_without_mutating_
|
|||||||
|
|
||||||
|
|
||||||
def test_artifact_completion_schema_binds_directory_descendant_but_not_multiple_outputs():
|
def test_artifact_completion_schema_binds_directory_descendant_but_not_multiple_outputs():
|
||||||
source = [{
|
source = [
|
||||||
'type': 'function',
|
{
|
||||||
'function': {
|
'type': 'function',
|
||||||
'name': 'write_file',
|
'function': {
|
||||||
'parameters': {
|
'name': 'write_file',
|
||||||
'type': 'object',
|
'parameters': {
|
||||||
'properties': {'path': {'type': 'string'}},
|
'type': 'object',
|
||||||
|
'properties': {'path': {'type': 'string'}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}]
|
{
|
||||||
|
'type': 'function',
|
||||||
|
'function': {
|
||||||
|
'name': 'python',
|
||||||
|
'parameters': {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {'code': {'type': 'string'}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
directory_bound = artifact_completion_tool_schemas(
|
directory_bound = artifact_completion_tool_schemas(
|
||||||
source, ('/workspace/results/',),
|
source, ('/workspace/results/',),
|
||||||
@@ -644,6 +656,13 @@ def test_artifact_completion_schema_binds_directory_descendant_but_not_multiple_
|
|||||||
assert not re.search(directory_path['pattern'], '/workspace/results')
|
assert not re.search(directory_path['pattern'], '/workspace/results')
|
||||||
assert 'inside the required directory' in directory_path['description']
|
assert 'inside the required directory' in directory_path['description']
|
||||||
assert 'pattern' not in source[0]['function']['parameters']['properties']['path']
|
assert 'pattern' not in source[0]['function']['parameters']['properties']['path']
|
||||||
|
directory_code = directory_bound[1]['function']['parameters']['properties']['code']
|
||||||
|
assert re.search(
|
||||||
|
directory_code['pattern'],
|
||||||
|
"Path('/workspace/results/1.tex').write_text('table')",
|
||||||
|
)
|
||||||
|
assert not re.search(directory_code['pattern'], "Path('/workspace/source.tar').unlink()")
|
||||||
|
assert 'non-empty files inside' in directory_code['description']
|
||||||
assert artifact_completion_tool_schemas(
|
assert artifact_completion_tool_schemas(
|
||||||
source, ('/workspace/a.txt', '/workspace/b.txt'),
|
source, ('/workspace/a.txt', '/workspace/b.txt'),
|
||||||
) == source
|
) == source
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ ROOT = Path(__file__).resolve().parents[1]
|
|||||||
def test_original_harness_version_is_canonical_semver() -> None:
|
def test_original_harness_version_is_canonical_semver() -> None:
|
||||||
version = (ROOT / "HARNESS_VERSION").read_text(encoding="utf-8").strip()
|
version = (ROOT / "HARNESS_VERSION").read_text(encoding="utf-8").strip()
|
||||||
|
|
||||||
assert version == "0.20.14"
|
assert version == "0.20.15"
|
||||||
assert re.fullmatch(r"\d+\.\d+\.\d+", version)
|
assert re.fullmatch(r"\d+\.\d+\.\d+", version)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user