|
| 1 | +/** |
| 2 | + * Copyright 2025 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +/** |
| 18 | + * Live integration tests that call the real Anthropic API. |
| 19 | + * Only runs when ANTHROPIC_API_KEY environment variable is set. |
| 20 | + * |
| 21 | + * Run with: ANTHROPIC_API_KEY=your-key pnpm test:live |
| 22 | + */ |
| 23 | + |
| 24 | +import * as assert from 'assert'; |
| 25 | +import { genkit } from 'genkit'; |
| 26 | +import { describe, it } from 'node:test'; |
| 27 | +import { anthropic } from '../src/index.js'; |
| 28 | + |
| 29 | +const API_KEY = process.env.ANTHROPIC_API_KEY; |
| 30 | + |
| 31 | +describe('Live Anthropic API Tests', { skip: !API_KEY }, () => { |
| 32 | + it('should work with short model name claude-3-5-haiku', async () => { |
| 33 | + const ai = genkit({ |
| 34 | + plugins: [anthropic({ apiKey: API_KEY })], |
| 35 | + }); |
| 36 | + |
| 37 | + const result = await ai.generate({ |
| 38 | + model: 'anthropic/claude-3-5-haiku', |
| 39 | + prompt: 'Say "hello" and nothing else.', |
| 40 | + }); |
| 41 | + |
| 42 | + assert.ok(result.text.toLowerCase().includes('hello')); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should work with short model name claude-3-haiku', async () => { |
| 46 | + const ai = genkit({ |
| 47 | + plugins: [anthropic({ apiKey: API_KEY })], |
| 48 | + }); |
| 49 | + |
| 50 | + const result = await ai.generate({ |
| 51 | + model: 'anthropic/claude-3-haiku', |
| 52 | + prompt: 'Say "hello" and nothing else.', |
| 53 | + }); |
| 54 | + |
| 55 | + assert.ok(result.text.toLowerCase().includes('hello')); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should work with full versioned model name', async () => { |
| 59 | + const ai = genkit({ |
| 60 | + plugins: [anthropic({ apiKey: API_KEY })], |
| 61 | + }); |
| 62 | + |
| 63 | + const result = await ai.generate({ |
| 64 | + model: 'anthropic/claude-3-5-haiku-20241022', |
| 65 | + prompt: 'Say "hello" and nothing else.', |
| 66 | + }); |
| 67 | + |
| 68 | + assert.ok(result.text.toLowerCase().includes('hello')); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should work with anthropic.model() helper', async () => { |
| 72 | + const ai = genkit({ |
| 73 | + plugins: [anthropic({ apiKey: API_KEY })], |
| 74 | + }); |
| 75 | + |
| 76 | + const result = await ai.generate({ |
| 77 | + model: anthropic.model('claude-3-5-haiku'), |
| 78 | + prompt: 'Say "hello" and nothing else.', |
| 79 | + }); |
| 80 | + |
| 81 | + assert.ok(result.text.toLowerCase().includes('hello')); |
| 82 | + }); |
| 83 | +}); |
0 commit comments