Skip to content
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

change sdk url based on env variable #58

Merged
merged 3 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "0.19.1"
"version": "0.19.2"
}
4 changes: 2 additions & 2 deletions packages/@pufflig/ps-chains/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/@pufflig/ps-models/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions packages/@pufflig/ps-node-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/@pufflig/ps-nodes-config/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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",
Expand Down
11 changes: 6 additions & 5 deletions packages/@pufflig/ps-nodes/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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",
Expand All @@ -32,9 +32,10 @@
"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",
"openai": "^3.3.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/@pufflig/ps-sdk/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions packages/@pufflig/ps-sdk/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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;
};
23 changes: 13 additions & 10 deletions packages/@pufflig/ps-sdk/src/createCompletion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios, { AxiosRequestConfig } from "axios";
import { SERVICE_URL } from "./constants";
import { getServiceUrl } from "./constants";
import { Datapoint } from "./types";

interface CreateCompletionInput {
Expand All @@ -15,7 +15,7 @@ interface CreateCompletionInput {
}

interface Callbacks {
onTokenReceived?: (token: string) => void;
onNewToken?: (token: string) => void;
}

interface Completion {
Expand All @@ -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",
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@pufflig/ps-sdk/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default defineConfig({
fileName: (format) => `ps-sdk.${format}.js`,
},
rollupOptions: {
external: [],
external: ["axios"],
},
},
});
2 changes: 1 addition & 1 deletion packages/@pufflig/ps-types/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down