@deepagents/text2sql 0.17.1 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -801,19 +801,21 @@ async function toSql(options) {
|
|
|
801
801
|
const sqlOutput = structuredOutput2({
|
|
802
802
|
model,
|
|
803
803
|
context,
|
|
804
|
-
schema: z4.
|
|
805
|
-
z4.
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
804
|
+
schema: z4.object({
|
|
805
|
+
result: z4.union([
|
|
806
|
+
z4.object({
|
|
807
|
+
sql: z4.string().describe("The SQL query that answers the question"),
|
|
808
|
+
reasoning: z4.string().describe("The reasoning steps taken to generate the SQL")
|
|
809
|
+
}),
|
|
810
|
+
z4.object({
|
|
811
|
+
error: z4.string().describe(
|
|
812
|
+
"Error message explaining why the question cannot be answered with the given schema"
|
|
813
|
+
)
|
|
814
|
+
})
|
|
815
|
+
])
|
|
816
|
+
})
|
|
815
817
|
});
|
|
816
|
-
const output = await sqlOutput.generate();
|
|
818
|
+
const { result: output } = await sqlOutput.generate();
|
|
817
819
|
if ("error" in output) {
|
|
818
820
|
throw new UnanswerableSQLError(output.error);
|
|
819
821
|
}
|
|
@@ -843,6 +845,16 @@ function formatErrorMessage(error) {
|
|
|
843
845
|
}
|
|
844
846
|
return error.message;
|
|
845
847
|
}
|
|
848
|
+
function isModelUnavailableError(error) {
|
|
849
|
+
if (!APICallError.isInstance(error)) {
|
|
850
|
+
return false;
|
|
851
|
+
}
|
|
852
|
+
const message2 = error.message.toLowerCase();
|
|
853
|
+
const responseBody = (error.responseBody ?? "").toLowerCase();
|
|
854
|
+
const is404ModelError = error.statusCode === 404 && (message2.includes("model") || responseBody.includes("model_not_found"));
|
|
855
|
+
const errorCode = typeof error.data === "object" && error.data !== null && "error" in error.data && typeof error.data.error === "object" && error.data.error !== null && "code" in error.data.error && typeof error.data.error.code === "string" ? error.data.error.code.toLowerCase() : void 0;
|
|
856
|
+
return is404ModelError || errorCode === "model_not_found" || responseBody.includes('"code":"model_not_found"') || message2.includes("model") && message2.includes("does not exist or you do not have access to it");
|
|
857
|
+
}
|
|
846
858
|
async function withRetry(computation, options = { retries: 3 }) {
|
|
847
859
|
const errors = [];
|
|
848
860
|
let attempts = 0;
|
|
@@ -856,6 +868,9 @@ async function withRetry(computation, options = { retries: 3 }) {
|
|
|
856
868
|
if (UnanswerableSQLError.isInstance(context.error)) {
|
|
857
869
|
return false;
|
|
858
870
|
}
|
|
871
|
+
if (isModelUnavailableError(context.error)) {
|
|
872
|
+
return false;
|
|
873
|
+
}
|
|
859
874
|
if (SQLValidationError.isInstance(context.error)) {
|
|
860
875
|
return true;
|
|
861
876
|
}
|