Skip to content
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

bug: Use repr() for chat tool calls when exporting markdown #30

Merged
merged 6 commits into from
Jan 8, 2025

Conversation

schloerke
Copy link
Contributor

@schloerke schloerke commented Dec 30, 2024

If we're putting the value in a python code block, then it is safe to assume the code can be run. repr() should return eval-able objects (which do not need an extra layer of quoting).

First seen in :

## User


```python
# tool result (toolu_bdrk_01CmkqJNgwQLAG4HseMnvAR6)
"{"email":"[email protected]"}"
```

Desired output:

## User


```python
# tool result (toolu_bdrk_01CmkqJNgwQLAG4HseMnvAR6)
{"email":"[email protected]"}
```

When using repr(), strings will be quoted. JSON will be given as is.

>>> a = str("asfd") 
>>> print(f"\n{a}\n")

asfd

>>> a = repr("asfd")
>>> 
>>> print(f"\n{a}\n")

'asfd'

>>> a = str({"a": 1, "b": 2})
>>> print(f"\n{a}\n")

{'a': 1, 'b': 2}

>>> a = repr({"a": 1, "b": 2})
>>> print(f"\n{a}\n")

{'a': 1, 'b': 2}

If we're putting the value in a python code block, then it is safe to assume the code can be run. `repr()` should return eval-able objects (which do not need an extra layer of quoting).
@schloerke schloerke requested a review from cpsievert December 30, 2024 21:33
@schloerke schloerke self-assigned this Dec 30, 2024
@schloerke
Copy link
Contributor Author

Still isn't what I want

@schloerke schloerke marked this pull request as draft December 30, 2024 22:32
@schloerke
Copy link
Contributor Author

Need to use pprint.pformat, but I can see rich is already available.

@schloerke
Copy link
Contributor Author

😂 Link

E       assert 'Joe: sage green' in "I cannot answer this question. The available function `favorite_color` does not contain any information about Joe and Hadley's favorite colors.\n"
E        +  where "I cannot answer this question. The available function `favorite_color` does not contain any information about Joe and Hadley's favorite colors.\n" = str(<chatlas._chat.ChatResponse object at 0x7fcc73020a70>)

@schloerke schloerke marked this pull request as ready for review December 31, 2024 15:50
@schloerke
Copy link
Contributor Author

The test that is failing is a false-positive. I re-ran it once and it did not improve. 🙄

@schloerke
Copy link
Contributor Author

Got it to pass by waiting. woot

@schloerke schloerke changed the title bug: Use repr() on for chat's value bug: Use repr() for chat tool calls when exporting markdown Jan 8, 2025
@schloerke schloerke merged commit 52088cf into main Jan 8, 2025
3 of 6 checks passed
@schloerke schloerke deleted the schloerke-patch-1 branch January 8, 2025 15:29
schloerke added a commit that referenced this pull request Jan 8, 2025
* main:
  bug: Use `repr()` for chat tool calls when exporting markdown (#30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants