From a869e45c0056d16050bdc5c87c1696827ec32b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= Date: Sat, 23 Sep 2023 16:10:19 +0200 Subject: [PATCH 1/3] change sdk url based on env variable --- packages/@pufflig/ps-sdk/package.json | 2 +- packages/@pufflig/ps-sdk/src/constants.ts | 7 +++++++ packages/@pufflig/ps-sdk/src/createCompletion.ts | 4 ++-- packages/@pufflig/ps-sdk/vite.config.ts | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/@pufflig/ps-sdk/package.json b/packages/@pufflig/ps-sdk/package.json index 1776963..bebc2b5 100644 --- a/packages/@pufflig/ps-sdk/package.json +++ b/packages/@pufflig/ps-sdk/package.json @@ -3,7 +3,7 @@ "version": "0.19.1", "license": "MIT", "main": "./dist/ps-sdk.umd.js", - "module": "./dist/ps-sdk.es.js", + "module": "./dist/ps-sdk.cjs.js", "types": "./dist/ps-sdk.d.ts", "files": [ "dist" diff --git a/packages/@pufflig/ps-sdk/src/constants.ts b/packages/@pufflig/ps-sdk/src/constants.ts index 1948ad6..4eebb91 100644 --- a/packages/@pufflig/ps-sdk/src/constants.ts +++ b/packages/@pufflig/ps-sdk/src/constants.ts @@ -1 +1,8 @@ export const SERVICE_URL = "https://api.prompt.studio/api/v1/completion"; + +export const getServiceUrl = () => { + if (process.env.PROMPT_STUDIO_RUNTIME === "local") { + return "http://localhost:8088/api/v1/completion"; + } + return SERVICE_URL; +}; diff --git a/packages/@pufflig/ps-sdk/src/createCompletion.ts b/packages/@pufflig/ps-sdk/src/createCompletion.ts index 34742f0..df8a62d 100644 --- a/packages/@pufflig/ps-sdk/src/createCompletion.ts +++ b/packages/@pufflig/ps-sdk/src/createCompletion.ts @@ -1,5 +1,5 @@ import axios, { AxiosRequestConfig } from "axios"; -import { SERVICE_URL } from "./constants"; +import { getServiceUrl } from "./constants"; import { Datapoint } from "./types"; interface CreateCompletionInput { @@ -27,7 +27,7 @@ export async function createCompletion(input: CreateCompletionInput, callbacks?: const payload: AxiosRequestConfig = { method: "post", - url: SERVICE_URL, + url: getServiceUrl(), responseType: "stream", headers: { "Content-Type": "application/json", diff --git a/packages/@pufflig/ps-sdk/vite.config.ts b/packages/@pufflig/ps-sdk/vite.config.ts index aa7e1ef..015916e 100644 --- a/packages/@pufflig/ps-sdk/vite.config.ts +++ b/packages/@pufflig/ps-sdk/vite.config.ts @@ -12,7 +12,7 @@ export default defineConfig({ lib: { entry: path.resolve(__dirname, "src/index.ts"), name: "@pufflig/ps-sdk", - formats: ["es", "umd"], + formats: ["cjs", "es", "umd"], fileName: (format) => `ps-sdk.${format}.js`, }, rollupOptions: { From c02a40a538e8fb9746f396ade968b568a129a87b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= Date: Sat, 23 Sep 2023 23:49:47 +0200 Subject: [PATCH 2/3] add runtime flag --- packages/@pufflig/ps-nodes/package.json | 1 + packages/@pufflig/ps-sdk/package.json | 2 +- .../@pufflig/ps-sdk/src/createCompletion.ts | 19 +++++++++++-------- packages/@pufflig/ps-sdk/vite.config.ts | 4 ++-- yarn.lock | 6 +++--- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/@pufflig/ps-nodes/package.json b/packages/@pufflig/ps-nodes/package.json index 5813f99..c7dcc83 100644 --- a/packages/@pufflig/ps-nodes/package.json +++ b/packages/@pufflig/ps-nodes/package.json @@ -35,6 +35,7 @@ "@pufflig/ps-models": "^0.19.1", "@pufflig/ps-nodes-config": "^0.19.1", "@pufflig/ps-sdk": "^0.19.1", + "axios": "^1.5.0", "lodash": "^4.17.21", "mustache": "^4.2.0", "openai": "^3.3.0", diff --git a/packages/@pufflig/ps-sdk/package.json b/packages/@pufflig/ps-sdk/package.json index bebc2b5..1776963 100644 --- a/packages/@pufflig/ps-sdk/package.json +++ b/packages/@pufflig/ps-sdk/package.json @@ -3,7 +3,7 @@ "version": "0.19.1", "license": "MIT", "main": "./dist/ps-sdk.umd.js", - "module": "./dist/ps-sdk.cjs.js", + "module": "./dist/ps-sdk.es.js", "types": "./dist/ps-sdk.d.ts", "files": [ "dist" diff --git a/packages/@pufflig/ps-sdk/src/createCompletion.ts b/packages/@pufflig/ps-sdk/src/createCompletion.ts index df8a62d..222db0e 100644 --- a/packages/@pufflig/ps-sdk/src/createCompletion.ts +++ b/packages/@pufflig/ps-sdk/src/createCompletion.ts @@ -15,7 +15,7 @@ interface CreateCompletionInput { } interface Callbacks { - onTokenReceived?: (token: string) => void; + onNewToken?: (token: string) => void; } interface Completion { @@ -50,17 +50,20 @@ export async function createCompletion(input: CreateCompletionInput, callbacks?: const response = await axios(payload); const stream = response.data; - let completion = ""; + let result = {}; stream.on("data", (buffer: Buffer) => { const chunk = buffer.toString("utf-8"); - const row = chunk.split("\n\n")[0]; - const match = row.match(/^data: (.+)/); - const data = JSON.parse(match?.[1] || "{}"); - callbacks?.onTokenReceived?.(data.datapoint.model_output); - completion += data.datapoint.model_output; - result = data; + const rows = chunk.split("\n\n"); + rows.forEach((row) => { + const match = row.match(/^data: (.+)/); + const data = JSON.parse(match?.[1] || "{}"); + if (data.datapoint?.model_output) { + callbacks?.onNewToken?.(data.datapoint.model_output); + result = data; + } + }); }); return new Promise((resolve, reject) => { diff --git a/packages/@pufflig/ps-sdk/vite.config.ts b/packages/@pufflig/ps-sdk/vite.config.ts index 015916e..c62f90f 100644 --- a/packages/@pufflig/ps-sdk/vite.config.ts +++ b/packages/@pufflig/ps-sdk/vite.config.ts @@ -12,11 +12,11 @@ export default defineConfig({ lib: { entry: path.resolve(__dirname, "src/index.ts"), name: "@pufflig/ps-sdk", - formats: ["cjs", "es", "umd"], + formats: ["es", "umd"], fileName: (format) => `ps-sdk.${format}.js`, }, rollupOptions: { - external: [], + external: ["axios"], }, }, }); diff --git a/yarn.lock b/yarn.lock index ea761c5..c973422 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17304,9 +17304,9 @@ vite-plugin-dts@^2.3.0: ts-morph "18.0.0" vite-plugin-dts@^3.5.3: - version "3.5.3" - resolved "https://registry.yarnpkg.com/vite-plugin-dts/-/vite-plugin-dts-3.5.3.tgz#602dca3ceb5e56bed1b9ec32d92d4c24d049581d" - integrity sha512-h94j/+SR1PhLR9jnEtcjZILagE2QZBAV8V1y3T2Ujcet1VI0Et4dZSU1W8fbnp6obB7B3/b8hArqdi2/9HuH+w== + version "3.5.4" + resolved "https://registry.yarnpkg.com/vite-plugin-dts/-/vite-plugin-dts-3.5.4.tgz#4feb3dd2201c51cc2727efd60ffc55b70af0e41d" + integrity sha512-BJLBj1Vg9kV7ZMXAULT9UGogrElwz5s+k8TzC7LsFkHv5Jy90OWnHKUp8qm7sypu2pkF5pTJ5McUuHudnT0Imw== dependencies: "@microsoft/api-extractor" "^7.36.4" "@rollup/pluginutils" "^5.0.2" From a1d1afb1d6f3fc5cf8177327e0058af6ba711c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= Date: Sat, 23 Sep 2023 23:52:28 +0200 Subject: [PATCH 3/3] v0.19.2 --- lerna.json | 2 +- packages/@pufflig/ps-chains/package.json | 4 ++-- packages/@pufflig/ps-models/package.json | 4 ++-- packages/@pufflig/ps-node-editor/package.json | 8 ++++---- packages/@pufflig/ps-nodes-config/package.json | 6 +++--- packages/@pufflig/ps-nodes/package.json | 10 +++++----- packages/@pufflig/ps-sdk/package.json | 4 ++-- packages/@pufflig/ps-types/package.json | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lerna.json b/lerna.json index 1938761..e550b38 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "0.19.1" + "version": "0.19.2" } diff --git a/packages/@pufflig/ps-chains/package.json b/packages/@pufflig/ps-chains/package.json index 230a54d..73a3a72 100644 --- a/packages/@pufflig/ps-chains/package.json +++ b/packages/@pufflig/ps-chains/package.json @@ -1,6 +1,6 @@ { "name": "@pufflig/ps-chains", - "version": "0.19.1", + "version": "0.19.2", "license": "MIT", "main": "./dist/ps-chains.umd.js", "module": "./dist/ps-chains.es.js", @@ -16,7 +16,7 @@ "test": "jest" }, "devDependencies": { - "@pufflig/ps-types": "^0.19.1", + "@pufflig/ps-types": "^0.19.2", "@types/react-dom": "^18.2.7", "immer": "^10.0.2", "prop-types": "^15.8.1", diff --git a/packages/@pufflig/ps-models/package.json b/packages/@pufflig/ps-models/package.json index 762abe0..9c67246 100644 --- a/packages/@pufflig/ps-models/package.json +++ b/packages/@pufflig/ps-models/package.json @@ -1,7 +1,7 @@ { "name": "@pufflig/ps-models", "private": false, - "version": "0.19.1", + "version": "0.19.2", "description": "Configuration of models used in Prompt Studio", "files": [ "dist" @@ -16,7 +16,7 @@ "author": "Pufflig AB", "license": "MIT", "devDependencies": { - "@pufflig/ps-types": "^0.19.1", + "@pufflig/ps-types": "^0.19.2", "typescript": "^5.1.6", "vite": "^4.3.9", "vite-plugin-dts": "^2.3.0" diff --git a/packages/@pufflig/ps-node-editor/package.json b/packages/@pufflig/ps-node-editor/package.json index 0a809ee..8b44cc5 100644 --- a/packages/@pufflig/ps-node-editor/package.json +++ b/packages/@pufflig/ps-node-editor/package.json @@ -3,7 +3,7 @@ "main": "./dist/ps-node-editor.umd.js", "module": "./dist/ps-node-editor.es.js", "types": "./dist/ps-node-editor.d.ts", - "version": "0.19.1", + "version": "0.19.2", "type": "module", "scripts": { "dev": "vite", @@ -20,15 +20,15 @@ "@emotion/css": "^11.11.2", "@emotion/react": "^11.11.1", "@emotion/styled": "^11.11.0", - "@pufflig/ps-chains": "^0.19.1", - "@pufflig/ps-nodes": "^0.19.1", + "@pufflig/ps-chains": "^0.19.2", + "@pufflig/ps-nodes": "^0.19.2", "framer-motion": "^10.16.0", "react": "^18.2.0", "react-dom": "^18.2.0", "reactflow": "^11.8.2" }, "devDependencies": { - "@pufflig/ps-types": "^0.19.1", + "@pufflig/ps-types": "^0.19.2", "@pufflig/ps-ui": "*", "@storybook/addon-essentials": "^7.2.1", "@storybook/addon-interactions": "^7.2.1", diff --git a/packages/@pufflig/ps-nodes-config/package.json b/packages/@pufflig/ps-nodes-config/package.json index 0747362..5e6dbe1 100644 --- a/packages/@pufflig/ps-nodes-config/package.json +++ b/packages/@pufflig/ps-nodes-config/package.json @@ -1,7 +1,7 @@ { "name": "@pufflig/ps-nodes-config", "private": false, - "version": "0.19.1", + "version": "0.19.2", "description": "Configuration files for nodes used in prompt studio.", "files": [ "dist" @@ -16,10 +16,10 @@ "author": "Pufflig AB", "license": "MIT", "dependencies": { - "@pufflig/ps-models": "^0.19.1" + "@pufflig/ps-models": "^0.19.2" }, "devDependencies": { - "@pufflig/ps-types": "^0.19.1", + "@pufflig/ps-types": "^0.19.2", "@types/jest": "^29.5.1", "jest": "^29.5.0", "ts-jest": "^29.1.0", diff --git a/packages/@pufflig/ps-nodes/package.json b/packages/@pufflig/ps-nodes/package.json index c7dcc83..68add2d 100644 --- a/packages/@pufflig/ps-nodes/package.json +++ b/packages/@pufflig/ps-nodes/package.json @@ -1,7 +1,7 @@ { "name": "@pufflig/ps-nodes", "private": false, - "version": "0.19.1", + "version": "0.19.2", "description": "Collection of nodes used in Prompt Studio", "files": [ "dist" @@ -17,7 +17,7 @@ "author": "Pufflig AB", "license": "MIT", "devDependencies": { - "@pufflig/ps-types": "^0.19.1", + "@pufflig/ps-types": "^0.19.2", "@types/jest": "^29.5.1", "@types/lodash": "^4.14.196", "@types/mustache": "^4.2.2", @@ -32,9 +32,9 @@ "node": "18.16.0" }, "dependencies": { - "@pufflig/ps-models": "^0.19.1", - "@pufflig/ps-nodes-config": "^0.19.1", - "@pufflig/ps-sdk": "^0.19.1", + "@pufflig/ps-models": "^0.19.2", + "@pufflig/ps-nodes-config": "^0.19.2", + "@pufflig/ps-sdk": "^0.19.2", "axios": "^1.5.0", "lodash": "^4.17.21", "mustache": "^4.2.0", diff --git a/packages/@pufflig/ps-sdk/package.json b/packages/@pufflig/ps-sdk/package.json index 1776963..d311ed2 100644 --- a/packages/@pufflig/ps-sdk/package.json +++ b/packages/@pufflig/ps-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@pufflig/ps-sdk", - "version": "0.19.1", + "version": "0.19.2", "license": "MIT", "main": "./dist/ps-sdk.umd.js", "module": "./dist/ps-sdk.es.js", @@ -21,7 +21,7 @@ "vite-plugin-dts": "^3.5.3" }, "dependencies": { - "@pufflig/ps-models": "^0.19.1", + "@pufflig/ps-models": "^0.19.2", "axios": "^1.5.0" }, "gitHead": "d637557b77c60c4aa75f6f65b038a6eb4e9d5dc4" diff --git a/packages/@pufflig/ps-types/package.json b/packages/@pufflig/ps-types/package.json index 72e3d06..8570190 100644 --- a/packages/@pufflig/ps-types/package.json +++ b/packages/@pufflig/ps-types/package.json @@ -1,6 +1,6 @@ { "name": "@pufflig/ps-types", - "version": "0.19.1", + "version": "0.19.2", "description": "Typescript definitions for Prompt Studio", "main": "src/index.ts", "author": "Pufflig AB",