Adding a Command
Let's continue working with the Gemini agent from quickstart. We can add a command /prompt
that is expert at generating prompts for the users.
Create a new file lib/commands/prompt.dart
and define the PromptCommand
:
import 'package:dash_agent/configuration/command.dart' ;
import 'package:dash_agent/steps/steps.dart' ;
import 'package:dash_agent/variables/dash_input.dart' ;
import 'package:dash_agent/variables/dash_output.dart' ;
import 'package:gemini/data_sources.dart' ;
/// [PromptCommand] generates a prompt based on user input.
class PromptCommand extends Command {
PromptCommand ( this .promptDataSource);
/// [Data source that contains blogs/guidelines specific to prompting techniques]
final PromptDataSource promptDataSource;
final promptGuidelines = StringInput ( 'Prompt Guidelines' );
@override
String get slug => '/prompt' ;
@override
String get intent => 'Generate perfect prompt' ;
@override
String get textFieldLayout =>
"Enter your desired prompt guidelines: $ promptGuidelines " ;
@override
List < DashInput > get registerInputs => [promptGuidelines];
@override
List < Step > get steps {
final matchingDocs = MatchDocumentOuput ();
final promptOutput = PromptOutput ();
return [
// [Find the right guidelines for the users's requirement]
MatchDocumentStep (
query :
'Documenation helpful to generate prompt for guidelines $ promptGuidelines ' ,
dataSources : [promptDataSource],
output : matchingDocs),
// [LLM request using user inputs + matched prompt guidelines]
PromptQueryStep (
prompt : '''
You are a prompting expert helping use generate new prompts for their LLM requests.
Here is the guidelines for which the user wants to generate or edit the prompt: $ promptGuidelines
Here is documentation on prompting strategies with some examples from an official guide on writing good quality prompts:
$ matchingDocs
Generate, review or refine the prompt for user based on their guidelines, currrent prompt and the references and documentation provided.''' ,
promptOutput : promptOutput,
),
// [Append the result to the chat]
AppendToChatStep (value : '$ promptOutput ' )
];
}
}
PromptDataSource
:
class PromptDataSource extends DataSource {
@override
List < FileDataObject > get fileObjects => [];
@override
List < ProjectDataObject > get projectObjects => [];
@override
List < WebDataObject > get webObjects => [
WebDataObject . fromWebPage (
'https://ai.google.dev/gemini-api/docs/prompting-intro' ),
WebDataObject . fromWebPage (
'https://ai.google.dev/gemini-api/docs/prompting_with_media' ),
WebDataObject . fromWebPage (
'https://ai.google.dev/gemini-api/docs/prompting-strategies' ),
WebDataObject . fromWebPage (
'https://ai.google.dev/gemini-api/docs/file-prompting-strategies' ),
];
}
slug
, intent
and textFieldLayout
helps to choose and understand the usage of a command.
User can provide inputs on the kind of prompts they want to create and a perfect one will be crafted for them.