MCPcopy
hub / github.com/langchain-ai/langchain / VertexAI

Class VertexAI

libs/community/langchain_community/llms/vertexai.py:209–391  ·  view source on GitHub ↗

Google Vertex AI large language models.

Source from the content-addressed store, hash-verified

207 alternative_import="langchain_google_vertexai.VertexAI",
208)
209class VertexAI(_VertexAICommon, BaseLLM):
210 """Google Vertex AI large language models."""
211
212 model_name: str = "text-bison"
213 "The name of the Vertex AI large language model."
214 tuned_model_name: Optional[str] = None
215 "The name of a tuned model. If provided, model_name is ignored."
216
217 @classmethod
218 def is_lc_serializable(self) -> bool:
219 return True
220
221 @classmethod
222 def get_lc_namespace(cls) -> List[str]:
223 """Get the namespace of the langchain object."""
224 return ["langchain", "llms", "vertexai"]
225
226 @root_validator()
227 def validate_environment(cls, values: Dict) -> Dict:
228 """Validate that the python package exists in environment."""
229 tuned_model_name = values.get("tuned_model_name")
230 model_name = values["model_name"]
231 is_gemini = is_gemini_model(values["model_name"])
232 cls._try_init_vertexai(values)
233 try:
234 from vertexai.language_models import (
235 CodeGenerationModel,
236 TextGenerationModel,
237 )
238 from vertexai.preview.language_models import (
239 CodeGenerationModel as PreviewCodeGenerationModel,
240 )
241 from vertexai.preview.language_models import (
242 TextGenerationModel as PreviewTextGenerationModel,
243 )
244
245 if is_gemini:
246 from vertexai.preview.generative_models import (
247 GenerativeModel,
248 )
249
250 if is_codey_model(model_name):
251 model_cls = CodeGenerationModel
252 preview_model_cls = PreviewCodeGenerationModel
253 elif is_gemini:
254 model_cls = GenerativeModel
255 preview_model_cls = GenerativeModel
256 else:
257 model_cls = TextGenerationModel
258 preview_model_cls = PreviewTextGenerationModel
259
260 if tuned_model_name:
261 values["client"] = model_cls.get_tuned_model(tuned_model_name)
262 values["client_preview"] = preview_model_cls.get_tuned_model(
263 tuned_model_name
264 )
265 else:
266 if is_gemini:

Callers 9

chain.pyFile · 0.90
test_vertex_callFunction · 0.90
test_vertex_generateFunction · 0.90
test_vertex_agenerateFunction · 0.90
test_vertex_streamFunction · 0.90
test_vertex_consistencyFunction · 0.90

Calls

no outgoing calls

Tested by 8

test_vertex_callFunction · 0.72
test_vertex_generateFunction · 0.72
test_vertex_agenerateFunction · 0.72
test_vertex_streamFunction · 0.72
test_vertex_consistencyFunction · 0.72