Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Bug fixes

* `.set_model_params()` now works correctly for `.*_async()` methods. (#198)
* `.chat_structured()` results are now included correctly into the multi-turn conversation history. (#203)

## [0.13.2] - 2025-10-02

Expand Down
3 changes: 2 additions & 1 deletion chatlas/_provider_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ def _as_content_block(content: Content) -> "ContentBlockParam":
if isinstance(content, ContentText):
return {"text": content.text, "type": "text"}
elif isinstance(content, ContentJson):
return {"text": "<structured data/>", "type": "text"}
text = orjson.dumps(content.value).decode("utf-8")
return {"text": text, "type": "text"}
elif isinstance(content, ContentPDF):
return {
"type": "document",
Expand Down
3 changes: 2 additions & 1 deletion chatlas/_provider_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ def _as_part_type(self, content: Content) -> "Part":
if isinstance(content, ContentText):
return Part.from_text(text=content.text)
elif isinstance(content, ContentJson):
return Part.from_text(text="<structured data/>")
text = orjson.dumps(content.value).decode("utf-8")
return Part.from_text(text=text)
elif isinstance(content, ContentPDF):
from google.genai.types import Blob

Expand Down
8 changes: 4 additions & 4 deletions chatlas/_provider_openai_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,8 @@ def _turns_as_inputs(turns: list[Turn]) -> list["ChatCompletionMessageParam"]:
if isinstance(x, ContentText):
content_parts.append({"type": "text", "text": x.text})
elif isinstance(x, ContentJson):
content_parts.append(
{"type": "text", "text": "<structured data/>"}
)
text = orjson.dumps(x.value).decode("utf-8")
content_parts.append({"type": "text", "text": text})
elif isinstance(x, ContentToolRequest):
tool_calls.append(
{
Expand Down Expand Up @@ -286,7 +285,8 @@ def _turns_as_inputs(turns: list[Turn]) -> list["ChatCompletionMessageParam"]:
if isinstance(x, ContentText):
contents.append({"type": "text", "text": x.text})
elif isinstance(x, ContentJson):
contents.append({"type": "text", "text": "<structured data/>"})
text = orjson.dumps(x.value).decode("utf-8")
contents.append({"type": "text", "text": text})
elif isinstance(x, ContentPDF):
contents.append(
{
Expand Down
3 changes: 2 additions & 1 deletion chatlas/_provider_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ def _as_request_messages(self, turns: list[Turn]):
}
)
elif isinstance(x, ContentJson):
req.content = req.content or "<structured data/>"
text = orjson.dumps(x.value).decode("utf-8")
req.content = req.content or text

res.append(req)
return res
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ def assert_data_extraction(chat_fun: ChatFun):
assert data2.author == "Hadley Wickham"
assert data2.title.lower() == "apples are tasty"

class Person(BaseModel):
name: str
age: int
data = chat.chat_structured("Generate the name and age of a random person.", data_model=Person)
response = chat.chat("What is the name of the person?")
assert data.name in str(response)


def assert_images_inline(chat_fun: ChatFun, stream: bool = True):
img = Image.new("RGB", (60, 30), color="red")
Expand Down