Load the JS client using pnpm workspaces

This makes it so we're using our own openpipe client for all OpenAI calls from the OpenPipe app.

The client doesn't do anything at the moment beyond proxying to the OpenAI lib. But this infra work should make it easier to quickly iterate on the client and test the changes in our own app.
This commit is contained in:
Kyle Corbitt
2023-08-12 15:19:48 -07:00
parent 8d373ec9b5
commit 344b257db4
29 changed files with 876 additions and 1562 deletions

View File

@@ -6,7 +6,7 @@ const config = {
overrides: [
{
extends: ["plugin:@typescript-eslint/recommended-requiring-type-checking"],
files: ["*.ts", "*.tsx"],
files: ["*.mts", "*.ts", "*.tsx"],
parserOptions: {
project: path.join(__dirname, "tsconfig.json"),
},

View File

@@ -36,6 +36,8 @@ let config = {
});
return config;
},
transpilePackages: ["openpipe"],
};
config = nextRoutes()(config);

View File

@@ -1,5 +1,6 @@
{
"name": "openpipe",
"name": "openpipe-app",
"private": true,
"type": "module",
"version": "0.1.0",
"license": "Apache-2.0",
@@ -16,7 +17,7 @@
"postinstall": "prisma generate",
"lint": "next lint",
"start": "next start",
"codegen": "tsx src/server/scripts/client-codegen.ts",
"codegen:clients": "tsx src/server/scripts/client-codegen.ts",
"seed": "tsx prisma/seed.ts",
"check": "concurrently 'pnpm lint' 'pnpm tsc' 'pnpm prettier . --check'",
"test": "pnpm vitest"
@@ -99,7 +100,8 @@
"uuid": "^9.0.0",
"vite-tsconfig-paths": "^4.2.0",
"zod": "^3.21.4",
"zustand": "^4.3.9"
"zustand": "^4.3.9",
"openpipe": "workspace:*"
},
"devDependencies": {
"@openapi-contrib/openapi-schema-to-json-schema": "^4.0.5",

9160
app/pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,19 +4,18 @@ import fs from "fs";
import path from "path";
import { execSync } from "child_process";
console.log("Exporting public OpenAPI schema to client-libs/schema.json");
const scriptPath = import.meta.url.replace("file://", "");
const clientLibsPath = path.join(path.dirname(scriptPath), "../../../../client-libs");
const schemaPath = path.join(clientLibsPath, "schema.json");
const schemaPath = path.join(clientLibsPath, "openapi.json");
console.log(`Exporting public OpenAPI schema to ${schemaPath}`);
console.log("Exporting schema");
fs.writeFileSync(schemaPath, JSON.stringify(openApiDocument, null, 2), "utf-8");
console.log("Generating Typescript client");
console.log("Generating TypeScript client");
const tsClientPath = path.join(clientLibsPath, "typescript/codegen");
const tsClientPath = path.join(clientLibsPath, "typescript/src/codegen");
fs.rmSync(tsClientPath, { recursive: true, force: true });
@@ -27,6 +26,8 @@ execSync(
},
);
console.log("Done!");
console.log("Generating Python client");
process.exit(0);
execSync(path.join(clientLibsPath, "python/codegen.sh"));
console.log("Done!");

View File

@@ -1,12 +1,10 @@
import { type ClientOptions, default as OriginalOpenAI } from "openai";
import { type ClientOptions } from "openai";
import fs from "fs";
import path from "path";
import OpenAI from "openpipe/src/openai";
import { env } from "~/env.mjs";
// TODO: use local dependency
// import { OpenAI } from "openpipe";
let config: ClientOptions;
try {
@@ -23,4 +21,4 @@ try {
// export const openai = env.OPENPIPE_API_KEY ? new OpenAI.OpenAI(config) : new OriginalOpenAI(config);
export const openai = new OriginalOpenAI(config);
export const openai = new OpenAI(config);

View File

@@ -25,11 +25,11 @@
".eslintrc.cjs",
"next-env.d.ts",
"**/*.ts",
"**/*.mts",
"**/*.tsx",
"**/*.cjs",
"**/*.mjs",
"**/*.js",
"src/pages/api/sentry-example-api.js"
"**/*.js"
],
"exclude": ["node_modules"]
}