-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJokeAgent.java
More file actions
71 lines (63 loc) · 2.69 KB
/
Copy pathJokeAgent.java
File metadata and controls
71 lines (63 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Joke Agent -- uses a raw data_map configuration to integrate
* with the API Ninjas joke API.
*
* Run with: API_NINJAS_KEY=your_key java JokeAgent
*/
import com.signalwire.sdk.agent.AgentBase;
import java.util.List;
import java.util.Map;
public class JokeAgent {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("API_NINJAS_KEY");
if (apiKey == null || apiKey.isEmpty()) {
System.err.println("Error: API_NINJAS_KEY environment variable is required.");
System.err.println("Get a free key at https://api.api-ninjas.com/");
System.exit(1);
}
var agent = AgentBase.builder()
.name("joke-agent")
.route("/joke-agent")
.port(3000)
.build();
agent.promptAddSection("Personality",
"You are a funny assistant who loves to tell jokes.");
agent.promptAddSection("Goal",
"Make people laugh with great jokes.");
agent.promptAddSection("Instructions", "", List.of(
"Use the get_joke function to tell jokes when asked",
"You can tell either regular jokes or dad jokes",
"Be enthusiastic about sharing humor"
));
// Register a raw data_map function (no webhook handler needed)
agent.registerSwaigFunction(Map.of(
"function", "get_joke",
"description", "Tell a joke",
"parameters", Map.of(
"type", "object",
"properties", Map.of(
"type", Map.of(
"type", "string",
"description", "Must be 'jokes' or 'dadjokes'"
)
)
),
"data_map", Map.of(
"webhooks", List.of(Map.of(
"url", "https://api.api-ninjas.com/v1/%{args.type}",
"method", "GET",
"headers", Map.of("X-Api-Key", apiKey),
"output", Map.of(
"response", "Tell the user: %{array[0].joke}"
),
"error_keys", "error"
)),
"output", Map.of(
"response", "The joke service isn't working right now. Make up a joke on your own."
)
)
));
System.out.println("Starting Joke Agent on port 3000...");
agent.run();
}
}