Skip to content

Commit eb1e33e

Browse files
committed
Add support for generative-anthropic
1 parent 4e73ae0 commit eb1e33e

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

src/collections/config/types/generative.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ export type GenerativeAWSConfig = {
1414
endpoint?: string;
1515
};
1616

17+
export type GenerativeAnthropicConfig = {
18+
maxTokens?: number;
19+
model?: string;
20+
stopSequences?: string[];
21+
temperature?: number;
22+
topK?: number;
23+
topP?: number;
24+
};
25+
1726
export type GenerativeAnyscaleConfig = {
1827
model?: string;
1928
temperature?: number;
@@ -83,6 +92,7 @@ export type GenerativeConfigType<G> = G extends 'generative-openai'
8392
: Record<string, any> | undefined;
8493

8594
export type GenerativeSearch =
95+
| 'generative-anthropic'
8696
| 'generative-anyscale'
8797
| 'generative-aws'
8898
| 'generative-mistral'

src/collections/configure/generative.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
GenerativeAWSConfig,
3+
GenerativeAnthropicConfig,
34
GenerativeAnyscaleConfig,
45
GenerativeAzureOpenAIConfig,
56
GenerativeCohereConfig,
@@ -12,6 +13,7 @@ import {
1213
} from '../config/types/index.js';
1314
import {
1415
GenerativeAWSConfigCreate,
16+
GenerativeAnthropicConfigCreate,
1517
GenerativeAnyscaleConfigCreate,
1618
GenerativeAzureOpenAIConfigCreate,
1719
GenerativeCohereConfigCreate,
@@ -23,12 +25,28 @@ import {
2325
} from '../index.js';
2426

2527
export default {
28+
/**
29+
* Create a `ModuleConfig<'generative-anthropic', GenerativeAnthropicConfig | undefined>` object for use when performing AI generation using the `generative-anthropic` module.
30+
*
31+
* See the [documentation](https://weaviate.io/developers/weaviate/modules/reader-generator-modules/generative-anthropic) for detailed usage.
32+
*
33+
* @param {GenerativeAnthropicConfigCreate} [config] The configuration for the `generative-anthropic` module.
34+
* @returns {ModuleConfig<'generative-anthropic', GenerativeAnthropicConfig | undefined>} The configuration object.
35+
*/
36+
anthropic(
37+
config?: GenerativeAnthropicConfigCreate
38+
): ModuleConfig<'generative-anthropic', GenerativeAnthropicConfig | undefined> {
39+
return {
40+
name: 'generative-anthropic',
41+
config,
42+
};
43+
},
2644
/**
2745
* Create a `ModuleConfig<'generative-anyscale', GenerativeAnyscaleConfig | undefined>` object for use when performing AI generation using the `generative-anyscale` module.
2846
*
2947
* See the [documentation](https://weaviate.io/developers/weaviate/modules/reader-generator-modules/generative-anyscale) for detailed usage.
3048
*
31-
* @param {GenerativeAnyscaleConfigCreate} config The configuration for the `generative-aws` module.
49+
* @param {GenerativeAnyscaleConfigCreate} [config] The configuration for the `generative-aws` module.
3250
* @returns {ModuleConfig<'generative-anyscale', GenerativeAnyscaleConfig | undefined>} The configuration object.
3351
*/
3452
anyscale(

src/collections/configure/types/generative.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
GenerativeAWSConfig,
3+
GenerativeAnthropicConfig,
34
GenerativeAnyscaleConfig,
45
GenerativeMistralConfig,
56
GenerativeOctoAIConfig,
@@ -20,6 +21,8 @@ export type GenerativeOpenAIConfigCreate = GenerativeOpenAIConfigBaseCreate & {
2021
model?: string;
2122
};
2223

24+
export type GenerativeAnthropicConfigCreate = GenerativeAnthropicConfig;
25+
2326
export type GenerativeAzureOpenAIConfigCreate = GenerativeOpenAIConfigBaseCreate & {
2427
resourceName: string;
2528
deploymentId: string;

src/collections/configure/unit.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
GenerativeAWSConfig,
3+
GenerativeAnthropicConfig,
34
GenerativeAnyscaleConfig,
45
GenerativeAzureOpenAIConfig,
56
GenerativeCohereConfig,
@@ -1066,6 +1067,36 @@ describe('Unit testing of the vectorizer factory class', () => {
10661067
});
10671068

10681069
describe('Unit testing of the generative factory class', () => {
1070+
it('should create the correct GenerativeAnthropicConfig type with required & default values', () => {
1071+
const config = configure.generative.anthropic();
1072+
expect(config).toEqual<ModuleConfig<'generative-anthropic', GenerativeAnthropicConfig | undefined>>({
1073+
name: 'generative-anthropic',
1074+
config: undefined,
1075+
});
1076+
});
1077+
1078+
it('should create the correct GenerativeAnthropicConfig type with all values', () => {
1079+
const config = configure.generative.anthropic({
1080+
maxTokens: 100,
1081+
model: 'model',
1082+
stopSequences: ['stop1', 'stop2'],
1083+
temperature: 0.5,
1084+
topK: 10,
1085+
topP: 0.8,
1086+
});
1087+
expect(config).toEqual<ModuleConfig<'generative-anthropic', GenerativeAnthropicConfig>>({
1088+
name: 'generative-anthropic',
1089+
config: {
1090+
maxTokens: 100,
1091+
model: 'model',
1092+
stopSequences: ['stop1', 'stop2'],
1093+
temperature: 0.5,
1094+
topK: 10,
1095+
topP: 0.8,
1096+
},
1097+
});
1098+
});
1099+
10691100
it('should create the correct GenerativeAnyscaleConfig type with required & default values', () => {
10701101
const config = configure.generative.anyscale();
10711102
expect(config).toEqual<ModuleConfig<'generative-anyscale', GenerativeAnyscaleConfig | undefined>>({

0 commit comments

Comments
 (0)