Skip to content

Commit

Permalink
update non=object schema
Browse files Browse the repository at this point in the history
  • Loading branch information
luyaxi committed Aug 23, 2024
1 parent ecdeda9 commit 401d307
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
32 changes: 27 additions & 5 deletions codelinker/linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ async def request(

schema = return_type.json_schema()
schema = replace_refs(schema, schema)
schema["description"] = return_type.__doc__ if return_type.__doc__ is not None else ""

resolve_none_object = False
if schema["type"] != "object":
schema = {
"type": "object",
"properties": {
"content": schema
}
}
resolve_none_object = True

messages = deepcopy(messages)
if prompt is not None:
messages.append({"role": "user", "content": prompt})
Expand All @@ -71,25 +83,35 @@ async def request(
messages=messages,
schemas=StructureSchema(
name=request_name,
description=schema.pop("description", ""),
description=schema.pop("description"),
parameters=schema
),
**completions_kwargs,
)
if isinstance(rets, StructuredRet):
if resolve_none_object:
return return_type.validate_python(rets.content["content"])
return return_type.validate_python(rets.content)
elif isinstance(rets, list):
returns = []
for item in rets:
if isinstance(item, list):
rets = []
for i in item:
rets.append(
return_type.validate_python(i.content))
if resolve_none_object:
rets.append(
return_type.validate_python(i.content["content"]))
else:
rets.append(
return_type.validate_python(i.content))
returns.append(rets)
elif isinstance(item, StructuredRet):
returns.append(
return_type.validate_python(item.content))
if resolve_none_object:
returns.append(
return_type.validate_python(item.content["content"]))
else:
returns.append(
return_type.validate_python(item.content))
else:
raise ValueError("Invalid return type")
else:
Expand Down
2 changes: 1 addition & 1 deletion codelinker/request/objGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def _chatcompletion_with_tool_call(
raise ValueError(
"You can't provide schemas with tools/tool_choice!")

if isinstance(schemas, StructureSchema):
if isinstance(schemas, StructureSchema):
kwargs["tools"] = [{
"type": "function",
"function": {
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "codelinker"
version = "0.2.10"
version = "0.2.11"
description = ""
authors = ["luyaxi <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 401d307

Please sign in to comment.