|
| 1 | +# LangChain Google Web E2E Test |
| 2 | + |
| 3 | +This is a test application that demonstrates the `@langchain/google/web` package bundling and functionality in a web environment. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Basic AI chat interface using Google's Gemini model |
| 8 | +- Streaming responses for real-time interaction |
| 9 | +- Clean, responsive UI built with React and Vite |
| 10 | +- Tests web bundling capabilities of the `@langchain/google/web` package |
| 11 | + |
| 12 | +## Getting Started |
| 13 | + |
| 14 | +### Prerequisites |
| 15 | + |
| 16 | +1. **Google AI API Key**: You'll need a Google AI API key to use this application |
| 17 | + - Visit [Google AI Studio](https://aistudio.google.com/app/apikey) |
| 18 | + - Create a new API key |
| 19 | + - You can either: |
| 20 | + - Enter the key directly in the application interface, or |
| 21 | + - Set it as an environment variable (see Configuration section below) |
| 22 | + |
| 23 | +### Installation |
| 24 | + |
| 25 | +1. Install dependencies: |
| 26 | + |
| 27 | + ```bash |
| 28 | + yarn install |
| 29 | + ``` |
| 30 | + |
| 31 | +2. Start the development server: |
| 32 | + |
| 33 | + ```bash |
| 34 | + yarn run dev |
| 35 | + ``` |
| 36 | + |
| 37 | +3. Open your browser and navigate to the provided local URL (usually `http://localhost:5173`) |
| 38 | + |
| 39 | +### Configuration |
| 40 | + |
| 41 | +You can configure the Google AI API key in two ways: |
| 42 | + |
| 43 | +#### Option 1: Environment Variable (Recommended) |
| 44 | + |
| 45 | +Create a `.env` file in the e2e directory: |
| 46 | + |
| 47 | +```bash |
| 48 | +# .env |
| 49 | +VITE_GOOGLE_API_KEY=your-google-ai-api-key-here |
| 50 | +``` |
| 51 | + |
| 52 | +**Note**: The `VITE_` prefix is required for Vite to make the environment variable available in the browser. |
| 53 | + |
| 54 | +#### Option 2: Manual Entry |
| 55 | + |
| 56 | +If no environment variable is set, you can enter your API key directly in the application interface. |
| 57 | + |
| 58 | +### Usage |
| 59 | + |
| 60 | +1. **Enter your API Key**: Paste your Google AI API key in the "Google AI API Key" field |
| 61 | +2. **Enter your prompt**: Type your question or prompt in the text area |
| 62 | +3. **Send Message**: Click the "Send Message" button to start the conversation |
| 63 | +4. **View Response**: Watch as the AI streams its response in real-time |
| 64 | +5. **Clear**: Use the "Clear" button to reset the conversation |
| 65 | + |
| 66 | +### Example Prompts |
| 67 | + |
| 68 | +Try these example prompts to test the application: |
| 69 | + |
| 70 | +- "What is the capital of France?" |
| 71 | +- "Explain quantum computing in simple terms" |
| 72 | +- "Write a short poem about web development" |
| 73 | +- "What are the benefits of streaming responses in chat applications?" |
| 74 | + |
| 75 | +## Technical Details |
| 76 | + |
| 77 | +### Model Configuration |
| 78 | + |
| 79 | +The application uses the `gemini-1.5-flash` model, which is: |
| 80 | + |
| 81 | +- Fast and efficient for real-time chat |
| 82 | +- Supports streaming responses |
| 83 | +- Good balance between speed and quality |
| 84 | + |
| 85 | +### Streaming Implementation |
| 86 | + |
| 87 | +The app demonstrates proper streaming implementation: |
| 88 | + |
| 89 | +```typescript |
| 90 | +const stream = await model.stream(prompt); |
| 91 | +let fullResponse = ""; |
| 92 | + |
| 93 | +for await (const chunk of stream) { |
| 94 | + const content = chunk.content as string; |
| 95 | + fullResponse += content; |
| 96 | + setResponse(fullResponse); |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +### Web Bundling |
| 101 | + |
| 102 | +This application tests that `@langchain/google/web` can be properly bundled for web environments using Vite, ensuring: |
| 103 | + |
| 104 | +- Proper tree-shaking |
| 105 | +- No Node.js-specific dependencies in the bundle |
| 106 | +- Compatible with modern web browsers |
| 107 | + |
| 108 | +## Build for Production |
| 109 | + |
| 110 | +To build the application for production: |
| 111 | + |
| 112 | +```bash |
| 113 | +yarn run build |
| 114 | +``` |
| 115 | + |
| 116 | +The built files will be in the `dist` directory and can be served by any static file server. |
| 117 | + |
| 118 | +## Troubleshooting |
| 119 | + |
| 120 | +### API Key Issues |
| 121 | + |
| 122 | +- Ensure your API key is valid and has proper permissions |
| 123 | +- Check that you're using the correct API key from Google AI Studio (not Google Cloud) |
| 124 | + |
| 125 | +### Network Issues |
| 126 | + |
| 127 | +- The application requires an internet connection to communicate with Google's API |
| 128 | +- Check browser console for any CORS or network-related errors |
| 129 | + |
| 130 | +### Bundle Issues |
| 131 | + |
| 132 | +- If you encounter bundling issues, check that you're importing from `@langchain/google/web` specifically |
| 133 | +- Ensure all dependencies are properly installed |
| 134 | + |
| 135 | +## Development |
| 136 | + |
| 137 | +This application serves as an E2E test for the `@langchain/google/web` package. When making changes to the core package, you can test them here by: |
| 138 | + |
| 139 | +1. Building the core package |
| 140 | +2. Running this E2E application |
| 141 | +3. Verifying that streaming and bundling work correctly |
| 142 | + |
| 143 | +## License |
| 144 | + |
| 145 | +This is part of the LangChain.js project and follows the same license terms. |
0 commit comments