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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
- import { OpenAiChatCompletionProvider } from '../../src/providers/openai/chat';
- import { OpenAiCompletionProvider } from '../../src/providers/openai/completion';
- import { OpenAiEmbeddingProvider } from '../../src/providers/openai/embedding';
- import { createTogetherAiProvider } from '../../src/providers/togetherai';
- import type { ProviderOptions } from '../../src/types';
- import type { EnvOverrides } from '../../src/types/env';
- jest.mock('../../src/providers/openai');
- describe('createTogetherAiProvider', () => {
- beforeEach(() => {
- jest.clearAllMocks();
- });
- it('should create a chat completion provider when type is chat', () => {
- const provider = createTogetherAiProvider('togetherai:chat:model-name');
- expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
- expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
- });
- it('should create a completion provider when type is completion', () => {
- const provider = createTogetherAiProvider('togetherai:completion:model-name');
- expect(provider).toBeInstanceOf(OpenAiCompletionProvider);
- expect(OpenAiCompletionProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
- });
- it('should create an embedding provider when type is embedding', () => {
- const provider = createTogetherAiProvider('togetherai:embedding:model-name');
- expect(provider).toBeInstanceOf(OpenAiEmbeddingProvider);
- expect(OpenAiEmbeddingProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
- });
- it('should create an embedding provider when type is embeddings', () => {
- const provider = createTogetherAiProvider('togetherai:embeddings:model-name');
- expect(provider).toBeInstanceOf(OpenAiEmbeddingProvider);
- expect(OpenAiEmbeddingProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
- });
- it('should default to chat completion provider when no type is specified', () => {
- const provider = createTogetherAiProvider('togetherai:model-name');
- expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
- expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
- });
- it('should pass correct configuration to the provider', () => {
- const options: {
- config?: ProviderOptions;
- id?: string;
- env?: EnvOverrides;
- } = {
- id: 'custom-id',
- };
- createTogetherAiProvider('togetherai:chat:model-name', options);
- // Verify that the OpenAI provider was called with the correct parameters
- expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('model-name', {
- config: {
- apiBaseUrl: 'https://api.together.xyz/v1',
- apiKeyEnvar: 'TOGETHER_API_KEY',
- passthrough: {},
- },
- id: 'custom-id',
- });
- });
- it('should handle model names with colons', () => {
- createTogetherAiProvider('togetherai:chat:org:model:name');
- expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('org:model:name', expect.any(Object));
- });
- describe('parameter handling', () => {
- it('should add all parameters to passthrough', () => {
- const options = {
- config: {
- config: {
- max_tokens: 4096,
- temperature: 0.7,
- top_p: 0.9,
- repetition_penalty: 1.1,
- custom_param: 'value',
- },
- },
- };
- createTogetherAiProvider('togetherai:chat:model-name', options);
- expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith(
- 'model-name',
- expect.objectContaining({
- config: expect.objectContaining({
- apiBaseUrl: 'https://api.together.xyz/v1',
- apiKeyEnvar: 'TOGETHER_API_KEY',
- passthrough: expect.objectContaining({
- max_tokens: 4096,
- temperature: 0.7,
- top_p: 0.9,
- repetition_penalty: 1.1,
- custom_param: 'value',
- }),
- }),
- }),
- );
- });
- it('should handle TogetherAI-specific parameters correctly', () => {
- const options = {
- config: {
- config: {
- stop_sequences: ['END'],
- top_k: 50,
- safety_model: 'safety-model',
- },
- },
- };
- createTogetherAiProvider('togetherai:chat:model-name', options);
- expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith(
- 'model-name',
- expect.objectContaining({
- config: expect.objectContaining({
- passthrough: expect.objectContaining({
- stop_sequences: ['END'],
- top_k: 50,
- safety_model: 'safety-model',
- }),
- }),
- }),
- );
- });
- it('should handle passthrough correctly', () => {
- const options = {
- config: {
- config: {
- temperature: 0.7,
- passthrough: {
- custom_param: 'value',
- },
- },
- },
- };
- createTogetherAiProvider('togetherai:chat:model-name', options);
- expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith(
- 'model-name',
- expect.objectContaining({
- config: expect.objectContaining({
- passthrough: expect.objectContaining({
- temperature: 0.7,
- passthrough: {
- custom_param: 'value',
- },
- }),
- }),
- }),
- );
- });
- });
- });
|