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.8 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
  1. import {
  2. OpenAiChatCompletionProvider,
  3. OpenAiCompletionProvider,
  4. OpenAiEmbeddingProvider,
  5. } from '../../src/providers/openai';
  6. import { createTogetherAiProvider } from '../../src/providers/togetherai';
  7. import type { ProviderOptions } from '../../src/types';
  8. import type { EnvOverrides } from '../../src/types/env';
  9. jest.mock('../../src/providers/openai');
  10. describe('createTogetherAiProvider', () => {
  11. beforeEach(() => {
  12. jest.clearAllMocks();
  13. });
  14. it('should create a chat completion provider when type is chat', () => {
  15. const provider = createTogetherAiProvider('togetherai:chat:model-name');
  16. expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
  17. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
  18. });
  19. it('should create a completion provider when type is completion', () => {
  20. const provider = createTogetherAiProvider('togetherai:completion:model-name');
  21. expect(provider).toBeInstanceOf(OpenAiCompletionProvider);
  22. expect(OpenAiCompletionProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
  23. });
  24. it('should create an embedding provider when type is embedding', () => {
  25. const provider = createTogetherAiProvider('togetherai:embedding:model-name');
  26. expect(provider).toBeInstanceOf(OpenAiEmbeddingProvider);
  27. expect(OpenAiEmbeddingProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
  28. });
  29. it('should create an embedding provider when type is embeddings', () => {
  30. const provider = createTogetherAiProvider('togetherai:embeddings:model-name');
  31. expect(provider).toBeInstanceOf(OpenAiEmbeddingProvider);
  32. expect(OpenAiEmbeddingProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
  33. });
  34. it('should default to chat completion provider when no type is specified', () => {
  35. const provider = createTogetherAiProvider('togetherai:model-name');
  36. expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
  37. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('model-name', expect.any(Object));
  38. });
  39. it('should pass correct configuration to the provider', () => {
  40. const options: {
  41. config?: ProviderOptions;
  42. id?: string;
  43. env?: EnvOverrides;
  44. } = {
  45. id: 'custom-id',
  46. };
  47. createTogetherAiProvider('togetherai:chat:model-name', options);
  48. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith(
  49. 'model-name',
  50. expect.objectContaining({
  51. config: {
  52. apiBaseUrl: 'https://api.together.xyz/v1',
  53. apiKeyEnvar: 'TOGETHER_API_KEY',
  54. },
  55. id: 'custom-id',
  56. }),
  57. );
  58. });
  59. it('should handle model names with colons', () => {
  60. createTogetherAiProvider('togetherai:chat:org:model:name');
  61. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('org:model:name', expect.any(Object));
  62. });
  63. });
Tip!

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

Comments

Loading...