-
-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from MervinPraison/develop
Update TypeScript Documentation and Examples with Simplified Agent Wo…
- Loading branch information
Showing
11 changed files
with
79 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,17 @@ | ||
import { Agent, PraisonAIAgents } from 'praisonai'; | ||
|
||
// Create story agent | ||
const storyAgent = new Agent({ | ||
instructions: "You are a storyteller. Write a very short story (2-3 sentences) about a given topic.", | ||
name: "StoryAgent", | ||
verbose: true | ||
instructions: "Generate a very short story (2-3 sentences) about artificial intelligence with emojis.", | ||
name: "StoryAgent" | ||
}); | ||
|
||
// Create summary agent | ||
const summaryAgent = new Agent({ | ||
instructions: "You are an editor. Create a one-sentence summary of the given story.", | ||
name: "SummaryAgent", | ||
verbose: true | ||
instructions: "Summarize the provided AI story in one sentence with emojis.", | ||
name: "SummaryAgent" | ||
}); | ||
|
||
// Create and start agents | ||
const agents = new PraisonAIAgents({ | ||
agents: [storyAgent, summaryAgent], | ||
tasks: [ | ||
"Write a short story about a cat", | ||
"{previous_result}" // This will be replaced with the story | ||
], | ||
verbose: true | ||
agents: [storyAgent, summaryAgent] | ||
}); | ||
|
||
agents.start() | ||
.then(results => { | ||
console.log('\nStory:', results[0]); | ||
console.log('\nSummary:', results[1]); | ||
}) | ||
.catch(error => console.error('Error:', error)); | ||
agents.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,8 @@ | ||
import { Agent } from 'praisonai'; | ||
|
||
// Single agent example - Science Explainer | ||
const agent = new Agent({ | ||
instructions: `You are a science expert who explains complex phenomena in simple terms. | ||
Provide clear, accurate, and easy-to-understand explanations.`, | ||
name: "ScienceExplainer", | ||
verbose: true | ||
instructions: `You are a creative writer who writes short stories with emojis.`, | ||
name: "StoryWriter" | ||
}); | ||
|
||
agent.start("Why is the sky blue?") | ||
.then(response => { | ||
console.log('\nExplanation:'); | ||
console.log(response); | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
}); | ||
agent.start("Write a story about a time traveler") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,21 @@ | ||
import { Agent, PraisonAIAgents } from 'praisonai'; | ||
|
||
// Create recipe agent | ||
const recipeAgent = new Agent({ | ||
instructions: `You are a professional chef and nutritionist. Create 5 healthy food recipes that are both nutritious and delicious. | ||
Each recipe should include: | ||
1. Recipe name | ||
2. List of ingredients with quantities | ||
3. Step-by-step cooking instructions | ||
4. Nutritional information | ||
5. Health benefits | ||
Format your response in markdown.`, | ||
name: "RecipeAgent", | ||
verbose: true | ||
instructions: `You are a professional chef and nutritionist. Create 1 healthy food recipes that are both nutritious and delicious.`, | ||
name: "RecipeAgent" | ||
}); | ||
|
||
// Create blog agent | ||
const blogAgent = new Agent({ | ||
instructions: `You are a food and health blogger. Write an engaging blog post about the provided recipes. | ||
The blog post should: | ||
1. Have an engaging title | ||
2. Include an introduction about healthy eating | ||
3. Discuss each recipe and its unique health benefits | ||
4. Include tips for meal planning and preparation | ||
5. End with a conclusion encouraging healthy eating habits | ||
Here are the recipes to write about: | ||
{previous_result} | ||
Format your response in markdown.`, | ||
name: "BlogAgent", | ||
verbose: true | ||
instructions: `You are a food and health blogger. Write an engaging blog post about the provided recipes`, | ||
name: "BlogAgent" | ||
}); | ||
|
||
// Create PraisonAIAgents instance with tasks | ||
const agents = new PraisonAIAgents({ | ||
agents: [recipeAgent, blogAgent], | ||
tasks: [ | ||
"Create 5 healthy and delicious recipes", | ||
"Write a blog post about the recipes" | ||
], | ||
verbose: true | ||
"Create 1 healthy and delicious recipes in 5 lines with emojis", | ||
"Write a blog post about the recipes in 5 lines with emojis" | ||
] | ||
}); | ||
|
||
// Start the agents | ||
agents.start() | ||
.then(results => { | ||
console.log('\nFinal Results:'); | ||
console.log('\nRecipe Task Results:'); | ||
console.log(results[0]); | ||
console.log('\nBlog Task Results:'); | ||
console.log(results[1]); | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
}); | ||
agents.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Agent, PraisonAIAgents } from '../../src/agent/proxy'; | ||
|
||
const storyAgent = new Agent({ | ||
instructions: "Generate a very short story (2-3 sentences) about artificial intelligence developing emotions and creativity with emojis.", | ||
name: "StoryAgent" | ||
}); | ||
|
||
const summaryAgent = new Agent({ | ||
instructions: "Summarize the provided AI story in one sentence. Do not ask for input - the story will be automatically provided to you with emojis.", | ||
name: "SummaryAgent" | ||
}); | ||
|
||
const agents = new PraisonAIAgents({ | ||
agents: [storyAgent, summaryAgent] | ||
}); | ||
|
||
agents.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,9 @@ | ||
import { Agent } from '../../src/agent/proxy'; | ||
|
||
// Single agent example - Short Story Writer | ||
const agent = new Agent({ | ||
instructions: `You are a creative writer who writes short stories. | ||
Keep stories brief (max 100 words) and engaging.`, | ||
name: "StoryWriter", | ||
verbose: true, | ||
pretty: true, // Enable pretty logging | ||
stream: true // Enable streaming output | ||
Keep stories brief (max 50 words) and engaging with emojis.`, | ||
name: "StoryWriter" | ||
}); | ||
|
||
// Write a very short story | ||
agent.start("Write a 100-word story about a time traveler") | ||
.catch(error => { | ||
console.error('Error:', error); | ||
}); | ||
agent.start("Write a story about a time traveler") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters