Skip to content

Better structured outputs handling #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion defog/llm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
import json
import traceback
import re
from dataclasses import dataclass
from typing import Dict, List, Optional, Any, Union, Callable

Expand Down Expand Up @@ -872,7 +873,17 @@ async def _process_openai_response(
else:
# No tools provided
if response_format and model not in ["o1-mini", "o1-preview"]:
content = response.choices[0].message.parsed
try:
content = response.choices[0].message.parsed
except Exception as e:
content = response.choices[0].message.content
# parse the content as json
try:
# clean up any markdown formatting
content = re.sub(r"```(.*)```", r"\1", content)
content = json.loads(content)
except Exception as e:
raise Exception(f"Error parsing content: {e}")
else:
content = response.choices[0].message.content

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def package_files(directory):
name="defog",
packages=find_packages(),
package_data={"defog": ["gcp/*", "aws/*"] + next_static_files},
version="0.68.0",
version="0.68.1",
description="Defog is a Python library that helps you generate data queries from natural language questions.",
author="Full Stack Data Pte. Ltd.",
license="MIT",
Expand Down