refactor: agent schema

This commit is contained in:
Han Xiao
2025-03-02 09:40:30 +08:00
parent 46fd2d0594
commit 61b28da719

View File

@@ -1,13 +1,13 @@
import {z} from "zod"; import {z} from "zod";
import {ObjectGeneratorSafe} from "./safe-generator"; import {ObjectGeneratorSafe} from "./safe-generator";
import {EvaluationType} from "../types"; import {EvaluationType, PromptPair} from "../types";
export const MAX_URLS_PER_STEP = 2 export const MAX_URLS_PER_STEP = 2
export const MAX_QUERIES_PER_STEP = 5 export const MAX_QUERIES_PER_STEP = 5
export const MAX_REFLECT_PER_STEP = 3 export const MAX_REFLECT_PER_STEP = 3
function getLanguagePrompt(question: string) { function getLanguagePrompt(question: string): PromptPair {
return `Identifies both the language used and the overall vibe of the question return {system:`Identifies both the language used and the overall vibe of the question
<rules> <rules>
Combine both language and emotional vibe in a descriptive phrase, considering: Combine both language and emotional vibe in a descriptive phrase, considering:
@@ -53,10 +53,8 @@ Evaluation: {
"langCode": "en", "langCode": "en",
"languageStyle": "casual English" "languageStyle": "casual English"
} }
</examples> </examples>`,
user: question};
Now evaluate this question:
${question}`;
} }
export class Schemas { export class Schemas {
@@ -66,11 +64,13 @@ export class Schemas {
async setLanguage(query: string) { async setLanguage(query: string) {
const generator = new ObjectGeneratorSafe(); const generator = new ObjectGeneratorSafe();
const prompt = getLanguagePrompt(query.slice(0, 100))
const result = await generator.generateObject({ const result = await generator.generateObject({
model: 'evaluator', model: 'evaluator',
schema: this.getLanguageSchema(), schema: this.getLanguageSchema(),
prompt: getLanguagePrompt(query.slice(0, 100)), system: prompt.system,
prompt: prompt.user
}); });
this.languageCode = result.object.langCode; this.languageCode = result.object.langCode;