-
Notifications
You must be signed in to change notification settings - Fork 763
fix: transform x-ai error response to open-ai format #1250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -8,15 +8,43 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
responseTransformers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} from '../open-ai-base'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
interface XAIErrorResponse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
error: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
message: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
code: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
param: string | null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type: string | null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
code?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const xAIResponseTransform = <T>(response: T) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let _response = response as XAIErrorResponse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ('error' in _response) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
error: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
message: _response.error as string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
code: _response.code ?? null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
param: null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type: null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
provider: X_AI, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+24
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐛 Bug Fix Issue: The error handling doesn't properly handle the case when the error property is an object rather than a string, despite the interface defining it as potentially being an object.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const XAIConfig: ProviderConfigs = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chatComplete: chatCompleteParams([], { model: 'grok-beta' }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
complete: completeParams([], { model: 'grok-beta' }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
embed: embedParams([], { model: 'v1' }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
api: XAIAPIConfig, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
responseTransforms: responseTransformers(X_AI, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chatComplete: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
complete: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
embed: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chatComplete: xAIResponseTransform, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
complete: xAIResponseTransform, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
embed: xAIResponseTransform, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Code Refactor
Issue: The function lacks documentation explaining its purpose and behavior.
Fix: Add JSDoc comments to explain the function's purpose and return value.
Impact: Improves code maintainability and makes it easier for other developers to understand the transformation logic.