|
15 | 15 | * limitations under the License. |
16 | 16 | */ |
17 | 17 | import { use, expect } from 'chai'; |
18 | | -import { GenerativeModel } from './generative-model'; |
| 18 | +import { GenerativeModel, validateGenerationConfig } from './generative-model'; |
19 | 19 | import { |
20 | 20 | FunctionCallingMode, |
21 | 21 | AI, |
@@ -956,3 +956,73 @@ describe('GenerativeModel dispatch logic', () => { |
956 | 956 | }); |
957 | 957 | }); |
958 | 958 | }); |
| 959 | + |
| 960 | +describe('validateGenerationConfig', () => { |
| 961 | + it('does not allow setting both thinkingBudget and thinkingLevel', () => { |
| 962 | + expect(() => { |
| 963 | + validateGenerationConfig({ |
| 964 | + thinkingConfig: { |
| 965 | + thinkingBudget: 200 |
| 966 | + } |
| 967 | + }); |
| 968 | + }).to.not.throw(); |
| 969 | + expect(() => { |
| 970 | + validateGenerationConfig({ |
| 971 | + thinkingConfig: { |
| 972 | + thinkingLevel: ThinkingLevel.LOW |
| 973 | + } |
| 974 | + }); |
| 975 | + }).to.not.throw(); |
| 976 | + expect(() => { |
| 977 | + validateGenerationConfig({ |
| 978 | + thinkingConfig: { |
| 979 | + thinkingBudget: 200, |
| 980 | + thinkingLevel: ThinkingLevel.LOW |
| 981 | + } |
| 982 | + }); |
| 983 | + }).to.throw(); |
| 984 | + }); |
| 985 | + it('does not allow setting both responseSchema and responseJsonSchema', () => { |
| 986 | + expect(() => { |
| 987 | + validateGenerationConfig({ |
| 988 | + responseSchema: {}, |
| 989 | + responseMimeType: 'application/json' |
| 990 | + }); |
| 991 | + }).to.not.throw(); |
| 992 | + expect(() => { |
| 993 | + validateGenerationConfig({ |
| 994 | + responseJsonSchema: {}, |
| 995 | + responseMimeType: 'application/json' |
| 996 | + }); |
| 997 | + }).to.not.throw(); |
| 998 | + expect(() => { |
| 999 | + validateGenerationConfig({ |
| 1000 | + responseSchema: {}, |
| 1001 | + responseJsonSchema: {}, |
| 1002 | + responseMimeType: 'application/json' |
| 1003 | + }); |
| 1004 | + }).to.throw(); |
| 1005 | + }); |
| 1006 | + it( |
| 1007 | + 'throws if responseSchema or responseJsonSchema are set' + |
| 1008 | + ' and responseMimeType is not "application/json"', |
| 1009 | + () => { |
| 1010 | + expect(() => { |
| 1011 | + validateGenerationConfig({ |
| 1012 | + responseSchema: {} |
| 1013 | + }); |
| 1014 | + }).to.throw(); |
| 1015 | + expect(() => { |
| 1016 | + validateGenerationConfig({ |
| 1017 | + responseJsonSchema: {} |
| 1018 | + }); |
| 1019 | + }).to.throw(); |
| 1020 | + expect(() => { |
| 1021 | + validateGenerationConfig({ |
| 1022 | + responseJsonSchema: {}, |
| 1023 | + responseMimeType: 'text/plain' |
| 1024 | + }); |
| 1025 | + }).to.throw(); |
| 1026 | + } |
| 1027 | + ); |
| 1028 | +}); |
0 commit comments