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]: Python SDK introduces double-quotes #2209

Open
jbaron opened this issue Dec 2, 2024 · 4 comments
Open

[Bug]: Python SDK introduces double-quotes #2209

jbaron opened this issue Dec 2, 2024 · 4 comments
Assignees
Labels
bug Something isn't working Python Change/fix applies to Python. If all three, use the 'JS & dotnet & Python' label

Comments

@jbaron
Copy link

jbaron commented Dec 2, 2024

Language

Python

Version

latest

Description

When using the Python teams-ai library, the input messages receive additional double-quotes. This doesn't happen with the initial input, but happens with the sub-sequential inputs.

The action is still correct and has just the plain string, but somewhere in the process of converting the action into messages it goes wrong.

So for example when I enter in Teams, I see '"great"' back in the message history (so it has additional double-quotes).

This makes the LLM also use additional quotes in the response or format snippets badly.

When debugging the JavaScript version, this behavior was NOT observed.

Reproduction Steps

1. Enter first prompt (1 + 1) and wait for result
2. Enter second prompt (great)
3. During debugging observe that the message history has additional double-quotes around great.
@jbaron jbaron added the bug Something isn't working label Dec 2, 2024
@jbaron
Copy link
Author

jbaron commented Dec 2, 2024

The issue seems to be with the used to_string function that doesn't checks for plain strings and as a result uses json or yaml encoding.

def to_string(tokenizer: Tokenizer, value: Any, as_json: bool = False) -> str:
    """
    Converts a value to a string representation.
    Dates are converted to ISO strings and Objects are converted to JSON or YAML,
    whichever is shorter.

    Args:
        tokenizer (Tokenizer): The tokenizer object used for encoding.
        value (Any): The value to be converted.
        as_json (bool, optional): Flag indicating whether to return the value as JSON string.
        Defaults to False.

    Returns:
        str: The string representation of the value.
    """
    if value is None:
        return ""

    if hasattr(value, "isoformat") and callable(value.isoformat):
        # Used when the value is a datetime object
        return value.isoformat()
    value = todict(value)

    if as_json:
        return json.dumps(value, default=lambda o: o.__dict__, ensure_ascii=False)

    # Return shorter version of object
    yaml_str = yaml.dump(value, allow_unicode=True)
    json_str = json.dumps(value, default=lambda o: o.__dict__, ensure_ascii=False)
    if len(tokenizer.encode(yaml_str)) < len(tokenizer.encode(json_str)):
        return yaml_str

    return json_str

If the value is of the type string, it shouldn't use JSON or YAML encoding.

@Nivedipa-MSFT
Copy link

@jbaron - Thank you for your inquiry about your Teams app development issue! We will check and update you soon.

@sayali-MSFT
Copy link

Hello @jbaron ,Thank you for your patience! We have reported this as a bug for further investigation.

We will keep you updated as soon as we receive further information. Thank you for bringing this to our attention!

@corinagum corinagum added the Python Change/fix applies to Python. If all three, use the 'JS & dotnet & Python' label label Dec 9, 2024
@corinagum corinagum self-assigned this Dec 9, 2024
@corinagum
Copy link
Collaborator

Investigating

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Python Change/fix applies to Python. If all three, use the 'JS & dotnet & Python' label
Projects
None yet
Development

No branches or pull requests

4 participants