feat: [#916] Implement AI module with provider resolver and OpenAI driver#1421
Open
feat: [#916] Implement AI module with provider resolver and OpenAI driver#1421
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1421 +/- ##
==========================================
+ Coverage 65.94% 68.20% +2.25%
==========================================
Files 353 357 +4
Lines 26083 27630 +1547
==========================================
+ Hits 17201 18844 +1643
+ Misses 8141 7937 -204
- Partials 741 849 +108 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Conversation.Promptno longer acceptscontext.Context; context is bound once viaAI.WithContext(ctx)and reused across all operationsProviderResolverlazily initialises and caches AI providers from config, withViaaccepting a liveProviderinstance or afunc() (Provider, error)factoryAgentPromptinto chat completion requests with a configurable API key, base URL, and default text model (gpt-5.4)Closes #916
Why
The AI module now has a concrete implementation behind its interfaces. Moving context out of
Conversation.Promptand intoAI.WithContext(ctx)keeps the per-prompt call clean: callers bind a context once and every subsequentPromptandAgentcall carries it automatically without repetition.The new
ProviderResolverreads from theaiconfig key, initialises each driver on first use, and caches it, so the construction cost is paid only once. TheViafield accepts either a liveProviderfor direct injection (e.g. in tests) or afunc() (Provider, error)for lazy construction, keeping the bootstrap path flexible.The OpenAI provider maps
Agent.Instructions()to the OpenAI system message,Agent.Messages()to the preceding conversation history, and the currentInputto the final user message, then callsChat.Completions.Newvia theopenai-goclient. When the provider config omits a default text model, it falls back togpt-5.4.