|
1 |
| - |
2 | 1 | === "OpenAI"
|
3 | 2 | Install the langchain-openai package
|
4 | 3 |
|
|
24 | 23 | ```
|
25 | 24 |
|
26 | 25 |
|
27 |
| -=== "Amazon Bedrock" |
| 26 | +=== "AWS" |
28 | 27 | Install the langchain-aws package
|
29 | 28 |
|
30 | 29 | ```bash
|
|
67 | 66 |
|
68 | 67 | If you want more information on how to use other AWS services, please refer to the [langchain-aws](https://python.langchain.com/docs/integrations/providers/aws/) documentation.
|
69 | 68 |
|
70 |
| -=== "Azure OpenAI" |
| 69 | +=== "Google Cloud" |
| 70 | + Google offers two ways to access their models: Google AI Studio and Google Cloud Vertex AI. Google AI Studio requires just a Google account and API key, while Vertex AI requires a Google Cloud account. Use Google AI Studio if you're just starting out. |
| 71 | + |
| 72 | + First, install the required packages (only the packages you need based on your choice of API): |
| 73 | + |
| 74 | + ```bash |
| 75 | + # for Google AI Studio |
| 76 | + pip install langchain-google-genai |
| 77 | + # for Google Cloud Vertex AI |
| 78 | + pip install langchain-google-vertexai |
| 79 | + ``` |
| 80 | + |
| 81 | + Then set up your credentials based on your chosen API: |
| 82 | + |
| 83 | + For Google AI Studio: |
| 84 | + ```python |
| 85 | + import os |
| 86 | + os.environ["GOOGLE_API_KEY"] = "your-google-ai-key" # From https://ai.google.dev/ |
| 87 | + ``` |
| 88 | + |
| 89 | + For Google Cloud Vertex AI: |
| 90 | + ```python |
| 91 | + # Ensure you have credentials configured (gcloud, workload identity, etc.) |
| 92 | + # Or set service account JSON path: |
| 93 | + os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/service-account.json" |
| 94 | + ``` |
| 95 | + |
| 96 | + Define your configuration: |
| 97 | + |
| 98 | + ```python |
| 99 | + config = { |
| 100 | + "model": "gemini-1.5-pro", # or other model IDs |
| 101 | + "temperature": 0.4, |
| 102 | + "max_tokens": None, |
| 103 | + "top_p": 0.8, |
| 104 | + # For Vertex AI only: |
| 105 | + "project": "your-project-id", # Required for Vertex AI |
| 106 | + "location": "us-central1", # Required for Vertex AI |
| 107 | + } |
| 108 | + ``` |
| 109 | + |
| 110 | + Initialize the LLM and wrap it for use with ragas: |
| 111 | + |
| 112 | + ```python |
| 113 | + from ragas.llms import LangchainLLMWrapper |
| 114 | + from ragas.embeddings import LangchainEmbeddingsWrapper |
| 115 | + |
| 116 | + # Choose the appropriate import based on your API: |
| 117 | + from langchain_google_genai import ChatGoogleGenerativeAI |
| 118 | + from langchain_google_vertexai import ChatVertexAI |
| 119 | + |
| 120 | + # Initialize with Google AI Studio |
| 121 | + evaluator_llm = LangchainLLMWrapper(ChatGoogleGenerativeAI( |
| 122 | + model=config["model"], |
| 123 | + temperature=config["temperature"], |
| 124 | + max_tokens=config["max_tokens"], |
| 125 | + top_p=config["top_p"], |
| 126 | + )) |
| 127 | + |
| 128 | + # Or initialize with Vertex AI |
| 129 | + evaluator_llm = LangchainLLMWrapper(ChatVertexAI( |
| 130 | + model=config["model"], |
| 131 | + temperature=config["temperature"], |
| 132 | + max_tokens=config["max_tokens"], |
| 133 | + top_p=config["top_p"], |
| 134 | + project=config["project"], |
| 135 | + location=config["location"], |
| 136 | + )) |
| 137 | + ``` |
| 138 | + |
| 139 | + You can optionally configure safety settings: |
| 140 | + |
| 141 | + ```python |
| 142 | + from langchain_google_genai import HarmCategory, HarmBlockThreshold |
| 143 | + |
| 144 | + safety_settings = { |
| 145 | + HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE, |
| 146 | + # Add other safety settings as needed |
| 147 | + } |
| 148 | + |
| 149 | + # Apply to your LLM initialization |
| 150 | + evaluator_llm = LangchainLLMWrapper(ChatGoogleGenerativeAI( |
| 151 | + model=config["model"], |
| 152 | + temperature=config["temperature"], |
| 153 | + safety_settings=safety_settings, |
| 154 | + )) |
| 155 | + ``` |
| 156 | + |
| 157 | + Initialize the embeddings and wrap them for use with ragas (choose one of the following): |
| 158 | + |
| 159 | + ```python |
| 160 | + # Google AI Studio Embeddings |
| 161 | + from langchain_google_genai import GoogleGenerativeAIEmbeddings |
| 162 | + |
| 163 | + evaluator_embeddings = LangchainEmbeddingsWrapper(GoogleGenerativeAIEmbeddings( |
| 164 | + model="models/embedding-001", # Google's text embedding model |
| 165 | + task_type="retrieval_document" # Optional: specify the task type |
| 166 | + )) |
| 167 | + ``` |
| 168 | + |
| 169 | + ```python |
| 170 | + # Vertex AI Embeddings |
| 171 | + from langchain_google_vertexai import VertexAIEmbeddings |
| 172 | + |
| 173 | + evaluator_embeddings = LangchainEmbeddingsWrapper(VertexAIEmbeddings( |
| 174 | + model_name="textembedding-gecko@001", # or other available model |
| 175 | + project=config["project"], # Your GCP project ID |
| 176 | + location=config["location"] # Your GCP location |
| 177 | + )) |
| 178 | + ``` |
| 179 | + |
| 180 | + For more information on available models, features, and configurations, refer to: [Google AI Studio documentation](https://ai.google.dev/docs), [Google Cloud Vertex AI documentation](https://cloud.google.com/vertex-ai/docs), [LangChain Google AI integration](https://python.langchain.com/docs/integrations/chat/google_generative_ai), [LangChain Vertex AI integration](https://python.langchain.com/docs/integrations/chat/google_vertex_ai) |
| 181 | + |
| 182 | +=== "Azure" |
71 | 183 | Install the langchain-openai package
|
72 | 184 |
|
73 | 185 | ```bash
|
|
0 commit comments