Skip to content

Commit 9bbed97

Browse files
committed
Rename .json_schema into .signature and use the openAI tool description format
Signed-off-by: Louis Mandel <[email protected]>
1 parent 53f1f74 commit 9bbed97

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

pdl-live-react/src/pdl_ast.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,10 +2869,10 @@ export type Return =
28692869
| EmptyBlock
28702870
| null
28712871
/**
2872-
* Function schema computed from the function definition.
2872+
* Function signature computed from the function definition.
28732873
*
28742874
*/
2875-
export type JsonSchema = string | null
2875+
export type Signature = string | null
28762876
export type PdlBlock =
28772877
| boolean
28782878
| number
@@ -2941,7 +2941,7 @@ export interface FunctionBlock {
29412941
kind?: Kind20
29422942
function: Function
29432943
return: Return
2944-
json_schema?: JsonSchema
2944+
signature?: Signature
29452945
}
29462946
/**
29472947
* Enumerated type.

src/pdl/pdl-schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3764,7 +3764,7 @@
37643764
"description": "Body of the function.\n ",
37653765
"title": "Return"
37663766
},
3767-
"json_schema": {
3767+
"signature": {
37683768
"anyOf": [
37693769
{
37703770
"contentMediaType": "application/json",
@@ -3776,8 +3776,8 @@
37763776
}
37773777
],
37783778
"default": null,
3779-
"description": "Function schema computed from the function definition.\n ",
3780-
"title": "Json Schema"
3779+
"description": "Function signature computed from the function definition.\n ",
3780+
"title": "Signature"
37813781
}
37823782
},
37833783
"required": [

src/pdl/pdl_ast.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ class FunctionBlock(LeafBlock):
420420
returns: "BlockType" = Field(..., alias="return")
421421
"""Body of the function.
422422
"""
423-
json_schema: Optional[Json] = None
424-
"""Function schema computed from the function definition.
423+
signature: Optional[Json] = None
424+
"""Function signature computed from the function definition.
425425
"""
426426

427427
# Field for internal use

src/pdl/pdl_interpreter.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -895,16 +895,16 @@ def process_block_body(
895895
if block.def_ is not None:
896896
scope = scope | {block.def_: closure}
897897
closure.pdl__scope = scope
898-
json_schema: dict[str, Any] = {}
898+
signature: dict[str, Any] = {"type": "function"}
899899
if block.def_ is not None:
900-
json_schema |= {"name": block.def_}
900+
signature["name"] = block.def_
901901
if block.description is not None:
902-
json_schema |= {"description": block.description}
902+
signature["description"] = block.description
903903
if block.function is not None:
904-
json_schema |= get_json_schema(block.function, False) or {}
904+
signature["parameters"] = get_json_schema(block.function, False) or {}
905905
else:
906-
json_schema |= {"type": "object"}
907-
closure.json_schema = json_schema
906+
signature["parameters"] = {}
907+
closure.signature = signature
908908
result = PdlConst(closure)
909909
background = PdlList([])
910910
trace = closure.model_copy(update={})

tests/test_function.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ def test_function_call():
2020
assert text == "Hello world!"
2121

2222

23-
def test_hello_json_schema():
23+
def test_hello_signature():
2424
result = exec_dict(hello_def, output="all")
2525
closure = result["scope"]["hello"]
26-
assert closure.json_schema == {
26+
assert closure.signature == {
2727
"name": hello_def["def"],
2828
"description": hello_def["description"],
29-
"type": "object",
29+
"type": "function",
30+
"parameters": {},
3031
}
3132

3233

@@ -49,16 +50,19 @@ def test_function_params():
4950
assert text == "Hello World!"
5051

5152

52-
def test_hello_params_json_schema():
53+
def test_hello_params_signature():
5354
result = exec_dict(hello_params, output="all")
5455
closure = result["scope"]["hello"]
55-
assert closure.json_schema == {
56+
assert closure.signature == {
5657
"name": hello_params["text"][0]["def"],
5758
"description": hello_params["text"][0]["description"],
58-
"type": "object",
59-
"properties": {"name": {"type": "string"}},
60-
"required": ["name"],
61-
"additionalProperties": False,
59+
"type": "function",
60+
"parameters": {
61+
"type": "object",
62+
"properties": {"name": {"type": "string"}},
63+
"required": ["name"],
64+
"additionalProperties": False,
65+
},
6266
}
6367

6468

0 commit comments

Comments
 (0)