You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using generateText with 2 tools used to "profile" a research author by name.
What I notice is it never calls both tools always. I basically want the ai to call all tools and then use that data to generate a summary of a author profile.
const { text } = await generateText({
model: anthropic("claude-3-5-sonnet-20240620"),
tools: {
authorSearchApi: tool({
description:
"Find the author profile using Google Scholar. You must use this as well.",
parameters: z.object({
author: z.string().describe("The author to search for"),
}),
execute: async ({ author }) => {
console.log(`authorSearchApi: Searching for ${author}`);
try {
const url = "https://www.searchapi.io/api/v1/search";
const params = {
engine: "google_scholar",
q: `author:${author}`,
api_key: process.env.SEARCH_API_KEY,
};
const response = await axios.get(url, { params });
const data = response.data;
if (data.profiles && data.profiles.length > 0) {
const authorProfile = data.profiles[0];
return {
source: "google_scholar",
profile: authorProfile,
success: true,
};
}
console.log(`authorSearchApi: No results for ${author}`);
return {
source: "google_scholar",
profile: null,
success: false,
};
} catch (error: any) {
console.error(`authorSearchApi error:`, error.message);
return {
source: "google_scholar",
profile: null,
success: false,
error: error.message,
};
}
},
}),
semanticScholarTool: tool({
description:
"Find the author profile using Semantic Scholar. You must use this as well.",
parameters: z.object({
author: z.string().describe("The author to search for"),
}),
execute: async ({ author }) => {
console.log(`semanticScholarTool: Searching for ${author}`);
try {
const url = `https://api.semanticscholar.org/graph/v1/author/search`;
const params = {
query: author,
limit: 1,
};
const response = await axios.get(url, { params });
const data = response.data;
if (data?.data?.length > 0) {
const authorProfile = data.data[0];
return {
source: "semantic_scholar",
profile: authorProfile,
success: true,
};
}
console.log(`semanticScholarTool: No results for ${author}`);
return {
source: "semantic_scholar",
profile: null,
success: false,
};
} catch (error: any) {
console.error(`semanticScholarTool error:`, error.message);
return {
source: "semantic_scholar",
profile: null,
success: false,
error: error.message,
};
}
},
}),
},
toolChoice: "required",
maxSteps: 4,
prompt: `Profile the research author: ${document.firstAuthor}.
Use all tools first to get the best results.
Analyze and combine all available information about the author from both sources if available.`,
});
As usual sometimes it seems to do it and sometimes not.
I also notice something weird when it calls the semanticScholarTool, the author is some number. semanticScholarTool: Searching for 2238659230
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am using generateText with 2 tools used to "profile" a research author by name.
What I notice is it never calls both tools always. I basically want the ai to call all tools and then use that data to generate a summary of a author profile.
As usual sometimes it seems to do it and sometimes not.
I also notice something weird when it calls the semanticScholarTool, the author is some number.
semanticScholarTool: Searching for 2238659230
Any ideas to improve this?
Beta Was this translation helpful? Give feedback.
All reactions