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 2.9 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
  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. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith(
  47. 'model-name',
  48. expect.objectContaining({
  49. config: {
  50. apiBaseUrl: 'https://api.together.xyz/v1',
  51. apiKeyEnvar: 'TOGETHER_API_KEY',
  52. },
  53. id: 'custom-id',
  54. }),
  55. );
  56. });
  57. it('should handle model names with colons', () => {
  58. createTogetherAiProvider('togetherai:chat:org:model:name');
  59. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('org:model:name', expect.any(Object));
  60. });
  61. });
Tip!

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

Comments

Loading...