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

xai.test.ts 1.7 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
  1. import { OpenAiChatCompletionProvider } from '../../src/providers/openai';
  2. import { createXAIProvider } from '../../src/providers/xai';
  3. import type { ProviderOptions } from '../../src/types/providers';
  4. jest.mock('../../src/providers/openai');
  5. describe('xAI Provider', () => {
  6. beforeEach(() => {
  7. jest.clearAllMocks();
  8. });
  9. it('throws an error if no model name is provided', () => {
  10. expect(() => createXAIProvider('xai:')).toThrow('Model name is required');
  11. });
  12. it('creates an xAI provider with specified model', () => {
  13. const provider = createXAIProvider('xai:grok-2');
  14. expect(provider).toBeInstanceOf(OpenAiChatCompletionProvider);
  15. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('grok-2', expect.any(Object));
  16. });
  17. it('sets the correct API base URL and API key environment variable', () => {
  18. createXAIProvider('xai:grok-2');
  19. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith(
  20. expect.any(String),
  21. expect.objectContaining({
  22. config: expect.objectContaining({
  23. apiBaseUrl: 'https://api.x.ai/v1',
  24. apiKeyEnvar: 'XAI_API_KEY',
  25. }),
  26. }),
  27. );
  28. });
  29. it('merges provided options with xAI-specific config', () => {
  30. const options: ProviderOptions = {
  31. config: {
  32. temperature: 0.7,
  33. max_tokens: 100,
  34. },
  35. id: 'custom-id',
  36. };
  37. createXAIProvider('xai:grok-2', options);
  38. expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith(
  39. 'grok-2',
  40. expect.objectContaining({
  41. config: expect.objectContaining({
  42. apiBaseUrl: 'https://api.x.ai/v1',
  43. apiKeyEnvar: 'XAI_API_KEY',
  44. temperature: 0.7,
  45. max_tokens: 100,
  46. }),
  47. id: 'custom-id',
  48. }),
  49. );
  50. });
  51. });
Tip!

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

Comments

Loading...