@memberjunction/ai-gemini 2.32.1 → 2.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/readme.md +177 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ai-gemini",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.33.0",
|
|
4
4
|
"description": "MemberJunction Wrapper for Google Gemini AI Models",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"typescript": "^5.4.5"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@memberjunction/ai": "2.
|
|
23
|
-
"@memberjunction/global": "2.
|
|
22
|
+
"@memberjunction/ai": "2.33.0",
|
|
23
|
+
"@memberjunction/global": "2.33.0",
|
|
24
24
|
"@google/generative-ai": "0.21.0"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/readme.md
CHANGED
|
@@ -1,2 +1,178 @@
|
|
|
1
1
|
# @memberjunction/ai-gemini
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
A comprehensive wrapper for Google's Gemini AI models that seamlessly integrates with the MemberJunction AI framework, providing access to Google's powerful generative AI capabilities.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Google Gemini Integration**: Connect to Google's state-of-the-art Gemini models
|
|
8
|
+
- **Standardized Interface**: Implements MemberJunction's BaseLLM abstract class
|
|
9
|
+
- **Message Formatting**: Handles conversion between MemberJunction and Gemini message formats
|
|
10
|
+
- **Error Handling**: Robust error handling with detailed reporting
|
|
11
|
+
- **Chat Support**: Full support for chat-based interactions with Gemini models
|
|
12
|
+
- **Temperature Control**: Fine-tune generation creativity
|
|
13
|
+
- **Response Format Control**: Request specific response MIME types
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @memberjunction/ai-gemini
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Requirements
|
|
22
|
+
|
|
23
|
+
- Node.js 16+
|
|
24
|
+
- A Google AI Studio API key
|
|
25
|
+
- MemberJunction Core libraries
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Basic Setup
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { GeminiLLM } from '@memberjunction/ai-gemini';
|
|
33
|
+
|
|
34
|
+
// Initialize with your Google AI API key
|
|
35
|
+
const geminiLLM = new GeminiLLM('your-google-ai-api-key');
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Chat Completion
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { ChatParams } from '@memberjunction/ai';
|
|
42
|
+
|
|
43
|
+
// Create chat parameters
|
|
44
|
+
const chatParams: ChatParams = {
|
|
45
|
+
model: 'gemini-pro', // or 'gemini-pro-vision' for images, 'gemini-ultra' for more advanced capabilities
|
|
46
|
+
messages: [
|
|
47
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
48
|
+
{ role: 'user', content: 'What are the key features of the Gemini AI model?' }
|
|
49
|
+
],
|
|
50
|
+
temperature: 0.7,
|
|
51
|
+
maxOutputTokens: 1000
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Get a response
|
|
55
|
+
try {
|
|
56
|
+
const response = await geminiLLM.ChatCompletion(chatParams);
|
|
57
|
+
if (response.success) {
|
|
58
|
+
console.log('Response:', response.data.choices[0].message.content);
|
|
59
|
+
console.log('Time elapsed:', response.timeElapsed, 'ms');
|
|
60
|
+
} else {
|
|
61
|
+
console.error('Error:', response.errorMessage);
|
|
62
|
+
}
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error('Exception:', error);
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Direct Access to Gemini Client
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
// Access the underlying Google Generative AI client for advanced usage
|
|
72
|
+
const geminiClient = geminiLLM.GeminiClient;
|
|
73
|
+
|
|
74
|
+
// Use the client directly if needed
|
|
75
|
+
const model = geminiClient.getGenerativeModel({ model: 'gemini-pro' });
|
|
76
|
+
const result = await model.generateContent('Tell me a short joke about programming');
|
|
77
|
+
console.log(result.response.text());
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Supported Models
|
|
81
|
+
|
|
82
|
+
Google Gemini provides several models with different capabilities:
|
|
83
|
+
|
|
84
|
+
- `gemini-pro`: General-purpose text model
|
|
85
|
+
- `gemini-pro-vision`: Multimodal model that can process images and text
|
|
86
|
+
- `gemini-ultra`: Google's most advanced model (if available)
|
|
87
|
+
|
|
88
|
+
Check the [Google AI documentation](https://ai.google.dev/models/gemini) for the latest list of supported models.
|
|
89
|
+
|
|
90
|
+
## API Reference
|
|
91
|
+
|
|
92
|
+
### GeminiLLM Class
|
|
93
|
+
|
|
94
|
+
A class that extends BaseLLM to provide Google Gemini-specific functionality.
|
|
95
|
+
|
|
96
|
+
#### Constructor
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
new GeminiLLM(apiKey: string)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### Properties
|
|
103
|
+
|
|
104
|
+
- `GeminiClient`: (read-only) Returns the underlying Google Generative AI client instance
|
|
105
|
+
|
|
106
|
+
#### Methods
|
|
107
|
+
|
|
108
|
+
- `ChatCompletion(params: ChatParams): Promise<ChatResult>` - Perform a chat completion
|
|
109
|
+
- `SummarizeText(params: SummarizeParams): Promise<SummarizeResult>` - Not implemented yet
|
|
110
|
+
- `ClassifyText(params: ClassifyParams): Promise<ClassifyResult>` - Not implemented yet
|
|
111
|
+
|
|
112
|
+
#### Static Methods
|
|
113
|
+
|
|
114
|
+
- `MapMJMessageToGeminiHistoryEntry(message: ChatMessage): Content` - Converts MemberJunction messages to Gemini format
|
|
115
|
+
|
|
116
|
+
## Response Format Control
|
|
117
|
+
|
|
118
|
+
Control the format of Gemini responses using the `responseFormat` parameter:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
const params: ChatParams = {
|
|
122
|
+
// ...other parameters
|
|
123
|
+
responseFormat: 'text/plain', // Regular text response
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// For structured data
|
|
127
|
+
const jsonParams: ChatParams = {
|
|
128
|
+
// ...other parameters
|
|
129
|
+
responseFormat: 'application/json', // Request JSON response
|
|
130
|
+
};
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Error Handling
|
|
134
|
+
|
|
135
|
+
The wrapper provides detailed error information:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
try {
|
|
139
|
+
const response = await geminiLLM.ChatCompletion(params);
|
|
140
|
+
if (!response.success) {
|
|
141
|
+
console.error('Error:', response.errorMessage);
|
|
142
|
+
console.error('Status:', response.statusText);
|
|
143
|
+
console.error('Exception:', response.exception);
|
|
144
|
+
}
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.error('Exception occurred:', error);
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Message Handling
|
|
151
|
+
|
|
152
|
+
The wrapper handles proper message formatting and role conversion between MemberJunction's format and Google Gemini's expected format:
|
|
153
|
+
|
|
154
|
+
- MemberJunction's `system` and `user` roles are converted to Gemini's `user` role
|
|
155
|
+
- MemberJunction's `assistant` role is converted to Gemini's `model` role
|
|
156
|
+
- Messages are properly spaced to ensure alternating roles as required by Gemini
|
|
157
|
+
|
|
158
|
+
## Limitations
|
|
159
|
+
|
|
160
|
+
Currently, the wrapper implements:
|
|
161
|
+
- Chat completion functionality
|
|
162
|
+
|
|
163
|
+
Future implementations may include:
|
|
164
|
+
- `SummarizeText` functionality
|
|
165
|
+
- `ClassifyText` functionality
|
|
166
|
+
- Token counting and usage reporting
|
|
167
|
+
- Image processing with `gemini-pro-vision`
|
|
168
|
+
- Function calling
|
|
169
|
+
|
|
170
|
+
## Dependencies
|
|
171
|
+
|
|
172
|
+
- `@google/generative-ai`: Official Google Generative AI SDK
|
|
173
|
+
- `@memberjunction/ai`: MemberJunction AI core framework
|
|
174
|
+
- `@memberjunction/global`: MemberJunction global utilities
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
ISC
|