|
| 1 | +// Copyright 2025 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// You may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +'use strict'; |
| 16 | + |
| 17 | +const {assert} = require('chai'); |
| 18 | +const {describe, it} = require('mocha'); |
| 19 | +const proxyquire = require('proxyquire').noCallThru(); |
| 20 | + |
| 21 | +const projectId = process.env.CAIP_PROJECT_ID; |
| 22 | + |
| 23 | +describe('tuning-textgen-with-txt', () => { |
| 24 | + it('should fetch tuning job and generate content', async function () { |
| 25 | + this.timeout(1000000); |
| 26 | + |
| 27 | + const mockTuningJob = { |
| 28 | + name: 'test-tuning-job', |
| 29 | + experiment: 'test-experiment', |
| 30 | + tunedModel: { |
| 31 | + model: 'test-model', |
| 32 | + endpoint: 'test-endpoint', |
| 33 | + }, |
| 34 | + }; |
| 35 | + |
| 36 | + const mockGenerateContentResult = { |
| 37 | + text: 'Because it is hot and glowing!', |
| 38 | + }; |
| 39 | + |
| 40 | + class MockTunings { |
| 41 | + async get() { |
| 42 | + return mockTuningJob; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + class MockModels { |
| 47 | + async generateContent() { |
| 48 | + return mockGenerateContentResult; |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + class MockGoogleGenAI { |
| 53 | + constructor() { |
| 54 | + this.tunings = new MockTunings(); |
| 55 | + this.models = new MockModels(); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + const sample = proxyquire('../tuning/tuning-textgen-with-txt.js', { |
| 60 | + '@google/genai': {GoogleGenAI: MockGoogleGenAI}, |
| 61 | + }); |
| 62 | + |
| 63 | + const response = await sample.generateContent(projectId); |
| 64 | + |
| 65 | + assert.strictEqual(response, 'Because it is hot and glowing!'); |
| 66 | + }); |
| 67 | +}); |
0 commit comments