Switch the local inference provider MLX backend to use the safemlx crate (#10304)
This commit is contained in:
@@ -13,6 +13,11 @@ export async function safeJsonParse<T>(
|
||||
}
|
||||
|
||||
export function errorMessage(err: Error | unknown, default_value?: string) {
|
||||
const acpData = acpErrorData(err);
|
||||
if (typeof acpData === 'string') {
|
||||
return acpData;
|
||||
}
|
||||
|
||||
if (err instanceof Error) {
|
||||
return err.message;
|
||||
} else if (typeof err === 'object' && err !== null && 'message' in err) {
|
||||
@@ -22,6 +27,19 @@ export function errorMessage(err: Error | unknown, default_value?: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function acpErrorData(err: unknown): unknown {
|
||||
if (typeof err !== 'object' || err === null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const candidate = 'error' in err && isRecord(err.error) ? err.error : err;
|
||||
return isRecord(candidate) ? candidate.data : undefined;
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === 'object' && value !== null;
|
||||
}
|
||||
|
||||
export function formatErrorForLogging(error: unknown): string {
|
||||
if (error instanceof Error) {
|
||||
return `${error.name}: ${error.message}${error.stack ? `\n${error.stack}` : ''}`;
|
||||
|
||||
Reference in New Issue
Block a user