feat: update minRelScore and add searchLanguageCode support

This commit is contained in:
Han Xiao 2025-06-09 19:11:36 -07:00
parent ae2e7c7fc6
commit 2307c2ff44
4 changed files with 9 additions and 2 deletions

View File

@ -388,8 +388,9 @@ export async function getResponse(question?: string,
badHostnames: string[] = [],
onlyHostnames: string[] = [],
maxRef: number = 10,
minRelScore: number = 0.75,
minRelScore: number = 0.85,
languageCode: string | undefined = undefined,
searchLanguageCode?: string,
searchProvider?: string
): Promise<{ result: StepAction; context: TrackerContext; visitedURLs: string[], readURLs: string[], allURLs: string[] }> {
@ -420,6 +421,9 @@ export async function getResponse(question?: string,
const SchemaGen = new Schemas();
await SchemaGen.setLanguage(languageCode || question)
if (searchLanguageCode) {
SchemaGen.searchLanguageCode = searchLanguageCode;
}
const context: TrackerContext = {
tokenTracker: existingContext?.tokenTracker || new TokenTracker(tokenBudget),
actionTracker: existingContext?.actionTracker || new ActionTracker()

View File

@ -582,6 +582,7 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
body.max_annotations,
body.min_annotation_relevance,
body.language_code,
body.search_language_code,
body.search_provider
)
let finalAnswer = (finalStep as AnswerAction).mdAnswer;

View File

@ -260,6 +260,7 @@ export interface ChatCompletionRequest {
max_annotations?: number;
min_annotation_relevance?: number;
language_code?: string;
search_language_code?: string;
search_provider?: string;
}

View File

@ -96,6 +96,7 @@ const languageISO6391Map: Record<string, string> = {
export class Schemas {
public languageStyle: string = 'formal English';
public languageCode: string = 'en';
public searchLanguageCode: string | undefined = undefined;
async setLanguage(query: string) {
@ -162,7 +163,7 @@ export class Schemas {
z.object({
tbs: z.enum(['qdr:h', 'qdr:d', 'qdr:w', 'qdr:m', 'qdr:y']).describe('time-based search filter, must use this field if the search request asks for latest info. qdr:h for past hour, qdr:d for past 24 hours, qdr:w for past week, qdr:m for past month, qdr:y for past year. Choose exactly one.'),
location: z.string().describe('defines from where you want the search to originate. It is recommended to specify location at the city level in order to simulate a real users search.').optional(),
q: z.string().describe('keyword-based search query, 2-3 words preferred, total length < 30 characters').max(50),
q: z.string().describe(`keyword-based search query, 2-3 words preferred, total length < 30 characters. ${this.searchLanguageCode ? `Must in ${this.searchLanguageCode}` : ''}`).max(50),
}))
.max(MAX_QUERIES_PER_STEP)
.describe(`'Array of search keywords queries, orthogonal to each other. Maximum ${MAX_QUERIES_PER_STEP} queries allowed.'`)