mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-06-27 16:10:30 +08:00
Added the oasstApiClient global var and init
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import OasstApiClient from "src/lib/oasst_api_client";
|
||||
import { OasstApiClient } from "src/lib/oasst_api_client";
|
||||
|
||||
describe("Contract test for Oasst API", function () {
|
||||
// Assumes this is running the mock server.
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { JWT } from "next-auth/jwt";
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var oasstApiClient: OasstApiClient | undefined;
|
||||
}
|
||||
|
||||
class OasstError {
|
||||
message: string;
|
||||
errorCode: number;
|
||||
@@ -12,7 +17,7 @@ class OasstError {
|
||||
}
|
||||
}
|
||||
|
||||
export default class OasstApiClient {
|
||||
export class OasstApiClient {
|
||||
constructor(private readonly oasstApiUrl: string, private readonly oasstApiKey: string) {}
|
||||
|
||||
private async post(path: string, body: any): Promise<any> {
|
||||
@@ -85,3 +90,9 @@ export default class OasstApiClient {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const oasstApiClient =
|
||||
globalThis.oasstApiClient || new OasstApiClient(process.env.FASTAPI_URL, process.env.FASTAPI_KEY);
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
globalThis.oasstApiClient = oasstApiClient;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import OasstApiClient from "src/lib/oasst_api_client";
|
||||
import { oasstApiClient } from "src/lib/oasst_api_client";
|
||||
import prisma from "src/lib/prismadb";
|
||||
|
||||
/**
|
||||
@@ -21,8 +21,6 @@ const handler = async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const oasstApiClient = new OasstApiClient(process.env.FASTAPI_URL, process.env.FASTAPI_KEY);
|
||||
|
||||
// Fetch the new task.
|
||||
const task = await oasstApiClient.fetchTask(task_type, token);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import OasstApiClient from "src/lib/oasst_api_client";
|
||||
import { oasstApiClient } from "src/lib/oasst_api_client";
|
||||
import prisma from "src/lib/prismadb";
|
||||
|
||||
/**
|
||||
@@ -19,8 +19,6 @@ const handler = async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const oasstApiClient = new OasstApiClient(process.env.FASTAPI_URL, process.env.FASTAPI_KEY);
|
||||
|
||||
// Parse out the local task ID and the interaction contents.
|
||||
const { id, content, update_type } = await JSON.parse(req.body);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user