diff --git a/server/index.js b/server/index.js
index 8f418942..abb869e7 100644
--- a/server/index.js
+++ b/server/index.js
@@ -1,6 +1,6 @@
const express = require("express");
-const { createProxyMiddleware } = require("http-proxy-middleware");
+const { legacyCreateProxyMiddleware:createProxyMiddleware } = require("http-proxy-middleware");
require("dotenv").config();
const app = express();
const port = process.env.PORT || 4444; // default port 4444 for local development and 3000 for docker
@@ -15,7 +15,7 @@ app.get("/", function (req, res) {
const proxyOptions = {
target: `https://${process.env.endpoint}`,
changeOrigin: true,
- pathRewrite: { "^/v1/query": "/v1/query" },
+ pathRewrite: { "^/v1/query": "/v1/query", "^/v2/query": "/v2/query" },
onProxyReq: (proxyReq, req) => {
proxyReq.setHeader("Content-Type", "application/json");
proxyReq.setHeader("Accept", "application/json");
@@ -39,6 +39,7 @@ const proxyOptions = {
},
};
app.use("/v1/query", createProxyMiddleware(proxyOptions));
+app.use("/v2/query", createProxyMiddleware(proxyOptions));
app.post("/config", (req, res) => {
const {
diff --git a/src/contexts/apiV2sendSearchRequest.ts b/src/contexts/apiV2sendSearchRequest.ts
index 020298e7..f110c8c0 100644
--- a/src/contexts/apiV2sendSearchRequest.ts
+++ b/src/contexts/apiV2sendSearchRequest.ts
@@ -1,9 +1,9 @@
import {
SummaryLanguage,
QueryBody,
- QueryRequestHeaders,
ChainReranker,
} from "../views/search/types";
+import axios from "axios";
export type Reranker = {type: "none"}
| { type: "customer_reranker"; rerankerId: string }
@@ -213,26 +213,38 @@ export const apiV2sendSearchRequest = async ({
};
}
- const headers: QueryRequestHeaders = {
- "customer-id": customerId,
- "Content-Type": "application/json"
- };
-
- if (apiKey) headers["x-api-key"] = apiKey;
+ let headers = {};
+ let url = "";
+ if (process.env.NODE_ENV === "production") {
+ // Call proxy server if in production
+ url = `/v2/query`;
+ headers = {
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ },
+ };
+ } else {
+ // Call directly if in development
+ url = `https://${endpoint}/v2/query`;
+ headers = {
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ "customer-id": customerId,
+ "x-api-key": apiKey,
+ },
+ };
+ }
- const url = `https://${endpoint}/v2/query`;
- const response = await fetch(url, {
- method: "POST",
- headers: headers,
- body: JSON.stringify(body)
- });
+ const response = await axios.post(url, body, headers);
if (response.status === 400 || response.status === 403 || response.status === 404) {
- const result = await response.json();
+ const result = await response.data;
throw new Error(`BAD REQUEST: ${result?.messages[0] ?? result.field_errors}`);
}
if (response.status !== 200) throw new Error(response.status.toString());
- return await response.json()
+ return await response.data
};
diff --git a/src/contexts/sendSearchRequest.ts b/src/contexts/sendSearchRequest.ts
index 9548e030..9d6cd1f1 100644
--- a/src/contexts/sendSearchRequest.ts
+++ b/src/contexts/sendSearchRequest.ts
@@ -1,6 +1,6 @@
import axios from "axios";
import { START_TAG, END_TAG } from "../utils/parseSnippet";
-import { normal_reranker_id, slingshot_reranker_id, SummaryLanguage } from "../views/search/types";
+import { SummaryLanguage } from "../views/search/types";
type Reranker = {
isEnabled?: boolean,
@@ -65,14 +65,12 @@ const convertReranker = (reranker?: Reranker) => {
case "slingshot":
return {
reranker_name: "vectara-rrk-v1.0.0",
- reranker_id: slingshot_reranker_id,
...(index + 1 < rerankerNames.length && {next_reranking_config: buildRerankingConfig(index + 1)})
};
case "normal":
return {
reranker_name: "Rerank_Multilingual_v1",
- reranker_id: normal_reranker_id,
...(index + 1 < rerankerNames.length && {next_reranking_config: buildRerankingConfig(index + 1)})
};
@@ -83,7 +81,6 @@ const convertReranker = (reranker?: Reranker) => {
...(index + 1 < rerankerNames.length && {next_reranking_config: buildRerankingConfig(index + 1)})
};
- // Add other reranker types as needed
default:
return {}
}
diff --git a/src/views/search/SummaryUx.tsx b/src/views/search/SummaryUx.tsx
index 6aa07b14..3c1e775c 100644
--- a/src/views/search/SummaryUx.tsx
+++ b/src/views/search/SummaryUx.tsx
@@ -72,7 +72,7 @@ export const SummaryUx = () => {
- {(fcsMode !== "disable") && (
+ {(fcsMode !== "disable" && !isSummarizing) && (