-
Notifications
You must be signed in to change notification settings - Fork 90
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
Code Standardization and Cleanup #40
Code Standardization and Cleanup #40
Conversation
…operly pass request parameters.
…llability for most models.
- audited async/await usage - added documentation - formatted files to loosely maintain an 80 characters per line limit
Highly appreciate the work you have done here, but I won't merge the code with TODO comments for now. I was aware of the inconsistent file format as the first pull requests came in - mostly whitespacing (tabs/spaces) and I planned to add an editorconfig to address this if there's time. But I didn't want to reject contributions just because of their coding style. Thanks a lot for helping me out with this. One thing about this pull request though: I am not a fan of sub 80-char line limits as imo they add a lot of noise. This is very subjective of course but for me this particularly complex code ... public async Task<IEnumerable<Message>> SendAs(ChatRole role, string message, IEnumerable<string> imagesAsBase64, CancellationToken cancellationToken = default)
{
_messages.Add(new Message(role, message, imagesAsBase64?.ToArray()));
var request = new ChatRequest
{
Messages = Messages.ToList(),
Model = Client.SelectedModel,
Stream = true
};
var answer = await Client.SendChat(request, Streamer, cancellationToken);
_messages = answer.ToList();
return Messages;
} ... is way easier to read than this: public async Task<IEnumerable<Message>> SendAs(
ChatRole role,
string message,
IEnumerable<string>? imagesAsBase64,
CancellationToken cancellationToken = default)
{
_messages.Add(new Message(
role, message, imagesAsBase64?.ToArray()));
var request = new ChatRequest
{
Messages = Messages.ToList(),
Model = Model,
Stream = true
};
var answer = await Client.SendChat(
request, Streamer, cancellationToken);
_messages = answer.ToList();
return Messages;
} Mostly because the lines are more "atomic" and the code structure is easier to capture visually. It also emphasizes the argument list less, which is also not that important as the code itself. I do break some lines by myself if I think it makes sense but certainly not for a virtual character limit. This idea is from the 80s where people didn't have phones with 4k displays. This rule is highly obsolete to me. That being said, this is not a show stopper for me. But I might go through a few code parts after merging and reformat them again, just that you know. |
Thank you for the input @awaescher.
|
I am thanking you for this update and not telling me to gtfo after beefing over the free work you wanted to share 😅
These are all personal preferences, I don't want to convince anyone that my opinion is the best. Would you do me the favor and remove the TODOs or introduce a breaking change? I could bump the major version for this. |
|
All requests end in "Request", all responses now end in "Response" or "ResponseStream".
Release is out → 2.0.1 |
Hi guys. This is what the generated code looks like:
It is generated from this specification: It's not 100% perfect and feedback is still needed, but it's a solution that will work without the need to manually maintain specific implementation details |
Hi @HavenDV, I'm a big fan of leveraging OpenAPI clients when they're available! I also agree that it'd be great to have some deduplication of efforts. Can you open an issue to track the effort? With no OpenAPI spec currently, officially released, it's a bit of a moving target. But I think it would be a worthwhile endeavor to have an exploratory branch to explore how that might look. |
+1 for the issue, or even better a discussion which I just enabled for this repository. |
This is dependent on #38, or rather, it includes the changes from #38.
I took a look over the code and tried to standardize and correct a few inconsistencies. I also added a couple TODOs to help draw attention to additional areas that might lead to confusion, but where the changes would potentially be breaking. I primarily addressed the following things:
Task
/Task<T>
where appropriate. This change lets callers handle awaiting and will simplify future error handling.ShowModelResponse.Details
had its type changed toDetails
.ShowModelResponseDetails
removedRunningModel
changed to inherit fromModel
. Duplicate properties removed.GenerateEmbeddingRequest.Options
had its type changed toRequestOptions
fromstring
.