-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathindex.ts
More file actions
61 lines (54 loc) · 1.44 KB
/
index.ts
File metadata and controls
61 lines (54 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import * as Sentry from '@sentry/cloudflare';
import type { GoogleGenAIClient } from '@sentry/core';
import { MockGoogleGenAI } from './mocks';
interface Env {
SENTRY_DSN: string;
}
const mockClient = new MockGoogleGenAI({
apiKey: 'mock-api-key',
});
const client: GoogleGenAIClient = Sentry.instrumentGoogleGenAIClient(mockClient);
export default Sentry.withSentry(
(env: Env) => ({
dsn: env.SENTRY_DSN,
tracesSampleRate: 1.0,
}),
{
async fetch(_request, _env, _ctx) {
// Test 1: chats.create and sendMessage flow
const chat = client.chats.create({
model: 'gemini-1.5-pro',
config: {
temperature: 0.8,
topP: 0.9,
maxOutputTokens: 150,
},
history: [
{
role: 'user',
parts: [{ text: 'Hello, how are you?' }],
},
],
});
const chatResponse = await chat.sendMessage({
message: 'Tell me a joke',
});
// Test 2: models.generateContent
const modelResponse = await client.models.generateContent({
model: 'gemini-1.5-flash',
config: {
temperature: 0.7,
topP: 0.9,
maxOutputTokens: 100,
},
contents: [
{
role: 'user',
parts: [{ text: 'What is the capital of France?' }],
},
],
});
return new Response(JSON.stringify({ chatResponse, modelResponse }));
},
},
);