Skip to content

Commit c81ebd5

Browse files
raunakabaronszanto
authored andcommitted
feat: Vertex AI support (onyx-dot-app#4458)
* Add gemini well-known-llm-provider * Edit styling of anonymous function * Remove space * Edit how advanced options are displayed * Add VertexAI to acceptable llm providers * Add new `FileUploadFormField` component * Edit FileUpload component * Clean up logic for displaying native llm providers; add support for more complex `CustomConfigKey` types * Fix minor nits in web app * Add ability to pass vertex credentials to `litellm` * Remove unused prop * Change name of enum value * Add back ability to change form based on first time configurations * Create new Error with string instead of throwing raw string * Add more Gemini models * Edit mappings for Gemini models * Edit comment * Rearrange llm models * Run black formatter * Remove complex configurations during first time registration * Fix nit * Update llm provider name * Edit temporary formik field to also have the filename * Run reformatter * Reorder commits * Add advanced configurations for enabled LLM Providers
1 parent 47de5a5 commit c81ebd5

File tree

11 files changed

+413
-201
lines changed

11 files changed

+413
-201
lines changed

backend/onyx/llm/chat_llm.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from onyx.llm.interfaces import LLM
3737
from onyx.llm.interfaces import LLMConfig
3838
from onyx.llm.interfaces import ToolChoiceOptions
39+
from onyx.llm.llm_provider_options import CREDENTIALS_FILE_CUSTOM_CONFIG_KEY
3940
from onyx.llm.utils import model_is_reasoning_model
4041
from onyx.server.utils import mask_string
4142
from onyx.utils.logger import setup_logger
@@ -454,6 +455,13 @@ def _completion(
454455
if structured_response_format
455456
else {}
456457
),
458+
**(
459+
{
460+
"vertex_credentials": self.config.credentials_file,
461+
}
462+
if self.config.model_provider == "vertex_ai"
463+
else {}
464+
),
457465
**self._model_kwargs,
458466
)
459467
except Exception as e:
@@ -469,6 +477,12 @@ def _completion(
469477

470478
@property
471479
def config(self) -> LLMConfig:
480+
credentials_file: str | None = (
481+
self._custom_config.get(CREDENTIALS_FILE_CUSTOM_CONFIG_KEY, None)
482+
if self._custom_config
483+
else None
484+
)
485+
472486
return LLMConfig(
473487
model_provider=self._model_provider,
474488
model_name=self._model_version,
@@ -477,6 +491,7 @@ def config(self) -> LLMConfig:
477491
api_base=self._api_base,
478492
api_version=self._api_version,
479493
deployment_name=self._deployment_name,
494+
credentials_file=credentials_file,
480495
)
481496

482497
def _invoke_implementation(

backend/onyx/llm/interfaces.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class LLMConfig(BaseModel):
2626
api_base: str | None = None
2727
api_version: str | None = None
2828
deployment_name: str | None = None
29+
credentials_file: str | None = None
2930
# This disables the "model_" protected namespace for pydantic
3031
model_config = {"protected_namespaces": ()}
3132

backend/onyx/llm/llm_provider_options.py

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
from enum import Enum
2+
13
import litellm # type: ignore
24
from pydantic import BaseModel
35

46

7+
class CustomConfigKeyType(Enum):
8+
# used for configuration values that require manual input
9+
# i.e., textual API keys (e.g., "abcd1234")
10+
TEXT_INPUT = "text_input"
11+
12+
# used for configuration values that require a file to be selected/drag-and-dropped
13+
# i.e., file based credentials (e.g., "/path/to/credentials/file.json")
14+
FILE_INPUT = "file_input"
15+
16+
517
class CustomConfigKey(BaseModel):
618
name: str
19+
display_name: str
720
description: str | None = None
821
is_required: bool = True
922
is_secret: bool = False
23+
key_type: CustomConfigKeyType = CustomConfigKeyType.TEXT_INPUT
1024

1125

1226
class WellKnownLLMProviderDescriptor(BaseModel):
@@ -77,17 +91,50 @@ class WellKnownLLMProviderDescriptor(BaseModel):
7791
AZURE_PROVIDER_NAME = "azure"
7892

7993

94+
VERTEXAI_PROVIDER_NAME = "vertex_ai"
95+
VERTEXAI_DEFAULT_MODEL = "gemini-2.0-flash"
96+
VERTEXAI_DEFAULT_FAST_MODEL = "gemini-2.0-flash-lite"
97+
VERTEXAI_MODEL_NAMES = [
98+
# 2.5 pro models
99+
"gemini-2.5-pro-exp-03-25",
100+
# 2.0 flash-lite models
101+
VERTEXAI_DEFAULT_FAST_MODEL,
102+
"gemini-2.0-flash-lite-001",
103+
# "gemini-2.0-flash-lite-preview-02-05",
104+
# 2.0 flash models
105+
VERTEXAI_DEFAULT_MODEL,
106+
"gemini-2.0-flash-001",
107+
"gemini-2.0-flash-exp",
108+
# "gemini-2.0-flash-exp-image-generation",
109+
# "gemini-2.0-flash-thinking-exp-01-21",
110+
# 1.5 pro models
111+
"gemini-1.5-pro-latest",
112+
"gemini-1.5-pro",
113+
"gemini-1.5-pro-001",
114+
"gemini-1.5-pro-002",
115+
# 1.5 flash models
116+
"gemini-1.5-flash-latest",
117+
"gemini-1.5-flash",
118+
"gemini-1.5-flash-001",
119+
"gemini-1.5-flash-002",
120+
]
121+
122+
80123
_PROVIDER_TO_MODELS_MAP = {
81124
OPENAI_PROVIDER_NAME: OPEN_AI_MODEL_NAMES,
82125
BEDROCK_PROVIDER_NAME: BEDROCK_MODEL_NAMES,
83126
ANTHROPIC_PROVIDER_NAME: ANTHROPIC_MODEL_NAMES,
127+
VERTEXAI_PROVIDER_NAME: VERTEXAI_MODEL_NAMES,
84128
}
85129

86130

131+
CREDENTIALS_FILE_CUSTOM_CONFIG_KEY = "CREDENTIALS_FILE"
132+
133+
87134
def fetch_available_well_known_llms() -> list[WellKnownLLMProviderDescriptor]:
88135
return [
89136
WellKnownLLMProviderDescriptor(
90-
name="openai",
137+
name=OPENAI_PROVIDER_NAME,
91138
display_name="OpenAI",
92139
api_key_required=True,
93140
api_base_required=False,
@@ -126,14 +173,19 @@ def fetch_available_well_known_llms() -> list[WellKnownLLMProviderDescriptor]:
126173
api_base_required=False,
127174
api_version_required=False,
128175
custom_config_keys=[
129-
CustomConfigKey(name="AWS_REGION_NAME"),
176+
CustomConfigKey(
177+
name="AWS_REGION_NAME",
178+
display_name="AWS Region Name",
179+
),
130180
CustomConfigKey(
131181
name="AWS_ACCESS_KEY_ID",
182+
display_name="AWS Access Key ID",
132183
is_required=False,
133184
description="If using AWS IAM roles, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY can be left blank.",
134185
),
135186
CustomConfigKey(
136187
name="AWS_SECRET_ACCESS_KEY",
188+
display_name="AWS Secret Access Key",
137189
is_required=False,
138190
is_secret=True,
139191
description="If using AWS IAM roles, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY can be left blank.",
@@ -143,6 +195,26 @@ def fetch_available_well_known_llms() -> list[WellKnownLLMProviderDescriptor]:
143195
default_model="anthropic.claude-3-5-sonnet-20241022-v2:0",
144196
default_fast_model="anthropic.claude-3-5-sonnet-20241022-v2:0",
145197
),
198+
WellKnownLLMProviderDescriptor(
199+
name=VERTEXAI_PROVIDER_NAME,
200+
display_name="GCP Vertex AI",
201+
api_key_required=False,
202+
api_base_required=False,
203+
api_version_required=False,
204+
llm_names=fetch_models_for_provider(VERTEXAI_PROVIDER_NAME),
205+
custom_config_keys=[
206+
CustomConfigKey(
207+
name=CREDENTIALS_FILE_CUSTOM_CONFIG_KEY,
208+
display_name="Credentials File",
209+
description="This should be a JSON file containing some private credentials.",
210+
is_required=True,
211+
is_secret=False,
212+
key_type=CustomConfigKeyType.FILE_INPUT,
213+
),
214+
],
215+
default_model=VERTEXAI_DEFAULT_MODEL,
216+
default_fast_model=VERTEXAI_DEFAULT_MODEL,
217+
),
146218
]
147219

148220

web/src/app/admin/configuration/llm/ConfiguredLLMProviderDisplay.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ function LLMProviderUpdateModal({
2828
: llmProviderDescriptor?.display_name ||
2929
llmProviderDescriptor?.name ||
3030
"Custom LLM Provider";
31+
32+
const hasAdvancedOptions = llmProviderDescriptor?.name != "azure";
33+
3134
return (
3235
<Modal
3336
title={`${llmProviderDescriptor ? "Configure" : "Setup"} ${providerName}`}
@@ -41,6 +44,7 @@ function LLMProviderUpdateModal({
4144
existingLlmProvider={existingLlmProvider}
4245
shouldMarkAsDefault={shouldMarkAsDefault}
4346
setPopup={setPopup}
47+
hasAdvancedOptions={hasAdvancedOptions}
4448
/>
4549
) : (
4650
<CustomLLMProviderUpdateForm

web/src/app/admin/configuration/llm/LLMConfiguration.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ function LLMProviderUpdateModal({
3434
llmProviderDescriptor?.name ||
3535
existingLlmProvider?.name ||
3636
"Custom LLM Provider";
37+
38+
const hasAdvancedOptions = llmProviderDescriptor?.name != "azure";
39+
3740
return (
3841
<Modal title={`Setup ${providerName}`} onOutsideClick={() => onClose()}>
3942
<div className="max-h-[70vh] overflow-y-auto px-4">
@@ -44,6 +47,7 @@ function LLMProviderUpdateModal({
4447
existingLlmProvider={existingLlmProvider}
4548
shouldMarkAsDefault={shouldMarkAsDefault}
4649
setPopup={setPopup}
50+
hasAdvancedOptions={hasAdvancedOptions}
4751
/>
4852
) : (
4953
<CustomLLMProviderUpdateForm
@@ -75,9 +79,8 @@ function DefaultLLMProviderDisplay({
7579
{popup}
7680
<div className="border border-border p-3 dark:bg-neutral-800 dark:border-neutral-700 rounded w-96 flex shadow-md">
7781
<div className="my-auto">
78-
<div className="font-bold">{providerName} </div>
82+
<div className="font-bold">{providerName}</div>
7983
</div>
80-
8184
<div className="ml-auto">
8285
<Button variant="navigate" onClick={() => setFormIsVisible(true)}>
8386
Set up
@@ -169,15 +172,13 @@ export function LLMConfiguration() {
169172
</Text>
170173

171174
<div className="gap-y-4 flex flex-col">
172-
{llmProviderDescriptors.map((llmProviderDescriptor) => {
173-
return (
174-
<DefaultLLMProviderDisplay
175-
key={llmProviderDescriptor.name}
176-
llmProviderDescriptor={llmProviderDescriptor}
177-
shouldMarkAsDefault={existingLlmProviders.length === 0}
178-
/>
179-
);
180-
})}
175+
{llmProviderDescriptors.map((llmProviderDescriptor) => (
176+
<DefaultLLMProviderDisplay
177+
key={llmProviderDescriptor.name}
178+
llmProviderDescriptor={llmProviderDescriptor}
179+
shouldMarkAsDefault={existingLlmProviders.length === 0}
180+
/>
181+
))}
181182
</div>
182183

183184
<div className="mt-4">

0 commit comments

Comments
 (0)