-
Notifications
You must be signed in to change notification settings - Fork 16
Provider base and implementation for Anthropic, Google, and OpenAI via common abstractions #39
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
Conversation
…ider infrastructure, as well as an actual OpenAI implementation based on it (WIP).
@JasonTheAdams I implemented this for an early reference. Don't try it, it doesn't work - for that reason, also ignore any of the PHPCS / PHPStan errors :) |
@JasonTheAdams Note: For now, I put all the abstract and base classes into Part of me likes them being in one place as they're so closely related, which goes back to my earlier preference to not separate provider and model code into different namespaces. But I'm happy to stay aligned with our current approach, we just have to figure out how that would work best. |
… fix some minor bugs.
@JasonTheAdams Aside: d9b32fc shows how complex maintaining the list of models and their capabilities is. The current list here for the OpenAI provider is purely based on my own testing that I did for AI Services, so even that is probably slightly inaccurate or out of date. Realistically, there's just no way for us to always stay on top of all those nuances, especially not for all the different providers. In any case, that's what's needed for now, until we hopefully find a way to source this from some more reliable external database of sorts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finished going through all the code! Tons of great work! Excited to wrap this up!
src/Providers/ApiBasedImplementation/GenerateTextApiBasedProviderAvailability.php
Outdated
Show resolved
Hide resolved
src/Providers/ApiBasedImplementation/ListModelsApiBasedProviderAvailability.php
Outdated
Show resolved
Hide resolved
src/Providers/ApiBasedImplementation/ListModelsApiBasedProviderAvailability.php
Outdated
Show resolved
Hide resolved
src/Providers/OpenAiCompatibleImplementation/AbstractOpenAiCompatibleModelMetadataDirectory.php
Show resolved
Hide resolved
src/Providers/OpenAiCompatibleImplementation/AbstractOpenAiCompatibleTextGenerationModel.php
Outdated
Show resolved
Hide resolved
src/Providers/OpenAiCompatibleImplementation/AbstractOpenAiCompatibleTextGenerationModel.php
Show resolved
Hide resolved
…ss/php-ai-client into provider-base-and-implementation
Co-authored-by: Jason Adams <[email protected]>
…singModelConfig method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks really good to me. Left a few comments though feel free to ignore those if they're not valid. Was giving this a look to see how we would implement this in ClassifAI
src/ProviderImplementations/Anthropic/AnthropicModelMetadataDirectory.php
Outdated
Show resolved
Hide resolved
src/ProviderImplementations/OpenAi/OpenAiModelMetadataDirectory.php
Outdated
Show resolved
Hide resolved
src/Providers/OpenAiCompatibleImplementation/AbstractOpenAiCompatibleTextGenerationModel.php
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love it! LGTM!! 🎉
This PR provides basic implementations for text generation for Anthropic, Google, and OpenAI, all based on their respective OpenAI API compatible REST API endpoints. While Anthropic and Google provide their alternative API specifications that they generally recommend, focusing on their OpenAI API compatible endpoints first is a more pragmatic approach that will get us up to speed more quickly. We can reconsider using their recommended APIs later, if there is any additional value from doing that.
For documentation on the relevant OpenAI API specifications for the endpoints this implements support for, see:
The approach is as follows:
HttpTransporter
andRequestAuthentication
to the provider classes, orchestrated viaProviderRegistry
. This ensures under the hood that every relevant provider class has the necessary implementations set, without the provider class implementation itself having to worry about that.A subsequent PR will be opened to implement image generation for Google and OpenAI (Anthropic doesn't support that).