Skip to content

Commit 542cc0a

Browse files
add e2e tests
1 parent 61468b1 commit 542cc0a

File tree

20 files changed

+2447
-48
lines changed

20 files changed

+2447
-48
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React + TS</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "@langchain/google-e2e",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "tsc -b && vite build",
9+
"lint": "eslint .",
10+
"preview": "vite preview",
11+
"test": "wdio run ./wdio.conf.ts"
12+
},
13+
"dependencies": {
14+
"@langchain/google": "workspace:*",
15+
"react": "^19.1.0",
16+
"react-dom": "^19.1.0"
17+
},
18+
"devDependencies": {
19+
"@eslint/js": "^9.25.0",
20+
"@types/react": "^19.1.2",
21+
"@types/react-dom": "^19.1.2",
22+
"@vitejs/plugin-react": "^4.4.1",
23+
"@wdio/cli": "latest",
24+
"@wdio/local-runner": "latest",
25+
"@wdio/mocha-framework": "latest",
26+
"@wdio/spec-reporter": "latest",
27+
"eslint": "^9.25.0",
28+
"eslint-plugin-react-hooks": "^5.2.0",
29+
"eslint-plugin-react-refresh": "^0.4.19",
30+
"globals": "^16.0.0",
31+
"typescript": "~5.8.3",
32+
"typescript-eslint": "^8.30.1",
33+
"vite": "^6.3.5",
34+
"wdio-vite-service": "^2.1.0"
35+
}
36+
}
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)