Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

togetherai.test.ts 5.3 KB

You have to be logged in to leave a comment. Sign In
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
  1. import { OpenAiChatCompletionProvider } from '../../src/providers/openai/chat';
  2. import { OpenAiCompletionProvider } from '../../src/providers/openai/completion';
  3. import { OpenAiEmbeddingProvider } from '../../src/providers/openai/embedding';
  4. import { createTogetherAiProvider } from '../../src/providers/togetherai';
  5. import type { ProviderOptions } from '../../src/types';
  6. import type { EnvOverrides } from '../../src/types/env';
  7. jest.mock('../../src/providers/openai');
  8. describe('createTogetherAiProvider', () => {
  9. beforeEach(() => {
  10. jest.clearAllMocks();
  11. });
  12. it('should create a chat completion provider when type is chat', () => {
  13. const provider = createTogetherAiProvider('togetherai:chat:model-name');
  14. expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
  15. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
  16. });
  17. it('should create a completion provider when type is completion', () => {
  18. const provider = createTogetherAiProvider('togetherai:completion:model-name');
  19. expect(provider).toBeInstanceOf(OpenAiCompletionProvider);
  20. expect(OpenAiCompletionProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
  21. });
  22. it('should create an embedding provider when type is embedding', () => {
  23. const provider = createTogetherAiProvider('togetherai:embedding:model-name');
  24. expect(provider).toBeInstanceOf(OpenAiEmbeddingProvider);
  25. expect(OpenAiEmbeddingProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
  26. });
  27. it('should create an embedding provider when type is embeddings', () => {
  28. const provider = createTogetherAiProvider('togetherai:embeddings:model-name');
  29. expect(provider).toBeInstanceOf(OpenAiEmbeddingProvider);
  30. expect(OpenAiEmbeddingProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
  31. });
  32. it('should default to chat completion provider when no type is specified', () => {
  33. const provider = createTogetherAiProvider('togetherai:model-name');
  34. expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
  35. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
  36. });
  37. it('should pass correct configuration to the provider', () => {
  38. const options: {
  39. config?: ProviderOptions;
  40. id?: string;
  41. env?: EnvOverrides;
  42. } = {
  43. id: 'custom-id',
  44. };
  45. createTogetherAiProvider('togetherai:chat:model-name', options);
  46. // Verify that the OpenAI provider was called with the correct parameters
  47. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('model-name', {
  48. config: {
  49. apiBaseUrl: 'https://api.together.xyz/v1',
  50. apiKeyEnvar: 'TOGETHER_API_KEY',
  51. passthrough: {},
  52. },
  53. id: 'custom-id',
  54. });
  55. });
  56. it('should handle model names with colons', () => {
  57. createTogetherAiProvider('togetherai:chat:org:model:name');
  58. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('org:model:name', expect.any(Object));
  59. });
  60. describe('parameter handling', () => {
  61. it('should add all parameters to passthrough', () => {
  62. const options = {
  63. config: {
  64. config: {
  65. max_tokens: 4096,
  66. temperature: 0.7,
  67. top_p: 0.9,
  68. repetition_penalty: 1.1,
  69. custom_param: 'value',
  70. },
  71. },
  72. };
  73. createTogetherAiProvider('togetherai:chat:model-name', options);
  74. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith(
  75. 'model-name',
  76. expect.objectContaining({
  77. config: expect.objectContaining({
  78. apiBaseUrl: 'https://api.together.xyz/v1',
  79. apiKeyEnvar: 'TOGETHER_API_KEY',
  80. passthrough: expect.objectContaining({
  81. max_tokens: 4096,
  82. temperature: 0.7,
  83. top_p: 0.9,
  84. repetition_penalty: 1.1,
  85. custom_param: 'value',
  86. }),
  87. }),
  88. }),
  89. );
  90. });
  91. it('should handle TogetherAI-specific parameters correctly', () => {
  92. const options = {
  93. config: {
  94. config: {
  95. stop_sequences: ['END'],
  96. top_k: 50,
  97. safety_model: 'safety-model',
  98. },
  99. },
  100. };
  101. createTogetherAiProvider('togetherai:chat:model-name', options);
  102. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith(
  103. 'model-name',
  104. expect.objectContaining({
  105. config: expect.objectContaining({
  106. passthrough: expect.objectContaining({
  107. stop_sequences: ['END'],
  108. top_k: 50,
  109. safety_model: 'safety-model',
  110. }),
  111. }),
  112. }),
  113. );
  114. });
  115. it('should handle passthrough correctly', () => {
  116. const options = {
  117. config: {
  118. config: {
  119. temperature: 0.7,
  120. passthrough: {
  121. custom_param: 'value',
  122. },
  123. },
  124. },
  125. };
  126. createTogetherAiProvider('togetherai:chat:model-name', options);
  127. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith(
  128. 'model-name',
  129. expect.objectContaining({
  130. config: expect.objectContaining({
  131. passthrough: expect.objectContaining({
  132. temperature: 0.7,
  133. passthrough: {
  134. custom_param: 'value',
  135. },
  136. }),
  137. }),
  138. }),
  139. );
  140. });
  141. });
  142. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...