Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gkaretka committed Oct 29, 2024
1 parent cdac48e commit ccd240c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ which would lead to this in your prompt:
- `None` - no structured output is used (equals to toggle being in off state)
- `Function calling` - hacky way of implementing structured outputs before `Response format` was implemented into API
- `Response format` - new way of implementing structured outputs
4. Provide JSON schema in `json schema` text input (can be generated from `pydantic` model or `zod` if you use `nodejs`):
4. Provide JSON schema in `json schema` text input (can be generated from `pydantic` model or `zod` if you use `nodejs`) where `title` must satisfy `'^[a-zA-Z0-9_-]+$'`:
```json
{
"title": "get_delivery_date",
Expand Down
8 changes: 2 additions & 6 deletions prompterator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,10 @@ def format_traceback_for_markdown(text):
return re.sub(r"\n", "\n\n", text)


def normalize_name(name: str):
return re.sub("[^a-zA-Z0-9_]", "_", name).lower()


def build_function_calling_tooling(json_schema):
schema = json.loads(json_schema)
function = schema.copy()
function_name = normalize_name(function.pop("title"))
function_name = function.pop("title")
description = (
function.pop("description")
if function.get("description", None) is not None
Expand All @@ -411,7 +407,7 @@ def build_function_calling_tooling(json_schema):

def build_response_format(json_schema):
json_schema = json.loads(json_schema)
schema = {"name": normalize_name(json_schema.pop("title")), "schema": json_schema, "strict": True}
schema = {"name": json_schema.pop("title"), "schema": json_schema, "strict": True}
response_format = {"type": "json_schema", "json_schema": schema}

return response_format
Expand Down

0 comments on commit ccd240c

Please sign in to comment.