Skip to content

Commit

Permalink
chore: [deref] add doc string content
Browse files Browse the repository at this point in the history
  • Loading branch information
luochen1990 committed Aug 7, 2024
1 parent 776655c commit a74e311
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ai_powered/schema_deref.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ def deref(schema: dict[str, Any]) -> dict[str, Any]:
'''
msgspec 给出的 json schema 会包含 $ref 字段,这个函数用于将 $ref 字段替换为具体的 schema
这一行为是符合标准的,见: https://json-schema.org/understanding-json-schema/structuring#dollarref
但 OpenAI 及大部分 LLM 服务商尚不支持 $ref 字段,所以需要将其展开以获得更好的效果.
当然这一做法也有其局限性,比如无法处理环状引用,但这只能等到服务商支持 $ref 字段后再解决.
{'$ref': '#/$defs/ArgObj', '$defs': {'ArgObj': {'title': 'ArgObj', 'type': 'object', 'properties': {'python_expression': {'type': 'string'}}, 'required': ['python_expression']}}}
最终返回结果的最外层形如:
Expand Down

0 comments on commit a74e311

Please sign in to comment.