From e6cccefe8b2691bf280ee2f4ed1dbc482b0bf2e0 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Thu, 19 Sep 2024 13:55:07 -0400 Subject: [PATCH] Fix createCompleition method --- package-lock.json | 4 ++-- src/index.js | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0b5c0c7..7f92588 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "formulaic-node", - "version": "0.2.0", + "version": "0.2.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "formulaic-node", - "version": "0.2.0", + "version": "0.2.3", "license": "MPL-2.0", "devDependencies": { "jest": "^29.7.0" diff --git a/src/index.js b/src/index.js index 7d71adb..59b0d22 100644 --- a/src/index.js +++ b/src/index.js @@ -118,6 +118,16 @@ class Formulaic { } } + async getScripts(formulaId) { + const url = `${this.baseURL}/api/recipes/${formulaId}/scripts`; + this.logDebug("Fetching scripts for formula:", formulaId); + try { + return await this.httpClient.get(url); + } catch (error) { + throw new Error(`Failed to get scripts: ${error.message}`); + } + } + async createFormula(data) { const url = `${this.baseURL}/api/recipes`; @@ -135,8 +145,8 @@ class Formulaic { const variables = Array.isArray(data.variables) ? data.variables : []; try { - const formula = await this.getFormula(formulaId); - const url = `${this.baseURL}/api/recipes/${formulaId}/scripts/${formula.id}/artifacts`; + const script = await this.getScripts(formulaId); + const url = `${this.baseURL}/api/recipes/${formulaId}/scripts/${script.id}/artifacts`; this.logDebug("Creating completion for formula:", formulaId); return await this.httpClient.post(url, { ...data, models, variables });