Skip to content

Commit 2101205

Browse files
stephentoubCopilot
andcommitted
Address review feedback: add type guards in Python, fix Go comment typo
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4f18d31 commit 2101205

2 files changed

Lines changed: 28 additions & 15 deletions

File tree

go/definetool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func convertCallToolResult(value any) (ToolResult, bool) {
200200
return tr, true
201201
}
202202

203-
// generateSchemaForTypegenerates a JSON schema map from a Go type using reflection.
203+
// generateSchemaForType generates a JSON schema map from a Go type using reflection.
204204
// Panics if schema generation fails, as this indicates a programming error.
205205
func generateSchemaForType(t reflect.Type) map[string]any {
206206
if t == nil {

python/copilot/tools.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -299,31 +299,44 @@ def _convert_call_tool_result(call_result: dict[str, Any]) -> ToolResult:
299299
for block in call_result["content"]:
300300
block_type = block.get("type")
301301
if block_type == "text":
302-
text_parts.append(block.get("text", ""))
302+
text = block.get("text", "")
303+
if isinstance(text, str):
304+
text_parts.append(text)
303305
elif block_type == "image":
304-
binary_results.append(
305-
ToolBinaryResult(
306-
data=block.get("data", ""),
307-
mime_type=block.get("mimeType", ""),
308-
type="image",
306+
data = block.get("data", "")
307+
mime_type = block.get("mimeType", "")
308+
if isinstance(data, str) and isinstance(mime_type, str):
309+
binary_results.append(
310+
ToolBinaryResult(
311+
data=data,
312+
mime_type=mime_type,
313+
type="image",
314+
)
309315
)
310-
)
311316
elif block_type == "resource":
312317
resource = block.get("resource", {})
313-
if resource.get("text"):
314-
text_parts.append(resource["text"])
315-
if resource.get("blob"):
318+
if not isinstance(resource, dict):
319+
continue
320+
text = resource.get("text")
321+
if isinstance(text, str) and text:
322+
text_parts.append(text)
323+
blob = resource.get("blob")
324+
if isinstance(blob, str) and blob:
325+
mime_type = resource.get("mimeType", "application/octet-stream")
326+
uri = resource.get("uri", "")
316327
binary_results.append(
317328
ToolBinaryResult(
318-
data=resource["blob"],
319-
mime_type=resource.get("mimeType", "application/octet-stream"),
329+
data=blob,
330+
mime_type=mime_type
331+
if isinstance(mime_type, str)
332+
else "application/octet-stream",
320333
type="resource",
321-
description=resource.get("uri", ""),
334+
description=uri if isinstance(uri, str) else "",
322335
)
323336
)
324337

325338
return ToolResult(
326339
text_result_for_llm="\n".join(text_parts),
327-
result_type="failure" if call_result.get("isError") else "success",
340+
result_type="failure" if call_result.get("isError") is True else "success",
328341
binary_results_for_llm=binary_results if binary_results else None,
329342
)

0 commit comments

Comments
 (0)