Update external types (#137)
* Separate server and frontend error logic * Update types in external api
This commit is contained in:
@@ -4,7 +4,7 @@ import { useEffect, useState } from "react";
|
|||||||
import { BsPencil, BsX } from "react-icons/bs";
|
import { BsPencil, BsX } from "react-icons/bs";
|
||||||
import { api } from "~/utils/api";
|
import { api } from "~/utils/api";
|
||||||
import { useExperiment, useHandledAsyncCallback, useScenarioVars } from "~/utils/hooks";
|
import { useExperiment, useHandledAsyncCallback, useScenarioVars } from "~/utils/hooks";
|
||||||
import { maybeReportError } from "~/utils/standardResponses";
|
import { maybeReportError } from "~/utils/errorHandling/maybeReportError";
|
||||||
import { FloatingLabelInput } from "./FloatingLabelInput";
|
import { FloatingLabelInput } from "./FloatingLabelInput";
|
||||||
|
|
||||||
export const ScenarioVar = ({
|
export const ScenarioVar = ({
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export const externalApiRouter = createTRPCRouter({
|
|||||||
})
|
})
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
startTime: z.number().describe("Unix timestamp in milliseconds"),
|
requestedAt: z.number().describe("Unix timestamp in milliseconds"),
|
||||||
reqPayload: z.unknown().describe("JSON-encoded request payload"),
|
reqPayload: z.unknown().describe("JSON-encoded request payload"),
|
||||||
tags: z
|
tags: z
|
||||||
.record(z.string())
|
.record(z.string())
|
||||||
@@ -85,7 +85,7 @@ export const externalApiRouter = createTRPCRouter({
|
|||||||
await prisma.loggedCall.create({
|
await prisma.loggedCall.create({
|
||||||
data: {
|
data: {
|
||||||
projectId: key.projectId,
|
projectId: key.projectId,
|
||||||
requestedAt: new Date(input.startTime),
|
requestedAt: new Date(input.requestedAt),
|
||||||
cacheHit: true,
|
cacheHit: true,
|
||||||
modelResponseId: existingResponse.id,
|
modelResponseId: existingResponse.id,
|
||||||
},
|
},
|
||||||
@@ -106,12 +106,12 @@ export const externalApiRouter = createTRPCRouter({
|
|||||||
})
|
})
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
startTime: z.number().describe("Unix timestamp in milliseconds"),
|
requestedAt: z.number().describe("Unix timestamp in milliseconds"),
|
||||||
endTime: z.number().describe("Unix timestamp in milliseconds"),
|
receivedAt: z.number().describe("Unix timestamp in milliseconds"),
|
||||||
reqPayload: z.unknown().describe("JSON-encoded request payload"),
|
reqPayload: z.unknown().describe("JSON-encoded request payload"),
|
||||||
respPayload: z.unknown().optional().describe("JSON-encoded response payload"),
|
respPayload: z.unknown().optional().describe("JSON-encoded response payload"),
|
||||||
respStatus: z.number().optional().describe("HTTP status code of response"),
|
statusCode: z.number().optional().describe("HTTP status code of response"),
|
||||||
error: z.string().optional().describe("User-friendly error message"),
|
errorMessage: z.string().optional().describe("User-friendly error message"),
|
||||||
tags: z
|
tags: z
|
||||||
.record(z.string())
|
.record(z.string())
|
||||||
.optional()
|
.optional()
|
||||||
@@ -153,7 +153,7 @@ export const externalApiRouter = createTRPCRouter({
|
|||||||
data: {
|
data: {
|
||||||
id: newLoggedCallId,
|
id: newLoggedCallId,
|
||||||
projectId: key.projectId,
|
projectId: key.projectId,
|
||||||
requestedAt: new Date(input.startTime),
|
requestedAt: new Date(input.requestedAt),
|
||||||
cacheHit: false,
|
cacheHit: false,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -161,13 +161,13 @@ export const externalApiRouter = createTRPCRouter({
|
|||||||
data: {
|
data: {
|
||||||
id: newModelResponseId,
|
id: newModelResponseId,
|
||||||
originalLoggedCallId: newLoggedCallId,
|
originalLoggedCallId: newLoggedCallId,
|
||||||
requestedAt: new Date(input.startTime),
|
requestedAt: new Date(input.requestedAt),
|
||||||
receivedAt: new Date(input.endTime),
|
receivedAt: new Date(input.receivedAt),
|
||||||
reqPayload: input.reqPayload as Prisma.InputJsonValue,
|
reqPayload: input.reqPayload as Prisma.InputJsonValue,
|
||||||
respPayload: input.respPayload as Prisma.InputJsonValue,
|
respPayload: input.respPayload as Prisma.InputJsonValue,
|
||||||
statusCode: input.respStatus,
|
statusCode: input.statusCode,
|
||||||
errorMessage: input.error,
|
errorMessage: input.errorMessage,
|
||||||
durationMs: input.endTime - input.startTime,
|
durationMs: input.receivedAt - input.requestedAt,
|
||||||
cacheKey: respPayload.success ? requestHash : null,
|
cacheKey: respPayload.success ? requestHash : null,
|
||||||
inputTokens: usage?.inputTokens,
|
inputTokens: usage?.inputTokens,
|
||||||
outputTokens: usage?.outputTokens,
|
outputTokens: usage?.outputTokens,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { createTRPCRouter, protectedProcedure, publicProcedure } from "~/server/
|
|||||||
import { prisma } from "~/server/db";
|
import { prisma } from "~/server/db";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import { generateNewCell } from "~/server/utils/generateNewCell";
|
import { generateNewCell } from "~/server/utils/generateNewCell";
|
||||||
import { error, success } from "~/utils/standardResponses";
|
import { error, success } from "~/utils/errorHandling/standardResponses";
|
||||||
import { recordExperimentUpdated } from "~/server/utils/recordExperimentUpdated";
|
import { recordExperimentUpdated } from "~/server/utils/recordExperimentUpdated";
|
||||||
import { reorderPromptVariants } from "~/server/utils/reorderPromptVariants";
|
import { reorderPromptVariants } from "~/server/utils/reorderPromptVariants";
|
||||||
import { type PromptVariant } from "@prisma/client";
|
import { type PromptVariant } from "@prisma/client";
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { sql } from "kysely";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { createTRPCRouter, protectedProcedure, publicProcedure } from "~/server/api/trpc";
|
import { createTRPCRouter, protectedProcedure, publicProcedure } from "~/server/api/trpc";
|
||||||
import { kysely, prisma } from "~/server/db";
|
import { kysely, prisma } from "~/server/db";
|
||||||
import { error, success } from "~/utils/standardResponses";
|
import { error, success } from "~/utils/errorHandling/standardResponses";
|
||||||
import { requireCanModifyExperiment, requireCanViewExperiment } from "~/utils/accessControl";
|
import { requireCanModifyExperiment, requireCanViewExperiment } from "~/utils/accessControl";
|
||||||
|
|
||||||
export const scenarioVarsRouter = createTRPCRouter({
|
export const scenarioVarsRouter = createTRPCRouter({
|
||||||
|
|||||||
@@ -1,16 +1,5 @@
|
|||||||
import { toast } from "~/theme/ChakraThemeProvider";
|
import { toast } from "~/theme/ChakraThemeProvider";
|
||||||
|
import { type error, type success } from "./standardResponses";
|
||||||
export function error(message: string): { status: "error"; message: string } {
|
|
||||||
return {
|
|
||||||
status: "error",
|
|
||||||
message,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
export function success<T>(payload: T): { status: "success"; payload: T };
|
|
||||||
export function success(payload?: undefined): { status: "success"; payload: undefined };
|
|
||||||
export function success<T>(payload?: T) {
|
|
||||||
return { status: "success", payload };
|
|
||||||
}
|
|
||||||
|
|
||||||
type SuccessType<T> = ReturnType<typeof success<T>>;
|
type SuccessType<T> = ReturnType<typeof success<T>>;
|
||||||
type ErrorType = ReturnType<typeof error>;
|
type ErrorType = ReturnType<typeof error>;
|
||||||
11
app/src/utils/errorHandling/standardResponses.ts
Normal file
11
app/src/utils/errorHandling/standardResponses.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
export function error(message: string): { status: "error"; message: string } {
|
||||||
|
return {
|
||||||
|
status: "error",
|
||||||
|
message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export function success<T>(payload: T): { status: "success"; payload: T };
|
||||||
|
export function success(payload?: undefined): { status: "success"; payload: undefined };
|
||||||
|
export function success<T>(payload?: T) {
|
||||||
|
return { status: "success", payload };
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"startTime": {
|
"requestedAt": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"description": "Unix timestamp in milliseconds"
|
"description": "Unix timestamp in milliseconds"
|
||||||
},
|
},
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"startTime"
|
"requestedAt"
|
||||||
],
|
],
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
}
|
}
|
||||||
@@ -80,11 +80,11 @@
|
|||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"startTime": {
|
"requestedAt": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"description": "Unix timestamp in milliseconds"
|
"description": "Unix timestamp in milliseconds"
|
||||||
},
|
},
|
||||||
"endTime": {
|
"receivedAt": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"description": "Unix timestamp in milliseconds"
|
"description": "Unix timestamp in milliseconds"
|
||||||
},
|
},
|
||||||
@@ -94,11 +94,11 @@
|
|||||||
"respPayload": {
|
"respPayload": {
|
||||||
"description": "JSON-encoded response payload"
|
"description": "JSON-encoded response payload"
|
||||||
},
|
},
|
||||||
"respStatus": {
|
"statusCode": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"description": "HTTP status code of response"
|
"description": "HTTP status code of response"
|
||||||
},
|
},
|
||||||
"error": {
|
"errorMessage": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "User-friendly error message"
|
"description": "User-friendly error message"
|
||||||
},
|
},
|
||||||
@@ -111,8 +111,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"startTime",
|
"requestedAt",
|
||||||
"endTime"
|
"receivedAt"
|
||||||
],
|
],
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,272 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
/**
|
|
||||||
* OpenPipe API
|
|
||||||
* The public API for reporting API calls to OpenPipe
|
|
||||||
*
|
|
||||||
* The version of the OpenAPI document: 0.1.0
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
||||||
* https://openapi-generator.tech
|
|
||||||
* Do not edit the class manually.
|
|
||||||
*/
|
|
||||||
var __extends = (this && this.__extends) || (function () {
|
|
||||||
var extendStatics = function (d, b) {
|
|
||||||
extendStatics = Object.setPrototypeOf ||
|
|
||||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
||||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
||||||
return extendStatics(d, b);
|
|
||||||
};
|
|
||||||
return function (d, b) {
|
|
||||||
if (typeof b !== "function" && b !== null)
|
|
||||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
||||||
extendStatics(d, b);
|
|
||||||
function __() { this.constructor = d; }
|
|
||||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
var __assign = (this && this.__assign) || function () {
|
|
||||||
__assign = Object.assign || function(t) {
|
|
||||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
||||||
s = arguments[i];
|
|
||||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
||||||
t[p] = s[p];
|
|
||||||
}
|
|
||||||
return t;
|
|
||||||
};
|
|
||||||
return __assign.apply(this, arguments);
|
|
||||||
};
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
||||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
||||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
||||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
||||||
function step(op) {
|
|
||||||
if (f) throw new TypeError("Generator is already executing.");
|
|
||||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
||||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
||||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
||||||
switch (op[0]) {
|
|
||||||
case 0: case 1: t = op; break;
|
|
||||||
case 4: _.label++; return { value: op[1], done: false };
|
|
||||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
||||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
||||||
default:
|
|
||||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
||||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
||||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
||||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
||||||
if (t[2]) _.ops.pop();
|
|
||||||
_.trys.pop(); continue;
|
|
||||||
}
|
|
||||||
op = body.call(thisArg, _);
|
|
||||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
||||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
exports.DefaultApi = exports.DefaultApiFactory = exports.DefaultApiFp = exports.DefaultApiAxiosParamCreator = void 0;
|
|
||||||
var axios_1 = require("axios");
|
|
||||||
// Some imports not used depending on template conditions
|
|
||||||
// @ts-ignore
|
|
||||||
var common_1 = require("./common");
|
|
||||||
// @ts-ignore
|
|
||||||
var base_1 = require("./base");
|
|
||||||
/**
|
|
||||||
* DefaultApi - axios parameter creator
|
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
var DefaultApiAxiosParamCreator = function (configuration) {
|
|
||||||
var _this = this;
|
|
||||||
return {
|
|
||||||
/**
|
|
||||||
* Check if a prompt is cached
|
|
||||||
* @param {ExternalApiCheckCacheRequest} externalApiCheckCacheRequest
|
|
||||||
* @param {*} [options] Override http request option.
|
|
||||||
* @throws {RequiredError}
|
|
||||||
*/
|
|
||||||
externalApiCheckCache: function (externalApiCheckCacheRequest, options) {
|
|
||||||
if (options === void 0) { options = {}; }
|
|
||||||
return __awaiter(_this, void 0, void 0, function () {
|
|
||||||
var localVarPath, localVarUrlObj, baseOptions, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, headersFromBaseOptions;
|
|
||||||
return __generator(this, function (_a) {
|
|
||||||
// verify required parameter 'externalApiCheckCacheRequest' is not null or undefined
|
|
||||||
(0, common_1.assertParamExists)('externalApiCheckCache', 'externalApiCheckCacheRequest', externalApiCheckCacheRequest);
|
|
||||||
localVarPath = "/v1/check-cache";
|
|
||||||
localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
|
|
||||||
if (configuration) {
|
|
||||||
baseOptions = configuration.baseOptions;
|
|
||||||
}
|
|
||||||
localVarRequestOptions = __assign(__assign({ method: 'POST' }, baseOptions), options);
|
|
||||||
localVarHeaderParameter = {};
|
|
||||||
localVarQueryParameter = {};
|
|
||||||
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
||||||
(0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
|
|
||||||
headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
||||||
localVarRequestOptions.headers = __assign(__assign(__assign({}, localVarHeaderParameter), headersFromBaseOptions), options.headers);
|
|
||||||
localVarRequestOptions.data = (0, common_1.serializeDataIfNeeded)(externalApiCheckCacheRequest, localVarRequestOptions, configuration);
|
|
||||||
return [2 /*return*/, {
|
|
||||||
url: (0, common_1.toPathString)(localVarUrlObj),
|
|
||||||
options: localVarRequestOptions,
|
|
||||||
}];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Report an API call
|
|
||||||
* @param {ExternalApiReportRequest} externalApiReportRequest
|
|
||||||
* @param {*} [options] Override http request option.
|
|
||||||
* @throws {RequiredError}
|
|
||||||
*/
|
|
||||||
externalApiReport: function (externalApiReportRequest, options) {
|
|
||||||
if (options === void 0) { options = {}; }
|
|
||||||
return __awaiter(_this, void 0, void 0, function () {
|
|
||||||
var localVarPath, localVarUrlObj, baseOptions, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, headersFromBaseOptions;
|
|
||||||
return __generator(this, function (_a) {
|
|
||||||
// verify required parameter 'externalApiReportRequest' is not null or undefined
|
|
||||||
(0, common_1.assertParamExists)('externalApiReport', 'externalApiReportRequest', externalApiReportRequest);
|
|
||||||
localVarPath = "/v1/report";
|
|
||||||
localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
|
|
||||||
if (configuration) {
|
|
||||||
baseOptions = configuration.baseOptions;
|
|
||||||
}
|
|
||||||
localVarRequestOptions = __assign(__assign({ method: 'POST' }, baseOptions), options);
|
|
||||||
localVarHeaderParameter = {};
|
|
||||||
localVarQueryParameter = {};
|
|
||||||
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
||||||
(0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
|
|
||||||
headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
||||||
localVarRequestOptions.headers = __assign(__assign(__assign({}, localVarHeaderParameter), headersFromBaseOptions), options.headers);
|
|
||||||
localVarRequestOptions.data = (0, common_1.serializeDataIfNeeded)(externalApiReportRequest, localVarRequestOptions, configuration);
|
|
||||||
return [2 /*return*/, {
|
|
||||||
url: (0, common_1.toPathString)(localVarUrlObj),
|
|
||||||
options: localVarRequestOptions,
|
|
||||||
}];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
exports.DefaultApiAxiosParamCreator = DefaultApiAxiosParamCreator;
|
|
||||||
/**
|
|
||||||
* DefaultApi - functional programming interface
|
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
var DefaultApiFp = function (configuration) {
|
|
||||||
var localVarAxiosParamCreator = (0, exports.DefaultApiAxiosParamCreator)(configuration);
|
|
||||||
return {
|
|
||||||
/**
|
|
||||||
* Check if a prompt is cached
|
|
||||||
* @param {ExternalApiCheckCacheRequest} externalApiCheckCacheRequest
|
|
||||||
* @param {*} [options] Override http request option.
|
|
||||||
* @throws {RequiredError}
|
|
||||||
*/
|
|
||||||
externalApiCheckCache: function (externalApiCheckCacheRequest, options) {
|
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
|
||||||
var localVarAxiosArgs;
|
|
||||||
return __generator(this, function (_a) {
|
|
||||||
switch (_a.label) {
|
|
||||||
case 0: return [4 /*yield*/, localVarAxiosParamCreator.externalApiCheckCache(externalApiCheckCacheRequest, options)];
|
|
||||||
case 1:
|
|
||||||
localVarAxiosArgs = _a.sent();
|
|
||||||
return [2 /*return*/, (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration)];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Report an API call
|
|
||||||
* @param {ExternalApiReportRequest} externalApiReportRequest
|
|
||||||
* @param {*} [options] Override http request option.
|
|
||||||
* @throws {RequiredError}
|
|
||||||
*/
|
|
||||||
externalApiReport: function (externalApiReportRequest, options) {
|
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
|
||||||
var localVarAxiosArgs;
|
|
||||||
return __generator(this, function (_a) {
|
|
||||||
switch (_a.label) {
|
|
||||||
case 0: return [4 /*yield*/, localVarAxiosParamCreator.externalApiReport(externalApiReportRequest, options)];
|
|
||||||
case 1:
|
|
||||||
localVarAxiosArgs = _a.sent();
|
|
||||||
return [2 /*return*/, (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration)];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
exports.DefaultApiFp = DefaultApiFp;
|
|
||||||
/**
|
|
||||||
* DefaultApi - factory interface
|
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
var DefaultApiFactory = function (configuration, basePath, axios) {
|
|
||||||
var localVarFp = (0, exports.DefaultApiFp)(configuration);
|
|
||||||
return {
|
|
||||||
/**
|
|
||||||
* Check if a prompt is cached
|
|
||||||
* @param {ExternalApiCheckCacheRequest} externalApiCheckCacheRequest
|
|
||||||
* @param {*} [options] Override http request option.
|
|
||||||
* @throws {RequiredError}
|
|
||||||
*/
|
|
||||||
externalApiCheckCache: function (externalApiCheckCacheRequest, options) {
|
|
||||||
return localVarFp.externalApiCheckCache(externalApiCheckCacheRequest, options).then(function (request) { return request(axios, basePath); });
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Report an API call
|
|
||||||
* @param {ExternalApiReportRequest} externalApiReportRequest
|
|
||||||
* @param {*} [options] Override http request option.
|
|
||||||
* @throws {RequiredError}
|
|
||||||
*/
|
|
||||||
externalApiReport: function (externalApiReportRequest, options) {
|
|
||||||
return localVarFp.externalApiReport(externalApiReportRequest, options).then(function (request) { return request(axios, basePath); });
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
exports.DefaultApiFactory = DefaultApiFactory;
|
|
||||||
/**
|
|
||||||
* DefaultApi - object-oriented interface
|
|
||||||
* @export
|
|
||||||
* @class DefaultApi
|
|
||||||
* @extends {BaseAPI}
|
|
||||||
*/
|
|
||||||
var DefaultApi = /** @class */ (function (_super) {
|
|
||||||
__extends(DefaultApi, _super);
|
|
||||||
function DefaultApi() {
|
|
||||||
return _super !== null && _super.apply(this, arguments) || this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Check if a prompt is cached
|
|
||||||
* @param {ExternalApiCheckCacheRequest} externalApiCheckCacheRequest
|
|
||||||
* @param {*} [options] Override http request option.
|
|
||||||
* @throws {RequiredError}
|
|
||||||
* @memberof DefaultApi
|
|
||||||
*/
|
|
||||||
DefaultApi.prototype.externalApiCheckCache = function (externalApiCheckCacheRequest, options) {
|
|
||||||
var _this = this;
|
|
||||||
return (0, exports.DefaultApiFp)(this.configuration).externalApiCheckCache(externalApiCheckCacheRequest, options).then(function (request) { return request(_this.axios, _this.basePath); });
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* Report an API call
|
|
||||||
* @param {ExternalApiReportRequest} externalApiReportRequest
|
|
||||||
* @param {*} [options] Override http request option.
|
|
||||||
* @throws {RequiredError}
|
|
||||||
* @memberof DefaultApi
|
|
||||||
*/
|
|
||||||
DefaultApi.prototype.externalApiReport = function (externalApiReportRequest, options) {
|
|
||||||
var _this = this;
|
|
||||||
return (0, exports.DefaultApiFp)(this.configuration).externalApiReport(externalApiReportRequest, options).then(function (request) { return request(_this.axios, _this.basePath); });
|
|
||||||
};
|
|
||||||
return DefaultApi;
|
|
||||||
}(base_1.BaseAPI));
|
|
||||||
exports.DefaultApi = DefaultApi;
|
|
||||||
@@ -85,7 +85,7 @@ export interface ExternalApiCheckCacheRequest {
|
|||||||
* @type {number}
|
* @type {number}
|
||||||
* @memberof ExternalApiCheckCacheRequest
|
* @memberof ExternalApiCheckCacheRequest
|
||||||
*/
|
*/
|
||||||
'startTime': number;
|
'requestedAt': number;
|
||||||
/**
|
/**
|
||||||
* JSON-encoded request payload
|
* JSON-encoded request payload
|
||||||
* @type {any}
|
* @type {any}
|
||||||
@@ -110,13 +110,13 @@ export interface ExternalApiReportRequest {
|
|||||||
* @type {number}
|
* @type {number}
|
||||||
* @memberof ExternalApiReportRequest
|
* @memberof ExternalApiReportRequest
|
||||||
*/
|
*/
|
||||||
'startTime': number;
|
'requestedAt': number;
|
||||||
/**
|
/**
|
||||||
* Unix timestamp in milliseconds
|
* Unix timestamp in milliseconds
|
||||||
* @type {number}
|
* @type {number}
|
||||||
* @memberof ExternalApiReportRequest
|
* @memberof ExternalApiReportRequest
|
||||||
*/
|
*/
|
||||||
'endTime': number;
|
'receivedAt': number;
|
||||||
/**
|
/**
|
||||||
* JSON-encoded request payload
|
* JSON-encoded request payload
|
||||||
* @type {any}
|
* @type {any}
|
||||||
@@ -134,13 +134,13 @@ export interface ExternalApiReportRequest {
|
|||||||
* @type {number}
|
* @type {number}
|
||||||
* @memberof ExternalApiReportRequest
|
* @memberof ExternalApiReportRequest
|
||||||
*/
|
*/
|
||||||
'respStatus'?: number;
|
'statusCode'?: number;
|
||||||
/**
|
/**
|
||||||
* User-friendly error message
|
* User-friendly error message
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof ExternalApiReportRequest
|
* @memberof ExternalApiReportRequest
|
||||||
*/
|
*/
|
||||||
'error'?: string;
|
'errorMessage'?: string;
|
||||||
/**
|
/**
|
||||||
* Extra tags to attach to the call for filtering. Eg { \"userId\": \"123\", \"promptId\": \"populate-title\" }
|
* Extra tags to attach to the call for filtering. Eg { \"userId\": \"123\", \"promptId\": \"populate-title\" }
|
||||||
* @type {{ [key: string]: string; }}
|
* @type {{ [key: string]: string; }}
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
/**
|
|
||||||
* OpenPipe API
|
|
||||||
* The public API for reporting API calls to OpenPipe
|
|
||||||
*
|
|
||||||
* The version of the OpenAPI document: 0.1.0
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
||||||
* https://openapi-generator.tech
|
|
||||||
* Do not edit the class manually.
|
|
||||||
*/
|
|
||||||
var __extends = (this && this.__extends) || (function () {
|
|
||||||
var extendStatics = function (d, b) {
|
|
||||||
extendStatics = Object.setPrototypeOf ||
|
|
||||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
||||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
||||||
return extendStatics(d, b);
|
|
||||||
};
|
|
||||||
return function (d, b) {
|
|
||||||
if (typeof b !== "function" && b !== null)
|
|
||||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
||||||
extendStatics(d, b);
|
|
||||||
function __() { this.constructor = d; }
|
|
||||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
exports.RequiredError = exports.BaseAPI = exports.COLLECTION_FORMATS = exports.BASE_PATH = void 0;
|
|
||||||
var axios_1 = require("axios");
|
|
||||||
exports.BASE_PATH = "https://app.openpipe.ai/api".replace(/\/+$/, "");
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
exports.COLLECTION_FORMATS = {
|
|
||||||
csv: ",",
|
|
||||||
ssv: " ",
|
|
||||||
tsv: "\t",
|
|
||||||
pipes: "|",
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @export
|
|
||||||
* @class BaseAPI
|
|
||||||
*/
|
|
||||||
var BaseAPI = /** @class */ (function () {
|
|
||||||
function BaseAPI(configuration, basePath, axios) {
|
|
||||||
if (basePath === void 0) { basePath = exports.BASE_PATH; }
|
|
||||||
if (axios === void 0) { axios = axios_1.default; }
|
|
||||||
this.basePath = basePath;
|
|
||||||
this.axios = axios;
|
|
||||||
if (configuration) {
|
|
||||||
this.configuration = configuration;
|
|
||||||
this.basePath = configuration.basePath || this.basePath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return BaseAPI;
|
|
||||||
}());
|
|
||||||
exports.BaseAPI = BaseAPI;
|
|
||||||
;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @export
|
|
||||||
* @class RequiredError
|
|
||||||
* @extends {Error}
|
|
||||||
*/
|
|
||||||
var RequiredError = /** @class */ (function (_super) {
|
|
||||||
__extends(RequiredError, _super);
|
|
||||||
function RequiredError(field, msg) {
|
|
||||||
var _this = _super.call(this, msg) || this;
|
|
||||||
_this.field = field;
|
|
||||||
_this.name = "RequiredError";
|
|
||||||
return _this;
|
|
||||||
}
|
|
||||||
return RequiredError;
|
|
||||||
}(Error));
|
|
||||||
exports.RequiredError = RequiredError;
|
|
||||||
@@ -1,252 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
/**
|
|
||||||
* OpenPipe API
|
|
||||||
* The public API for reporting API calls to OpenPipe
|
|
||||||
*
|
|
||||||
* The version of the OpenAPI document: 0.1.0
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
||||||
* https://openapi-generator.tech
|
|
||||||
* Do not edit the class manually.
|
|
||||||
*/
|
|
||||||
var __assign = (this && this.__assign) || function () {
|
|
||||||
__assign = Object.assign || function(t) {
|
|
||||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
||||||
s = arguments[i];
|
|
||||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
||||||
t[p] = s[p];
|
|
||||||
}
|
|
||||||
return t;
|
|
||||||
};
|
|
||||||
return __assign.apply(this, arguments);
|
|
||||||
};
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
||||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
||||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
||||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
||||||
function step(op) {
|
|
||||||
if (f) throw new TypeError("Generator is already executing.");
|
|
||||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
||||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
||||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
||||||
switch (op[0]) {
|
|
||||||
case 0: case 1: t = op; break;
|
|
||||||
case 4: _.label++; return { value: op[1], done: false };
|
|
||||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
||||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
||||||
default:
|
|
||||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
||||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
||||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
||||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
||||||
if (t[2]) _.ops.pop();
|
|
||||||
_.trys.pop(); continue;
|
|
||||||
}
|
|
||||||
op = body.call(thisArg, _);
|
|
||||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
||||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
exports.createRequestFunction = exports.toPathString = exports.serializeDataIfNeeded = exports.setSearchParams = exports.setOAuthToObject = exports.setBearerAuthToObject = exports.setBasicAuthToObject = exports.setApiKeyToObject = exports.assertParamExists = exports.DUMMY_BASE_URL = void 0;
|
|
||||||
var base_1 = require("./base");
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
exports.DUMMY_BASE_URL = 'https://example.com';
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @throws {RequiredError}
|
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
var assertParamExists = function (functionName, paramName, paramValue) {
|
|
||||||
if (paramValue === null || paramValue === undefined) {
|
|
||||||
throw new base_1.RequiredError(paramName, "Required parameter ".concat(paramName, " was null or undefined when calling ").concat(functionName, "."));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
exports.assertParamExists = assertParamExists;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
var setApiKeyToObject = function (object, keyParamName, configuration) {
|
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
|
||||||
var localVarApiKeyValue, _a;
|
|
||||||
return __generator(this, function (_b) {
|
|
||||||
switch (_b.label) {
|
|
||||||
case 0:
|
|
||||||
if (!(configuration && configuration.apiKey)) return [3 /*break*/, 5];
|
|
||||||
if (!(typeof configuration.apiKey === 'function')) return [3 /*break*/, 2];
|
|
||||||
return [4 /*yield*/, configuration.apiKey(keyParamName)];
|
|
||||||
case 1:
|
|
||||||
_a = _b.sent();
|
|
||||||
return [3 /*break*/, 4];
|
|
||||||
case 2: return [4 /*yield*/, configuration.apiKey];
|
|
||||||
case 3:
|
|
||||||
_a = _b.sent();
|
|
||||||
_b.label = 4;
|
|
||||||
case 4:
|
|
||||||
localVarApiKeyValue = _a;
|
|
||||||
object[keyParamName] = localVarApiKeyValue;
|
|
||||||
_b.label = 5;
|
|
||||||
case 5: return [2 /*return*/];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
exports.setApiKeyToObject = setApiKeyToObject;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
var setBasicAuthToObject = function (object, configuration) {
|
|
||||||
if (configuration && (configuration.username || configuration.password)) {
|
|
||||||
object["auth"] = { username: configuration.username, password: configuration.password };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
exports.setBasicAuthToObject = setBasicAuthToObject;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
var setBearerAuthToObject = function (object, configuration) {
|
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
|
||||||
var accessToken, _a;
|
|
||||||
return __generator(this, function (_b) {
|
|
||||||
switch (_b.label) {
|
|
||||||
case 0:
|
|
||||||
if (!(configuration && configuration.accessToken)) return [3 /*break*/, 5];
|
|
||||||
if (!(typeof configuration.accessToken === 'function')) return [3 /*break*/, 2];
|
|
||||||
return [4 /*yield*/, configuration.accessToken()];
|
|
||||||
case 1:
|
|
||||||
_a = _b.sent();
|
|
||||||
return [3 /*break*/, 4];
|
|
||||||
case 2: return [4 /*yield*/, configuration.accessToken];
|
|
||||||
case 3:
|
|
||||||
_a = _b.sent();
|
|
||||||
_b.label = 4;
|
|
||||||
case 4:
|
|
||||||
accessToken = _a;
|
|
||||||
object["Authorization"] = "Bearer " + accessToken;
|
|
||||||
_b.label = 5;
|
|
||||||
case 5: return [2 /*return*/];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
exports.setBearerAuthToObject = setBearerAuthToObject;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
var setOAuthToObject = function (object, name, scopes, configuration) {
|
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
|
||||||
var localVarAccessTokenValue, _a;
|
|
||||||
return __generator(this, function (_b) {
|
|
||||||
switch (_b.label) {
|
|
||||||
case 0:
|
|
||||||
if (!(configuration && configuration.accessToken)) return [3 /*break*/, 5];
|
|
||||||
if (!(typeof configuration.accessToken === 'function')) return [3 /*break*/, 2];
|
|
||||||
return [4 /*yield*/, configuration.accessToken(name, scopes)];
|
|
||||||
case 1:
|
|
||||||
_a = _b.sent();
|
|
||||||
return [3 /*break*/, 4];
|
|
||||||
case 2: return [4 /*yield*/, configuration.accessToken];
|
|
||||||
case 3:
|
|
||||||
_a = _b.sent();
|
|
||||||
_b.label = 4;
|
|
||||||
case 4:
|
|
||||||
localVarAccessTokenValue = _a;
|
|
||||||
object["Authorization"] = "Bearer " + localVarAccessTokenValue;
|
|
||||||
_b.label = 5;
|
|
||||||
case 5: return [2 /*return*/];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
exports.setOAuthToObject = setOAuthToObject;
|
|
||||||
function setFlattenedQueryParams(urlSearchParams, parameter, key) {
|
|
||||||
if (key === void 0) { key = ""; }
|
|
||||||
if (parameter == null)
|
|
||||||
return;
|
|
||||||
if (typeof parameter === "object") {
|
|
||||||
if (Array.isArray(parameter)) {
|
|
||||||
parameter.forEach(function (item) { return setFlattenedQueryParams(urlSearchParams, item, key); });
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Object.keys(parameter).forEach(function (currentKey) {
|
|
||||||
return setFlattenedQueryParams(urlSearchParams, parameter[currentKey], "".concat(key).concat(key !== '' ? '.' : '').concat(currentKey));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (urlSearchParams.has(key)) {
|
|
||||||
urlSearchParams.append(key, parameter);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
urlSearchParams.set(key, parameter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
var setSearchParams = function (url) {
|
|
||||||
var objects = [];
|
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
|
||||||
objects[_i - 1] = arguments[_i];
|
|
||||||
}
|
|
||||||
var searchParams = new URLSearchParams(url.search);
|
|
||||||
setFlattenedQueryParams(searchParams, objects);
|
|
||||||
url.search = searchParams.toString();
|
|
||||||
};
|
|
||||||
exports.setSearchParams = setSearchParams;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
var serializeDataIfNeeded = function (value, requestOptions, configuration) {
|
|
||||||
var nonString = typeof value !== 'string';
|
|
||||||
var needsSerialization = nonString && configuration && configuration.isJsonMime
|
|
||||||
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
|
|
||||||
: nonString;
|
|
||||||
return needsSerialization
|
|
||||||
? JSON.stringify(value !== undefined ? value : {})
|
|
||||||
: (value || "");
|
|
||||||
};
|
|
||||||
exports.serializeDataIfNeeded = serializeDataIfNeeded;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
var toPathString = function (url) {
|
|
||||||
return url.pathname + url.search + url.hash;
|
|
||||||
};
|
|
||||||
exports.toPathString = toPathString;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
var createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, configuration) {
|
|
||||||
return function (axios, basePath) {
|
|
||||||
if (axios === void 0) { axios = globalAxios; }
|
|
||||||
if (basePath === void 0) { basePath = BASE_PATH; }
|
|
||||||
var axiosRequestArgs = __assign(__assign({}, axiosArgs.options), { url: ((configuration === null || configuration === void 0 ? void 0 : configuration.basePath) || basePath) + axiosArgs.url });
|
|
||||||
return axios.request(axiosRequestArgs);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
exports.createRequestFunction = createRequestFunction;
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
/**
|
|
||||||
* OpenPipe API
|
|
||||||
* The public API for reporting API calls to OpenPipe
|
|
||||||
*
|
|
||||||
* The version of the OpenAPI document: 0.1.0
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
||||||
* https://openapi-generator.tech
|
|
||||||
* Do not edit the class manually.
|
|
||||||
*/
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
exports.Configuration = void 0;
|
|
||||||
var Configuration = /** @class */ (function () {
|
|
||||||
function Configuration(param) {
|
|
||||||
if (param === void 0) { param = {}; }
|
|
||||||
this.apiKey = param.apiKey;
|
|
||||||
this.username = param.username;
|
|
||||||
this.password = param.password;
|
|
||||||
this.accessToken = param.accessToken;
|
|
||||||
this.basePath = param.basePath;
|
|
||||||
this.baseOptions = param.baseOptions;
|
|
||||||
this.formDataCtor = param.formDataCtor;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Check if the given MIME is a JSON MIME.
|
|
||||||
* JSON MIME examples:
|
|
||||||
* application/json
|
|
||||||
* application/json; charset=UTF8
|
|
||||||
* APPLICATION/JSON
|
|
||||||
* application/vnd.company+json
|
|
||||||
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
|
||||||
* @return True if the given MIME is JSON, false otherwise.
|
|
||||||
*/
|
|
||||||
Configuration.prototype.isJsonMime = function (mime) {
|
|
||||||
var jsonMime = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
|
|
||||||
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
|
|
||||||
};
|
|
||||||
return Configuration;
|
|
||||||
}());
|
|
||||||
exports.Configuration = Configuration;
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
/**
|
|
||||||
* OpenPipe API
|
|
||||||
* The public API for reporting API calls to OpenPipe
|
|
||||||
*
|
|
||||||
* The version of the OpenAPI document: 0.1.0
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
||||||
* https://openapi-generator.tech
|
|
||||||
* Do not edit the class manually.
|
|
||||||
*/
|
|
||||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
||||||
if (k2 === undefined) k2 = k;
|
|
||||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
||||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
||||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
||||||
}
|
|
||||||
Object.defineProperty(o, k2, desc);
|
|
||||||
}) : (function(o, m, k, k2) {
|
|
||||||
if (k2 === undefined) k2 = k;
|
|
||||||
o[k2] = m[k];
|
|
||||||
}));
|
|
||||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
||||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
__exportStar(require("./api"), exports);
|
|
||||||
__exportStar(require("./configuration"), exports);
|
|
||||||
@@ -13,7 +13,11 @@ type OPConfigurationParameters = {
|
|||||||
export class Configuration extends openai.Configuration {
|
export class Configuration extends openai.Configuration {
|
||||||
public qkConfig?: openPipeClient.Configuration;
|
public qkConfig?: openPipeClient.Configuration;
|
||||||
|
|
||||||
constructor(config: openai.ConfigurationParameters & { opParameters?: OPConfigurationParameters }) {
|
constructor(
|
||||||
|
config: openai.ConfigurationParameters & {
|
||||||
|
opParameters?: OPConfigurationParameters;
|
||||||
|
}
|
||||||
|
) {
|
||||||
super(config);
|
super(config);
|
||||||
if (config.opParameters) {
|
if (config.opParameters) {
|
||||||
this.qkConfig = new openPipeClient.Configuration(config.opParameters);
|
this.qkConfig = new openPipeClient.Configuration(config.opParameters);
|
||||||
@@ -21,7 +25,9 @@ export class Configuration extends openai.Configuration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateChatCompletion = InstanceType<typeof openai.OpenAIApi>["createChatCompletion"];
|
type CreateChatCompletion = InstanceType<
|
||||||
|
typeof openai.OpenAIApi
|
||||||
|
>["createChatCompletion"];
|
||||||
|
|
||||||
export class OpenAIApi extends openai.OpenAIApi {
|
export class OpenAIApi extends openai.OpenAIApi {
|
||||||
public openPipeApi?: openPipeClient.DefaultApi;
|
public openPipeApi?: openPipeClient.DefaultApi;
|
||||||
@@ -37,41 +43,44 @@ export class OpenAIApi extends openai.OpenAIApi {
|
|||||||
createChatCompletionRequest: Parameters<CreateChatCompletion>[0],
|
createChatCompletionRequest: Parameters<CreateChatCompletion>[0],
|
||||||
options?: Parameters<CreateChatCompletion>[1]
|
options?: Parameters<CreateChatCompletion>[1]
|
||||||
): ReturnType<CreateChatCompletion> {
|
): ReturnType<CreateChatCompletion> {
|
||||||
const startTime = Date.now();
|
const requestedAt = Date.now();
|
||||||
let resp: Awaited<ReturnType<CreateChatCompletion>> | null = null;
|
let resp: Awaited<ReturnType<CreateChatCompletion>> | null = null;
|
||||||
let respPayload: openai.CreateChatCompletionResponse | null = null;
|
let respPayload: openai.CreateChatCompletionResponse | null = null;
|
||||||
let respStatus: number | undefined = undefined;
|
let statusCode: number | undefined = undefined;
|
||||||
let error: string | undefined;
|
let errorMessage: string | undefined;
|
||||||
try {
|
try {
|
||||||
resp = await super.createChatCompletion(createChatCompletionRequest, options);
|
resp = await super.createChatCompletion(
|
||||||
|
createChatCompletionRequest,
|
||||||
|
options
|
||||||
|
);
|
||||||
respPayload = resp.data;
|
respPayload = resp.data;
|
||||||
respStatus = resp.status;
|
statusCode = resp.status;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error in createChatCompletion");
|
console.error("Error in createChatCompletion");
|
||||||
if ("isAxiosError" in err && err.isAxiosError) {
|
if ("isAxiosError" in err && err.isAxiosError) {
|
||||||
error = err.response?.data?.error?.message;
|
errorMessage = err.response?.data?.error?.message;
|
||||||
respPayload = err.response?.data;
|
respPayload = err.response?.data;
|
||||||
respStatus = err.response?.status;
|
statusCode = err.response?.status;
|
||||||
} else if ("message" in err) {
|
} else if ("message" in err) {
|
||||||
error = err.message.toString();
|
errorMessage = err.message.toString();
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
this.openPipeApi
|
this.openPipeApi
|
||||||
?.externalApiReport({
|
?.externalApiReport({
|
||||||
startTime,
|
requestedAt,
|
||||||
endTime: Date.now(),
|
receivedAt: Date.now(),
|
||||||
reqPayload: createChatCompletionRequest,
|
reqPayload: createChatCompletionRequest,
|
||||||
respPayload: respPayload,
|
respPayload: respPayload,
|
||||||
respStatus: respStatus,
|
statusCode: statusCode,
|
||||||
error,
|
errorMessage,
|
||||||
tags: {
|
tags: {
|
||||||
client: "openai-js",
|
client: "openai-js",
|
||||||
clientVersion: version,
|
clientVersion: version,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error("Error reporting to QK", err);
|
console.error("Error reporting to OP", err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export class OpenAI extends openai.OpenAI {
|
|||||||
const axiosInstance = axios.create({
|
const axiosInstance = axios.create({
|
||||||
baseURL: openPipeBaseUrl,
|
baseURL: openPipeBaseUrl,
|
||||||
headers: {
|
headers: {
|
||||||
'x-openpipe-api-key': openPipeApiKey,
|
"x-openpipe-api-key": openPipeApiKey,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.openPipeApi = new openPipeClient.DefaultApi(
|
this.openPipeApi = new openPipeClient.DefaultApi(
|
||||||
@@ -88,18 +88,18 @@ class ExtendedCompletions extends openai.OpenAI.Chat.Completions {
|
|||||||
console.log("Doing post API call for Streaming...");
|
console.log("Doing post API call for Streaming...");
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
const startTime = Date.now();
|
const requestedAt = Date.now();
|
||||||
const result = await super.create(
|
const result = await super.create(
|
||||||
params as CompletionCreateParams.CreateChatCompletionRequestNonStreaming,
|
params as CompletionCreateParams.CreateChatCompletionRequestNonStreaming,
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
await this.openaiInstance.openPipeApi?.externalApiReport({
|
await this.openaiInstance.openPipeApi?.externalApiReport({
|
||||||
startTime,
|
requestedAt,
|
||||||
endTime: Date.now(),
|
receivedAt: Date.now(),
|
||||||
reqPayload: params,
|
reqPayload: params,
|
||||||
respPayload: result,
|
respPayload: result,
|
||||||
respStatus: 200,
|
statusCode: 200,
|
||||||
error: undefined,
|
errorMessage: undefined,
|
||||||
tags,
|
tags,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user