Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/datacustomcode/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def deploy(
COMPUTE_TYPES,
CodeExtensionMetadata,
deploy_full,
describe_supported_signatures,
infer_use_in_feature,
)
from datacustomcode.token_provider import (
Expand Down Expand Up @@ -252,8 +253,9 @@ def deploy(
else:
click.secho(
"Error: Function signature does not match a supported type. "
"Use SearchIndexChunkingV1Request and "
"SearchIndexChunkingV1Response in function signature.",
"Use a supported Request/Response pair in the function "
"signature. For example, "
f"{describe_supported_signatures(entrypoint_path)}.",
fg="red",
)
raise click.Abort()
Expand Down Expand Up @@ -349,14 +351,27 @@ def init(directory: str, code_type: str, use_in_feature: Optional[str]):
+ " to automatically update config.json when you make changes to your code"
)

# Generate test.json for functions
# Prefer the sample tests/test.json shipped in the template; only
# generate one from the request model if the template doesn't have it
if code_type == "function":
test_json_path = _generate_function_test_file(entrypoint_path)
if test_json_path:
template_test_json = os.path.join(
os.path.dirname(entrypoint_path), TESTS_DIR, TEST_FILE
)
test_json_path: Optional[str]
if os.path.isfile(template_test_json):
test_json_path = template_test_json
click.echo(
"Generated test file at "
"Sample test file at "
+ click.style(test_json_path, fg="blue", bold=True)
)
else:
test_json_path = _generate_function_test_file(entrypoint_path)
if test_json_path:
click.echo(
"Generated test file at "
+ click.style(test_json_path, fg="blue", bold=True)
)
if test_json_path:
click.echo(
"Test your function locally with "
+ click.style(
Expand Down
7 changes: 4 additions & 3 deletions src/datacustomcode/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
SCRIPT_USE_IN_FEATURE_STREAMING,
]

# Pydantic request/response type names to feature names
# (request type name, response type name) pair to feature name
REQUEST_TYPE_TO_FEATURE = {
"SearchIndexChunkingV1Request": "SearchIndexChunking",
"SearchIndexChunkingV1Response": "SearchIndexChunking",
("SearchIndexChunkingV1Request", "SearchIndexChunkingV1Response"): (
"SearchIndexChunking"
),
}
34 changes: 27 additions & 7 deletions src/datacustomcode/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,35 @@ def infer_use_in_feature(entrypoint_path: str) -> Union[str, None]:
if not request_type_name or not response_type_name:
return None

# Look up features for both types
request_feature = REQUEST_TYPE_TO_FEATURE.get(request_type_name)
response_feature = REQUEST_TYPE_TO_FEATURE.get(response_type_name)
return REQUEST_TYPE_TO_FEATURE.get((request_type_name, response_type_name))

# Both must be present and must match
if request_feature and response_feature and request_feature == response_feature:
return request_feature

return None
def describe_supported_signatures(entrypoint_path: str) -> str:
"""Build a contract-mismatch hint based on the function's feature type.

If the request or response type belongs to a known feature, only that
feature's expected pair is listed; otherwise all supported pairs are.
Each pair is followed by the use_in_feature it maps to, e.g.
``Req/Resp for use_in_feature: SearchIndexChunking``.
"""
from datacustomcode.function_utils import inspect_function_types_static

request_type_name, response_type_name = inspect_function_types_static(
entrypoint_path
)
supported = list(REQUEST_TYPE_TO_FEATURE.items())
sharing_a_type = [
((expected_request, expected_response), feature)
for (expected_request, expected_response), feature in supported
if request_type_name == expected_request
or response_type_name == expected_response
]
# Narrow the hint only when the detected types point at a single feature
to_show = sharing_a_type if len(sharing_a_type) == 1 else supported
return " or ".join(
f"{expected_request}/{expected_response} for use_in_feature: {feature}"
for (expected_request, expected_response), feature in to_show
)


class CodeExtensionMetadata(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"input": [
{
"text": "Online Remittance Instructions",
"metadata": {
"type": "text",
"page_number": 1,
"transcript_fields": {
"speaker": "Agent",
"start_timestamp": 1.0,
"end_timestamp": 8.75
},
"text_as_html": "<p>Online Remittance Instructions</p>",
"source_dmo_fields": {
"FilePath__c": "quarterly_report.pdf",
"Size__c": 1377454.0,
"ContentType__c": "pdf",
"LastModified__c": "2026-03-25T02:01:24.918000"
},
"prepend": [
{
"dmo_name": "udmo_1__dlm",
"field_name": "ResolvedFilePath__c",
"value": "udlo_1__dll:quarterly_report.pdf"
}
],
"image_base64": "sample_image_base64",
"image_mime_type": "image/png",
"image_type": "diagram"
}
}
]
}
23 changes: 23 additions & 0 deletions tests/test_describe_supported_signatures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from datacustomcode.deploy import describe_supported_signatures


def test_describe_supported_signatures(tmp_path):
entrypoint = tmp_path / "entrypoint.py"
chunk_pair = (
"SearchIndexChunkingV1Request/SearchIndexChunkingV1Response "
"for use_in_feature: SearchIndexChunking"
)

def describe(request_type, response_type):
entrypoint.write_text(
f"def function(request: {request_type}, runtime)"
f" -> {response_type}:\n pass\n"
)
return describe_supported_signatures(str(entrypoint))

# A recognised request or response narrows the hint to its own feature
assert describe("SearchIndexChunkingV1Request", "dict") == chunk_pair
assert describe("dict", "SearchIndexChunkingV1Response") == chunk_pair
# Unrecognised types fall back to listing every supported pair
fallback = describe("dict", "dict")
assert fallback == chunk_pair
Loading