refactor(providers): refactor text handlers #472
+648
−981
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR refactors
Texthandlers to extendTextHandlerabstract class, once standarized many methods where the same between different providers.I removed parameters that were being passed between calls like
$requestand$responseand use instead class properties.This was initially part of #413 but I decided to separate it, once this and a refactor to
Streamhandlers is done it's going to be easier to finish that PR.Changes
$requestin constructor not ashandleparameter.tempResponseso we have something consistent to pass to events feat: add events #413buildHttpRequestPayload, it can be useful to build the request and use it in batched requests Request pooling? #417.Differences to clarify
There were some small differences in some providers I think my changes are working but it would be great to have that reviewed.
OpenAI ToolMap
In OpenAI
Texthandler in thehandlemethod toolCalls to be passed toAssitantMessageare evaluated consideringreasoningprism/src/Providers/OpenAI/Handlers/Text.php
Line 55 in 5697edb
while in
addStepmethod reasoning is ignored, I uniformed it to include reasoning also intempResponsethat is then used to buildStepinaddStep.Ollama finish reason
In Ollama
Texthandler, since there is no different finish reason for tool calls, it's alwaysthere was a check before the finishReason match, to keep it consistent with other providers I moved that check to
mapFinishReasonand I'm settingFinishReason::ToolCallswhen recognized:FinishReason::Length
Some providers have
FinishReason::Lengthsome don't, I left the match for all managed byhandleStop.Mistral inifinite steps
In Mistral
maxStepsset to 0 is taken as no limit, I don't see any reference in documentation, personally I'd rather set an high number but I would never risk an infinite loop.Since in this PR all providers are using the same check that has been removed.
Other classes changed
I had to do small changes in other handler classes because I am not passing any parameter to
validateResponse, not very elegant but I hope that can be fixed in a future refactor for the other handlers.@ChrisB-TL I would appreciate, if you have time, if you can have a look.