Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add tests for anthropic and improve oai test #3472

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/agent/src/plugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,6 @@ class TestRunner {
const plugins = this.runtime.plugins;

for (const plugin of plugins) {
if (!plugin.tests) {
logger.info(`Plugin ${plugin.name} has no tests`);
continue;
}

try {
logger.info(`Running tests for plugin: ${plugin.name}`);
const pluginTests = plugin.tests;
Expand Down
44 changes: 44 additions & 0 deletions packages/plugin-anthropic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,50 @@ export const anthropicPlugin: Plugin = {
return text;
}
},
tests: [
{
name: "anthropic_plugin_tests",
tests: [
{
name: 'anthropic_test_text_small',
fn: async (runtime) => {
try {
const text = await runtime.useModel(ModelClass.TEXT_SMALL, {
context: "Debug Mode:",
prompt: "What is the nature of reality in 10 words?",
});
if (text.length === 0) {
throw new Error("Failed to generate text");
}
console.log("generated with test_text_small:", text);
} catch (error) {
console.error("Error in test_text_small:", error);
throw error;
}
}
},
{
name: 'anthropic_test_text_large',
fn: async (runtime) => {
try {
const text = await runtime.useModel(ModelClass.TEXT_LARGE, {
context: "Debug Mode:",
prompt: "What is the nature of reality in 10 words?",
});
if (text.length === 0) {
throw new Error("Failed to generate text");
}
console.log("generated with test_text_small:", text);
} catch (error) {
console.error("Error in test_text_small:", error);
Comment on lines +120 to +122
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message in the text_large test incorrectly references test_text_small. For consistency with the test name, this should be updated to test_text_large in both the console.log and console.error statements.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

throw error;
}
}
}
]
}
]

};

export default anthropicPlugin;
24 changes: 10 additions & 14 deletions packages/plugin-openai/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,27 +296,27 @@ export const openaiPlugin: Plugin = {
name: "openai_plugin_tests",
tests: [
{
name: 'test_url_and_api_key_validation',
name: 'openai_test_url_and_api_key_validation',
fn: async (runtime) => {
const baseURL =
runtime.getSetting("OPENAI_BASE_URL") ?? "https://api.openai.com/v1";
const response = await fetch(`${baseURL}/models`, {
headers: { Authorization: `Bearer ${runtime.getSetting("OPENAI_API_KEY")}` },
});
console.log("response", await response.json());
const data = await response.json();
console.log("Models Available:", (data as any)?.data.length);
if (!response.ok) {
throw new Error(`Failed to validate OpenAI API key: ${response.statusText}`);
}
}
},
{
name: 'test_text_large',
name: 'openai_test_text_large',
fn: async (runtime) => {
console.log("test_openai_plugin");
try {
const text = await runtime.useModel(ModelClass.TEXT_LARGE, {
context: "Test Mode: Reply with a short answer",
prompt: "What is the nature of reality?",
context: "Debug Mode:",
prompt: "What is the nature of reality in 10 words?",
});
if (text.length === 0) {
throw new Error("Failed to generate text");
Expand All @@ -329,12 +329,11 @@ export const openaiPlugin: Plugin = {
}
},
{
name: 'test_text_small',
name: 'openai_test_text_small',
fn: async (runtime) => {
console.log("test_openai_plugin");
try {
const text = await runtime.useModel(ModelClass.TEXT_SMALL, {
context: "Test Mode:",
context: "Debug Mode:",
prompt: "What is the nature of reality in 10 words?",
});
if (text.length === 0) {
Expand All @@ -348,18 +347,15 @@ export const openaiPlugin: Plugin = {
}
},
{
name: 'test_image_generation',
name: 'openai_test_image_generation',
fn: async (runtime) => {
console.log("test_openai_plugin");
console.log("openai_test_image_generation");
try {
const image = await runtime.useModel(ModelClass.IMAGE, {
prompt: "A beautiful sunset over a calm ocean",
n: 1,
size: "1024x1024"
});
if (image.length === 0) {
throw new Error("Failed to generate image");
}
console.log("generated with test_image_generation:", image);
} catch (error) {
console.error("Error in test_image_generation:", error);
Expand Down
Loading