mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2026-03-22 07:29:35 +08:00
style: format imports and add language_code to request
This commit is contained in:
@@ -393,7 +393,8 @@ export async function getResponse(question?: string,
|
|||||||
badHostnames: string[] = [],
|
badHostnames: string[] = [],
|
||||||
onlyHostnames: string[] = [],
|
onlyHostnames: string[] = [],
|
||||||
maxRef: number = 10,
|
maxRef: number = 10,
|
||||||
minRelScore: number = 0.75
|
minRelScore: number = 0.75,
|
||||||
|
languageCode: string | undefined = 'zh-CN'
|
||||||
): Promise<{ result: StepAction; context: TrackerContext; visitedURLs: string[], readURLs: string[], allURLs: string[] }> {
|
): Promise<{ result: StepAction; context: TrackerContext; visitedURLs: string[], readURLs: string[], allURLs: string[] }> {
|
||||||
|
|
||||||
let step = 0;
|
let step = 0;
|
||||||
@@ -417,7 +418,7 @@ export async function getResponse(question?: string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const SchemaGen = new Schemas();
|
const SchemaGen = new Schemas();
|
||||||
await SchemaGen.setLanguage(question)
|
await SchemaGen.setLanguage(languageCode || question)
|
||||||
const context: TrackerContext = {
|
const context: TrackerContext = {
|
||||||
tokenTracker: existingContext?.tokenTracker || new TokenTracker(tokenBudget),
|
tokenTracker: existingContext?.tokenTracker || new TokenTracker(tokenBudget),
|
||||||
actionTracker: existingContext?.actionTracker || new ActionTracker()
|
actionTracker: existingContext?.actionTracker || new ActionTracker()
|
||||||
|
|||||||
@@ -566,7 +566,8 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
|
|||||||
body.bad_hostnames?.map(i => normalizeHostName(i)),
|
body.bad_hostnames?.map(i => normalizeHostName(i)),
|
||||||
body.only_hostnames?.map(i => normalizeHostName(i)),
|
body.only_hostnames?.map(i => normalizeHostName(i)),
|
||||||
body.max_annotations,
|
body.max_annotations,
|
||||||
body.min_annotation_relevance
|
body.min_annotation_relevance,
|
||||||
|
body.language_code
|
||||||
)
|
)
|
||||||
let finalAnswer = (finalStep as AnswerAction).mdAnswer;
|
let finalAnswer = (finalStep as AnswerAction).mdAnswer;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ program
|
|||||||
const { result } = await getResponse(
|
const { result } = await getResponse(
|
||||||
query,
|
query,
|
||||||
parseInt(options.tokenBudget),
|
parseInt(options.tokenBudget),
|
||||||
parseInt(options.maxAttempts)
|
parseInt(options.maxAttempts),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.action === 'answer') {
|
if (result.action === 'answer') {
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ export interface ChatCompletionRequest {
|
|||||||
|
|
||||||
max_annotations?: number;
|
max_annotations?: number;
|
||||||
min_annotation_relevance?: number;
|
min_annotation_relevance?: number;
|
||||||
|
language_code?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface URLAnnotation {
|
export interface URLAnnotation {
|
||||||
|
|||||||
@@ -59,12 +59,51 @@ Evaluation: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const languageISO6391Map: Record<string, string> = {
|
||||||
|
'en': 'English',
|
||||||
|
'zh': 'Chinese',
|
||||||
|
'zh-CN': 'Simplified Chinese',
|
||||||
|
'zh-TW': 'Traditional Chinese',
|
||||||
|
'de': 'German',
|
||||||
|
'fr': 'French',
|
||||||
|
'es': 'Spanish',
|
||||||
|
'it': 'Italian',
|
||||||
|
'ja': 'Japanese',
|
||||||
|
'ko': 'Korean',
|
||||||
|
'pt': 'Portuguese',
|
||||||
|
'ru': 'Russian',
|
||||||
|
'ar': 'Arabic',
|
||||||
|
'hi': 'Hindi',
|
||||||
|
'bn': 'Bengali',
|
||||||
|
'tr': 'Turkish',
|
||||||
|
'nl': 'Dutch',
|
||||||
|
'pl': 'Polish',
|
||||||
|
'sv': 'Swedish',
|
||||||
|
'no': 'Norwegian',
|
||||||
|
'da': 'Danish',
|
||||||
|
'fi': 'Finnish',
|
||||||
|
'el': 'Greek',
|
||||||
|
'he': 'Hebrew',
|
||||||
|
'hu': 'Hungarian',
|
||||||
|
'id': 'Indonesian',
|
||||||
|
'ms': 'Malay',
|
||||||
|
'th': 'Thai',
|
||||||
|
'vi': 'Vietnamese',
|
||||||
|
'ro': 'Romanian',
|
||||||
|
'bg': 'Bulgarian',
|
||||||
|
}
|
||||||
|
|
||||||
export class Schemas {
|
export class Schemas {
|
||||||
public languageStyle: string = 'formal English';
|
public languageStyle: string = 'formal English';
|
||||||
public languageCode: string = 'en';
|
public languageCode: string = 'en';
|
||||||
|
|
||||||
|
|
||||||
async setLanguage(query: string) {
|
async setLanguage(query: string) {
|
||||||
|
if (languageISO6391Map[query]) {
|
||||||
|
this.languageCode = query;
|
||||||
|
this.languageStyle = `formal ${languageISO6391Map[query]}`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
const generator = new ObjectGeneratorSafe();
|
const generator = new ObjectGeneratorSafe();
|
||||||
const prompt = getLanguagePrompt(query.slice(0, 100))
|
const prompt = getLanguagePrompt(query.slice(0, 100))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user