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

lambdalabs.test.ts 4.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
  1. import { createLambdaLabsProvider } from '../../src/providers/lambdalabs';
  2. import { OpenAiChatCompletionProvider } from '../../src/providers/openai/chat';
  3. import { OpenAiCompletionProvider } from '../../src/providers/openai/completion';
  4. import { OpenAiEmbeddingProvider } from '../../src/providers/openai/embedding';
  5. jest.mock('../../src/providers/openai/chat');
  6. jest.mock('../../src/providers/openai/completion');
  7. jest.mock('../../src/providers/openai/embedding');
  8. describe('createLambdaLabsProvider', () => {
  9. beforeEach(() => {
  10. jest.resetAllMocks();
  11. });
  12. it('should create chat provider when path includes chat', () => {
  13. const provider = createLambdaLabsProvider('lambda:chat:model-name');
  14. expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
  15. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('model-name', {
  16. config: {
  17. apiBaseUrl: 'https://api.lambda.ai/v1',
  18. apiKeyEnvar: 'LAMBDA_API_KEY',
  19. passthrough: {},
  20. },
  21. });
  22. });
  23. it('should create completion provider when path includes completion', () => {
  24. const provider = createLambdaLabsProvider('lambda:completion:model-name');
  25. expect(provider).toBeInstanceOf(OpenAiCompletionProvider);
  26. expect(OpenAiCompletionProvider).toHaveBeenCalledWith('model-name', {
  27. config: {
  28. apiBaseUrl: 'https://api.lambda.ai/v1',
  29. apiKeyEnvar: 'LAMBDA_API_KEY',
  30. passthrough: {},
  31. },
  32. });
  33. });
  34. it('should create embedding provider when path includes embedding', () => {
  35. const provider = createLambdaLabsProvider('lambda:embedding:model-name');
  36. expect(provider).toBeInstanceOf(OpenAiEmbeddingProvider);
  37. expect(OpenAiEmbeddingProvider).toHaveBeenCalledWith('model-name', {
  38. config: {
  39. apiBaseUrl: 'https://api.lambda.ai/v1',
  40. apiKeyEnvar: 'LAMBDA_API_KEY',
  41. passthrough: {},
  42. },
  43. });
  44. });
  45. it('should create embedding provider when path includes embeddings', () => {
  46. const provider = createLambdaLabsProvider('lambda:embeddings:model-name');
  47. expect(provider).toBeInstanceOf(OpenAiEmbeddingProvider);
  48. expect(OpenAiEmbeddingProvider).toHaveBeenCalledWith('model-name', {
  49. config: {
  50. apiBaseUrl: 'https://api.lambda.ai/v1',
  51. apiKeyEnvar: 'LAMBDA_API_KEY',
  52. passthrough: {},
  53. },
  54. });
  55. });
  56. it('should default to chat provider when no type specified', () => {
  57. const provider = createLambdaLabsProvider('lambda:model-name');
  58. expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
  59. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('model-name', {
  60. config: {
  61. apiBaseUrl: 'https://api.lambda.ai/v1',
  62. apiKeyEnvar: 'LAMBDA_API_KEY',
  63. passthrough: {},
  64. },
  65. });
  66. });
  67. it('should pass through additional config options', () => {
  68. const provider = createLambdaLabsProvider('lambda:chat:model-name', {
  69. config: {
  70. config: {
  71. temperature: 0.7,
  72. maxTokens: 100,
  73. },
  74. },
  75. });
  76. expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
  77. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('model-name', {
  78. config: {
  79. apiBaseUrl: 'https://api.lambda.ai/v1',
  80. apiKeyEnvar: 'LAMBDA_API_KEY',
  81. passthrough: {
  82. temperature: 0.7,
  83. maxTokens: 100,
  84. },
  85. },
  86. });
  87. });
  88. it('should pass through provider ID', () => {
  89. const provider = createLambdaLabsProvider('lambda:chat:model-name', {
  90. id: 'my-provider',
  91. });
  92. expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
  93. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('model-name', {
  94. id: 'my-provider',
  95. config: {
  96. apiBaseUrl: 'https://api.lambda.ai/v1',
  97. apiKeyEnvar: 'LAMBDA_API_KEY',
  98. passthrough: {},
  99. },
  100. });
  101. });
  102. it('should pass through env overrides', () => {
  103. const provider = createLambdaLabsProvider('lambda:chat:model-name', {
  104. env: {
  105. LAMBDA_API_KEY: 'test-key',
  106. },
  107. });
  108. expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
  109. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('model-name', {
  110. env: {
  111. LAMBDA_API_KEY: 'test-key',
  112. },
  113. config: {
  114. apiBaseUrl: 'https://api.lambda.ai/v1',
  115. apiKeyEnvar: 'LAMBDA_API_KEY',
  116. passthrough: {},
  117. },
  118. });
  119. });
  120. });
Tip!

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

Comments

Loading...