@@ -106,10 +106,10 @@ import { LLMArgs } from "./llm";
106106import { getDefaultModel , getDefaultEmbeddingModel } from "./oai" ;
107107import { buildOpenAIClient , extractOpenAIArgs } from "./oai" ;
108108import OpenAI from "openai" ;
109+ import { zodFunction } from "openai/helpers/zod" ;
109110import { ListContains } from "./list" ;
110111import { EmbeddingSimilarity } from "./string" ;
111- import { z } from "zod" ;
112- import zodToJsonSchema from "zod-to-json-schema" ;
112+ import { z } from "zod/v3" ;
113113import { makePartial , ScorerWithPartial } from "./partial" ;
114114
115115type RagasArgs = {
@@ -188,14 +188,11 @@ export const ContextEntityRecall: ScorerWithPartial<
188188 } ,
189189 ] ,
190190 tools : [
191- {
192- type : "function" ,
193- function : {
194- name : "extract_entities" ,
195- description : "Extract unique entities from a given text" ,
196- parameters : zodToJsonSchema ( entitySchema ) ,
197- } ,
198- } ,
191+ zodFunction ( {
192+ name : "extract_entities" ,
193+ description : "Extract unique entities from a given text" ,
194+ parameters : entitySchema ,
195+ } ) ,
199196 ] ,
200197 tool_choice : { type : "function" , function : { name : "extract_entities" } } ,
201198 } ) ;
@@ -268,14 +265,11 @@ export const ContextRelevancy: ScorerWithPartial<string, RagasArgs> =
268265 } ,
269266 ] ,
270267 tools : [
271- {
272- type : "function" ,
273- function : {
274- name : "extract_sentences" ,
275- description : "Extract relevant sentences from a given context" ,
276- parameters : zodToJsonSchema ( relevantSentencesSchema ) ,
277- } ,
278- } ,
268+ zodFunction ( {
269+ name : "extract_sentences" ,
270+ description : "Extract relevant sentences from a given context" ,
271+ parameters : relevantSentencesSchema ,
272+ } ) ,
279273 ] ,
280274 tool_choice : {
281275 type : "function" ,
@@ -371,13 +365,10 @@ export const ContextRecall: ScorerWithPartial<string, RagasArgs> = makePartial(
371365 } ,
372366 ] ,
373367 tools : [
374- {
375- type : "function" ,
376- function : {
377- name : "extract_statements" ,
378- parameters : zodToJsonSchema ( contextRecallSchema ) ,
379- } ,
380- } ,
368+ zodFunction ( {
369+ name : "extract_statements" ,
370+ parameters : contextRecallSchema ,
371+ } ) ,
381372 ] ,
382373 tool_choice : {
383374 type : "function" ,
@@ -473,15 +464,11 @@ export const ContextPrecision: ScorerWithPartial<string, RagasArgs> =
473464 } ,
474465 ] ,
475466 tools : [
476- {
477- type : "function" ,
478- function : {
479- name : "verify" ,
480- description :
481- "Verify if context was useful in arriving at the answer" ,
482- parameters : zodToJsonSchema ( contextPrecisionSchema ) ,
483- } ,
484- } ,
467+ zodFunction ( {
468+ name : "verify" ,
469+ description : "Verify if context was useful in arriving at the answer" ,
470+ parameters : contextPrecisionSchema ,
471+ } ) ,
485472 ] ,
486473 tool_choice : { type : "function" , function : { name : "verify" } } ,
487474 } ) ;
@@ -600,14 +587,11 @@ export const Faithfulness: ScorerWithPartial<string, RagasArgs> = makePartial(
600587 } ,
601588 ] ,
602589 tools : [
603- {
604- type : "function" ,
605- function : {
606- name : "extract_statements" ,
607- description : "Extract statements from an answer given a question" ,
608- parameters : zodToJsonSchema ( extractedStatementsSchema ) ,
609- } ,
610- } ,
590+ zodFunction ( {
591+ name : "extract_statements" ,
592+ description : "Extract statements from an answer given a question" ,
593+ parameters : extractedStatementsSchema ,
594+ } ) ,
611595 ] ,
612596 tool_choice : {
613597 type : "function" ,
@@ -631,15 +615,12 @@ export const Faithfulness: ScorerWithPartial<string, RagasArgs> = makePartial(
631615 } ,
632616 ] ,
633617 tools : [
634- {
635- type : "function" ,
636- function : {
637- name : "judge_statements" ,
638- description :
639- "Judge whether the statements are faithful to the context" ,
640- parameters : zodToJsonSchema ( statementFaithfulnessSchema ) ,
641- } ,
642- } ,
618+ zodFunction ( {
619+ name : "judge_statements" ,
620+ description :
621+ "Judge whether the statements are faithful to the context" ,
622+ parameters : statementFaithfulnessSchema ,
623+ } ) ,
643624 ] ,
644625 tool_choice : { type : "function" , function : { name : "judge_statements" } } ,
645626 } ) ;
@@ -741,15 +722,12 @@ export const AnswerRelevancy: ScorerWithPartial<
741722 } ,
742723 ] ,
743724 tools : [
744- {
745- type : "function" ,
746- function : {
747- name : "generate_question" ,
748- description :
749- "Generate a question for the given answer and identify if the answer is noncommittal" ,
750- parameters : zodToJsonSchema ( questionGenSchema ) ,
751- } ,
752- } ,
725+ zodFunction ( {
726+ name : "generate_question" ,
727+ description :
728+ "Generate a question for the given answer and identify if the answer is noncommittal" ,
729+ parameters : questionGenSchema ,
730+ } ) ,
753731 ] ,
754732 tool_choice : {
755733 type : "function" ,
@@ -920,14 +898,11 @@ export const AnswerCorrectness: ScorerWithPartial<
920898 } ,
921899 ] ,
922900 tools : [
923- {
924- type : "function" ,
925- function : {
926- name : "classify_statements" ,
927- description : "Classify statements as TP, FP, or FN" ,
928- parameters : zodToJsonSchema ( answerCorrectnessClassificationSchema ) ,
929- } ,
930- } ,
901+ zodFunction ( {
902+ name : "classify_statements" ,
903+ description : "Classify statements as TP, FP, or FN" ,
904+ parameters : answerCorrectnessClassificationSchema ,
905+ } ) ,
931906 ] ,
932907 tool_choice : {
933908 type : "function" ,
0 commit comments