Commit 841dd68
authored
feat: Vertex AI integration (#128)
* Add Vertex AI backend support
Introduce Vertex AI (Google) backend integration: add Vertex-specific settings, models, and services to enable using Vertex AI models.
Key changes:
- Add VertexInferenceParams and GoogleServiceAccountAuth to domain configuration; register BackendType.Vertex and include GoogleServiceAccountAuth in MaINSettings.
- Add Vertex model constants and cloud model records (Gemini/Veo) and register Vertex in LLMApiRegistry.
- Implement VertexService (LLM service) with request parameter mapping, model/endpoint URL construction, and validation of service-account config.
- Add VertexTokenProvider to create and exchange JWT for OAuth2 access tokens using a service account private key.
- Wire Vertex into factory, bootstrapper, HTTP clients, and service constants so it can be resolved and used.
- Add ChatExampleVertex example and register it in the examples program.
- Small ChatService fix: ensure BackendParams are created from model backend and message types set using resolved backend.
- Add local claude settings file used by the infer page tooling.
This commit enables selecting BackendType.Vertex and calling Vertex-hosted models via service-account authentication and token exchange.
* Add shared token cache and refresh lock for Vertex token
Introduce a static ConcurrentDictionary cache keyed by ClientEmail and a SemaphoreSlim to prevent concurrent token refreshes in VertexTokenProvider. Replace per-instance _cachedToken/_tokenExpiry with a CachedToken record, double-check cache after acquiring the lock, and store refreshed tokens with a buffered expiry. Also apply minor formatting/inline null-coalescing cleanup in VertexService getters.
* Add Vertex AI backend support and UI
Introduce Vertex AI support across the InferPage UI and settings plumbing. Changes include:
- Add a new BackendOption (id 9) for Vertex AI and corresponding selection/lookup logic in Settings.razor and Program.cs; Program warns that Vertex requires service account credentials.
- Extend the settings UI to collect Vertex auth fields (Project ID, Client Email, Private Key, Location), with toggleable key visibility and required-field validation to enable saving.
- Persist Vertex auth separately via SettingsService.SaveVertexAuthAsync/GetVertexAuthAsync and a VertexAuthStorage record; private_key is stored outside general settings. Also add VertexLocation to InferPageSettings.
- Pass a GoogleServiceAccountConfig (vertexAuth) through Utils.ApplySettings so MaINSettings.GoogleServiceAccountAuth can be set when selecting Vertex.
- Add model identifier constant for gemini-2.5-pro and fix a CloudModel reference to use Models.Gemini.Gemini2_5Pro.
These changes wire up UI, storage, and application settings so Vertex can be configured from the Settings page and applied at runtime.
* Fix vertex file send for pdf files (without ocr)
Expose CreateMemoryWithVertex on IMemoryFactory and implement it in MemoryFactory to build a KernelMemory configured for Vertex (Gemini) text generation and embeddings using a bearer token provider, location and projectId. Add PDF MIME detection in ChatHelper. Extend VertexService.AskMemory to bypass KernelMemory for multimodal requests: collect inline images/PDFs, convert non-native files to text via DocumentProcessor, aggregate text/context/memory, inject optional grammar JSON, and send combined content to Gemini; includes helper methods for file/stream processing and a list of Gemini-native extensions. Also add necessary usings and temporary file handling for stream processing.
* fix: Use model backend when creating BackendParams
Assign the backend from the chat model before creating BackendParams and use it to initialize BackendParams and to set message types. This ensures message Type mapping is based on model.Backend (and avoids relying on BackendParams.Backend prior to initialization), clarifying initialization order and avoiding potential mismatches.
* final improvements
Add a VertexExample.Setup helper and update examples to call it for Google service account configuration.
Refactor GoogleServiceAccountTokenProvider: use a per-client-email ConcurrentDictionary cache and per-email SemaphoreSlim locks, parse token responses via HttpClient.Json APIs, target oauth2.googleapis.com/token, add IDisposable to dispose RSA, improve error messages and token expiry handling.
Refactor VertexService: centralize GoogleServiceAccountConfig access via Auth property, build endpoints from Auth.ProjectId, streamline GetApiKey/GetApiName/ValidateApiKey, and reorganize multimodal file processing by introducing AppendDocument, BuildQuery and MergeInlineContent helpers, renaming native extensions and cleaning up temp file handling. Small logging and clarity improvements throughout.
* Add Vertex Imagen image generation service
Introduce support for Google Vertex Imagen image generation: add VertexImageGenService to call Vertex AI predict endpoints (uses service account token, default model/location, decodes base64 image into ChatResult), register BackendType.Vertex in ImageGenServiceFactory, add model constant (Imagen4_0_Generate) and CloudModel record (VertexImagen4_0Generate). Also adjust Home.razor injections and minor backendKey formatting. Includes basic response/error handling and model name extraction for publisher prefixes.
* Refactor: replace hardcoded image gen model constants with central ModelRegistry
Introduce new image-generation models and centralize image-gen logic: added Models constants (Imagen4_0_FastGenerate, Flux1Shnell) and new Cloud/Local model records for those models. Replace ad-hoc FLUX checks with ModelRegistry.TryGetById(...).HasImageGeneration across ChatMapper, AgentService, ChatService, and AgentStateManager. Update image generation services (Gemini, OpenAI, Vertex, Xai) to resolve default model IDs from Models, pass the resolved model through to ChatResult, and remove per-service hardcoded model constants. Also add necessary using/import adjustments and improve chat model availability handling in ChatService.
* Add MCP for vertex
Add support for Vertex AI Gemini chat completions and expose location on Mcp. Mcp.cs: introduce a new Location property with default "us-central1". McpService.cs: refactor InitializeChatCompletions to accept the Mcp config (and derive backend and model from it), add a using for LLMService.Auth, and wire up a Vertex backend case that creates a Google service-account token provider, builds a bearer token delegate, normalizes the model name, and registers the VertexAIGemini chat completion with the kernel using config.Location and the project ID. Also adjust the promptSettings call site to pass the config. Includes an auth presence check that throws if Vertex credentials are not configured.
* versioning
* Add new cloud models and XAI reasoning support
Introduce multiple new cloud model definitions and update Groq model constants, plus implement streaming parsing in XaiService.
Changes include:
- Added Gemini NanoBanana and several xAI models (Grok 4.20/4.1 variants, GrokImagine image/pro) and new Groq models (Llama3_3_70b, GptOss120b). Renamed constant Llama3_1_8bInstant -> Llama3_1_8b and added DeepSeek Chat; increased DeepSeek Reasoner token limit.
- Updated example and integration tests to use the renamed Groq model constant.
- Added ProcessChatCompletionChunk in XaiService to handle streaming content, incremental reasoning deltas, and encrypted reasoning blobs; added JSON helper types and System.Text.Json imports to support parsing.
These changes add support for new backends/models and improve handling of xAI streaming/ reasoning responses.1 parent 4734cb4 commit 841dd68
File tree
42 files changed
+1068
-75
lines changed- Examples/Examples
- Chat
- Utils
- MaIN.Core.E2ETests
- Releases
- src
- MaIN.Core
- MaIN.Domain
- Configuration
- BackendInferenceParams
- Vertex
- Entities
- Models
- Concrete
- MaIN.InferPage
- Components/Pages
- Services
- MaIN.Services
- Constants
- Mappers
- Services
- ImageGenServices
- LLMService
- Auth
- Factory
- Memory
- Utils
- Utils
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
42 files changed
+1068
-75
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| |||
186 | 187 | | |
187 | 188 | | |
188 | 189 | | |
| 190 | + | |
189 | 191 | | |
190 | 192 | | |
191 | 193 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
282 | | - | |
| 282 | + | |
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| 35 | + | |
33 | 36 | | |
0 commit comments