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

Unsafe overridden ToString on ChatCompletion #152

Open
isaacabraham opened this issue Jul 31, 2024 · 3 comments
Open

Unsafe overridden ToString on ChatCompletion #152

isaacabraham opened this issue Jul 31, 2024 · 3 comments
Assignees

Comments

@isaacabraham
Copy link

This override crashes as soon as there is no content returned e.g. in the case of a FunctionTool response.

@sunnynagavo
Copy link

sunnynagavo commented Aug 9, 2024

may be change it to this ?

/// <summary>Returns the text of the first element in the Content collection, or an empty string if the collection is null or empty.</summary>
public override string ToString() => Content != null && Content.Count > 0 ? Content[0].Text : string.Empty;

@joseharriaga
Copy link
Collaborator

Thank you for reaching out, @isaacabraham ! Based on how the chat completions API has evolved over the past few months and given that the Content property is not always present depending on the circumstances, we have decided to remove the ToString() override for now because it is a common cause of confusion. Instead, our current recommendation is for users to handle the ChatCompletion's Content property themselves based on their specific needs (in other words, based on if they expect function tool calls, refusals, etc.).

@joseharriaga joseharriaga self-assigned this Oct 3, 2024
@isaacabraham
Copy link
Author

@joseharriaga I would agree with this. Overriding ToString() is a somewhat opaque thing to do - especially if it's encapsulating some logic or varying data. Having a specific, well-known property sounds a safer and more reasonable thing to do.

ToString() should never crash - it's called implicitly in many areas of .NET applications.

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

No branches or pull requests

3 participants