-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- address PR comments Co-authored-by: Sam Sucik <[email protected]>
- Loading branch information
Showing
5 changed files
with
99 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import json | ||
|
||
|
||
def build_function_calling_tooling(json_schema: str): | ||
""" | ||
@param json_schema: contains desired output schema in proper Json Schema format | ||
@return: (tools, function name) where | ||
- tools is list of tools (single function in this case) callable by OpenAI model | ||
in function calling mode. | ||
- function name is the name of the desired function to be called | ||
""" | ||
schema = json.loads(json_schema) | ||
function = schema.copy() | ||
function_name = function.pop("title") | ||
description = ( | ||
function.pop("description") | ||
if function.get("description", None) is not None | ||
else function_name | ||
) | ||
tools = [ | ||
{ | ||
"type": "function", | ||
"function": { | ||
"name": function_name, | ||
"description": description, | ||
"parameters": function, | ||
}, | ||
} | ||
] | ||
|
||
return tools, function_name | ||
|
||
|
||
def build_response_format(json_schema: str): | ||
""" | ||
@param json_schema: contains desired output schema in proper Json Schema format | ||
@return: dict with desired response format directly usable with OpenAI API | ||
""" | ||
json_schema = json.loads(json_schema) | ||
schema = {"name": json_schema.pop("title"), "schema": json_schema, "strict": True} | ||
response_format = {"type": "json_schema", "json_schema": schema} | ||
|
||
return response_format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters