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

fixed FCS and added param for proxy server URL #187

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
23 changes: 18 additions & 5 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,45 @@ const proxyOptions = {
pathRewrite: { "^/v1/query": "/v1/query", "^/v2/query": "/v2/query" },
onProxyReq: (proxyReq, req) => {
proxyReq.setHeader("Content-Type", "application/json");
proxyReq.setHeader("Accept", "application/json");
proxyReq.setHeader("Accept", "text/event-stream");
proxyReq.setHeader("customer-id", process.env.customer_id);
proxyReq.setHeader("x-api-key", process.env.api_key);
proxyReq.setHeader("grpc-timeout", "60S");
proxyReq.setHeader("X-Source", "vectara-answer");

if (req.body.logQuery) {
// Accessing the domain name from the request headers
if (req.body && req.body.logQuery) {
const hostHeader = req.headers.host;
console.log(`${hostHeader} - user query: `, req.body.query[0].query)
console.log(`${hostHeader} - user query: `, req.body.query[0].query);
}

if (req.body) {
delete req.body.logQuery // remove the logQuery flag from request body
delete req.body.logQuery; // Remove the logQuery flag from request body
const bodyData = JSON.stringify(req.body);
proxyReq.setHeader("Content-Length", Buffer.byteLength(bodyData));
proxyReq.write(bodyData);
}
},
selfHandleResponse: true,
onProxyRes: (proxyRes, req, res) => {
res.setHeader("Content-Type", "text/event-stream");
res.setHeader("Transfer-Encoding", "chunked");

proxyRes.pipe(res);
proxyRes.on("error", (error) => {
console.error("Stream error:", error);
res.status(res.status).send(error);
});
},
};

app.use("/v1/query", createProxyMiddleware(proxyOptions));
app.use("/v2/query", createProxyMiddleware(proxyOptions));

app.post("/config", (req, res) => {
const {
// Search
endpoint,
proxy_server_url,
corpus_id,
corpus_key,
customer_id,
Expand Down Expand Up @@ -122,6 +134,7 @@ app.post("/config", (req, res) => {
res.send({
// Search
endpoint,
proxy_server_url,
corpus_id,
corpus_key,
customer_id,
Expand Down
4 changes: 4 additions & 0 deletions src/contexts/ConfigurationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
interface Config {
// Search
config_endpoint?: string;
config_proxy_server_url?: string;
config_corpus_key?: string;
config_corpus_id?: string;
config_customer_id?: string;
Expand Down Expand Up @@ -98,6 +99,7 @@ const requiredConfigVars = ["corpus_key", "corpus_id", "customer_id", "api_key",

type Search = {
endpoint?: string;
proxyServerUrl?: string;
corpusKey?: string;
corpusId?: string;
customerId?: string;
Expand Down Expand Up @@ -386,6 +388,7 @@ export const ConfigContextProvider = ({ children }: Props) => {
const {
// Search
config_endpoint,
config_proxy_server_url,
config_corpus_key,
config_corpus_id,
config_customer_id,
Expand Down Expand Up @@ -460,6 +463,7 @@ export const ConfigContextProvider = ({ children }: Props) => {

setSearch({
endpoint: config_endpoint,
proxyServerUrl: config_proxy_server_url,
corpusKey: config_corpus_key,
corpusId: config_corpus_id,
customerId: config_customer_id,
Expand Down
16 changes: 12 additions & 4 deletions src/contexts/SearchContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ export const SearchContextProvider = ({ children }: Props) => {
setIsSearching(true);
setIsSummarizing(true);
setSelectedSearchResultPosition(undefined);
const getRerankerNumResults = () => {
console.log(filter)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rmv?

if (filter) {
return 100
}
else return rerank.numResults
}
if (search.corpusKey) {
if (search.enableStreamQuery) {
try {
Expand Down Expand Up @@ -297,9 +304,10 @@ export const SearchContextProvider = ({ children }: Props) => {
customerId: search.customerId!,
query: value,
corpusKey: filterBySource.filterByCorpus && filter ? filter: search.corpusKey!,
domain: `https://${search.endpoint!}`,
domain: search.proxyServerUrl,
// domain: search.endpoint!,
search: {
limit: rerank.numResults,
limit: getRerankerNumResults(),
offset: 0,
metadataFilter: !filterBySource.filterByCorpus && filter ? `doc.source = '${filter.toLowerCase()}'` : "",
lexicalInterpolation:
Expand Down Expand Up @@ -346,7 +354,7 @@ export const SearchContextProvider = ({ children }: Props) => {
corpusKey: filterBySource.filterByCorpus && filter ? filter: search.corpusKey!,
endpoint: search.endpoint!,
search: {
limit: rerank.numResults,
limit: getRerankerNumResults(),
offset: 0,
metadataFilter: !filterBySource.filterByCorpus && filter ? `doc.source = '${filter.toLowerCase()}'` : "",
lexicalInterpolation:
Expand Down Expand Up @@ -479,7 +487,7 @@ export const SearchContextProvider = ({ children }: Props) => {
filter: !filterBySource.filterByCorpus && filter ? `doc.source = '${filter.toLowerCase()}'` : "",
queryValue: value,
rerank: rerank.isEnabled,
rerankNumResults: rerank.numResults,
rerankNumResults: getRerankerNumResults(),
rerankerId: getRerankerConfigForApiV1StreamQuery(rerank),
rerankDiversityBias: rerank.diversityBias,
summaryNumResults: summary.summaryNumResults,
Expand Down
2 changes: 1 addition & 1 deletion src/views/search/summary/FactualConsistencyBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const FactualConsistencyBadge = ({ score, fcsMode }: Props) => {
{/*{score === undefined && <VuiSpinner size="s" />}*/}
<VuiFlexItem>
{
fcsMode === "badge" ? <ConfidenceBadge confidenceLevel={getConfidenceLevel(score ?? -1)} />
fcsMode === "badge" && sanitizedScore !== "unavailable" ? <ConfidenceBadge confidenceLevel={getConfidenceLevel(score ?? -1)} />
: badge
}
</VuiFlexItem>
Expand Down