1
- import { ProviderConfigs } from '../types' ;
1
+ import { ErrorResponse , ProviderConfigs } from '../types' ;
2
2
import { X_AI } from '../../globals' ;
3
3
import XAIAPIConfig from './api' ;
4
4
import {
@@ -8,15 +8,43 @@ import {
8
8
responseTransformers ,
9
9
} from '../open-ai-base' ;
10
10
11
+ interface XAIErrorResponse {
12
+ error :
13
+ | {
14
+ message : string ;
15
+ code : string ;
16
+ param : string | null ;
17
+ type : string | null ;
18
+ }
19
+ | string ;
20
+ code ?: string ;
21
+ }
22
+
23
+ const xAIResponseTransform = < T > ( response : T ) => {
24
+ let _response = response as XAIErrorResponse ;
25
+ if ( 'error' in _response ) {
26
+ return {
27
+ error : {
28
+ message : _response . error as string ,
29
+ code : _response . code ?? null ,
30
+ param : null ,
31
+ type : null ,
32
+ } ,
33
+ provider : X_AI ,
34
+ } ;
35
+ }
36
+ return response ;
37
+ } ;
38
+
11
39
const XAIConfig : ProviderConfigs = {
12
40
chatComplete : chatCompleteParams ( [ ] , { model : 'grok-beta' } ) ,
13
41
complete : completeParams ( [ ] , { model : 'grok-beta' } ) ,
14
42
embed : embedParams ( [ ] , { model : 'v1' } ) ,
15
43
api : XAIAPIConfig ,
16
44
responseTransforms : responseTransformers ( X_AI , {
17
- chatComplete : true ,
18
- complete : true ,
19
- embed : true ,
45
+ chatComplete : xAIResponseTransform ,
46
+ complete : xAIResponseTransform ,
47
+ embed : xAIResponseTransform ,
20
48
} ) ,
21
49
} ;
22
50
0 commit comments