|
1 | 1 | import { z } from "zod"; |
2 | | -import { anthropic } from "@ai-sdk/anthropic"; |
3 | 2 | import { generateObject } from "ai"; |
4 | 3 | import Exa from 'exa-js'; |
| 4 | +import {getModel} from "@/lib/utils/modelUtils"; |
| 5 | +import { generateMetaAnalysisQuery } from '@/lib/meta-analysis/metaAnalysisQueries'; |
5 | 6 |
|
6 | 7 | const exa = new Exa(process.env.EXA_API_KEY); |
7 | 8 |
|
@@ -56,24 +57,24 @@ const MetaAnalysisReportSchema = z.object({ |
56 | 57 | effectivenessComparison: z.array(z.object({ |
57 | 58 | intervention: z.string().describe('Name of the compared intervention'), |
58 | 59 | relativeEffectiveness: z.string().describe('Relative effectiveness compared to the main drug'), |
59 | | - dalysAvoided: z.number().optional().describe('Estimated Disability-Adjusted Life Years (DALYs) avoided per patient'), |
60 | | - qalysIncreased: z.number().optional().describe('Estimated Quality-Adjusted Life Years (QALYs) increased per patient'), |
61 | | - numberNeededToHarm: z.number().optional().describe('Number Needed to Harm (NNH) to cause a negative health outcome'), |
62 | | - numberNeededToTreat: z.number().optional().describe('Number Needed to Treat (NNT) to achieve a positive health outcome'), |
| 60 | + dalysAvoided: z.union([z.number(), z.string()]).optional().describe('Estimated Disability-Adjusted Life Years (DALYs) avoided per patient'), |
| 61 | + qalysIncreased: z.union([z.number(), z.string()]).optional().describe('Estimated Quality-Adjusted Life Years (QALYs) increased per patient'), |
| 62 | + numberNeededToHarm: z.union([z.number(), z.string()]).optional().describe('Number Needed to Harm (NNH) to cause a negative health outcome'), |
| 63 | + numberNeededToTreat: z.union([z.number(), z.string()]).optional().describe('Number Needed to Treat (NNT) to achieve a positive health outcome'), |
63 | 64 | })).describe('Comparison of effectiveness with other treatments'), |
64 | | - dalysAvoided: z.number().optional().describe('Estimated Disability-Adjusted Life Years (DALYs) avoided per patient'), |
65 | | - qalysIncreased: z.number().optional().describe('Estimated Quality-Adjusted Life Years (QALYs) increased per patient'), |
66 | | - numberNeededToHarm: z.number().optional().describe('Number Needed to Harm (NNH) to cause a negative health outcome'), |
67 | | - numberOfPatients: z.number().optional().describe('Number of patients globally who would benefit from the drug'), |
68 | | - numberNeededToTreat: z.number().optional().describe('Number Needed to Treat (NNT) to achieve a positive health outcome'), |
| 65 | + dalysAvoided: z.union([z.number(), z.string()]).optional().describe('Estimated Disability-Adjusted Life Years (DALYs) avoided per patient'), |
| 66 | + qalysIncreased: z.union([z.number(), z.string()]).optional().describe('Estimated Quality-Adjusted Life Years (QALYs) increased per patient'), |
| 67 | + numberNeededToHarm: z.union([z.number(), z.string()]).optional().describe('Number Needed to Harm (NNH) to cause a negative health outcome'), |
| 68 | + numberOfPatients: z.union([z.number(), z.string()]).optional().describe('Number of patients globally who would benefit from the drug'), |
| 69 | + numberNeededToTreat: z.union([z.number(), z.string()]).optional().describe('Number Needed to Treat (NNT) to achieve a positive health outcome'), |
69 | 70 | //referenceSources: z.array(articleSchema).describe('Sources of information used in compiling this report') |
70 | 71 | }); |
71 | 72 |
|
72 | 73 | export type MetaAnalysisReportType = z.infer<typeof MetaAnalysisReportSchema>; |
73 | 74 |
|
74 | 75 |
|
75 | 76 | async function getWebResults(drugName: string, conditionName: string, numResults: number = 10): Promise<Article[]> { |
76 | | - const query = `${drugName} for ${conditionName} meta-analysis safety efficacy "clinical trials" "systematic review"`; |
| 77 | + const query = generateMetaAnalysisQuery(drugName, conditionName); |
77 | 78 | const searchResponse = await exa.searchAndContents(query, { |
78 | 79 | numResults, |
79 | 80 | useAutoprompt: false, |
@@ -111,8 +112,11 @@ export async function doMetaAnalysis(drugName: string, conditionName: string): P |
111 | 112 | Web search results: |
112 | 113 | ${webResultsText}`; |
113 | 114 |
|
| 115 | + //const model = getModel("gemini-1.5-flash") |
| 116 | + const model = getModel() |
| 117 | + |
114 | 118 | const result = await generateObject({ |
115 | | - model: anthropic('claude-3-5-sonnet-20240620'), |
| 119 | + model, |
116 | 120 | schema: MetaAnalysisReportSchema, |
117 | 121 | prompt, |
118 | 122 | }); |
|
0 commit comments