-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDatasphereWebhookEnvDemo.java
More file actions
60 lines (49 loc) · 2.17 KB
/
Copy pathDatasphereWebhookEnvDemo.java
File metadata and controls
60 lines (49 loc) · 2.17 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
/**
* DataSphere Webhook Environment Demo.
*
* Traditional webhook-based DataSphere skill configured from environment
* variables. Compare with DatasphereServerlessEnv for the serverless approach.
*
* Required: SIGNALWIRE_SPACE, SIGNALWIRE_PROJECT_ID, SIGNALWIRE_API_TOKEN,
* DATASPHERE_DOCUMENT_ID
*/
import com.signalwire.sdk.agent.AgentBase;
import java.util.Map;
public class DatasphereWebhookEnvDemo {
static String requireEnv(String name) {
String val = System.getenv(name);
if (val == null || val.isEmpty()) {
System.err.println("Error: Required environment variable " + name + " is not set.");
System.exit(1);
}
return val;
}
public static void main(String[] args) throws Exception {
String documentId = requireEnv("DATASPHERE_DOCUMENT_ID");
int count = Integer.parseInt(System.getenv().getOrDefault("DATASPHERE_COUNT", "3"));
double distance = Double.parseDouble(System.getenv().getOrDefault("DATASPHERE_DISTANCE", "4.0"));
var agent = AgentBase.builder()
.name("datasphere-webhook-env")
.route("/datasphere-webhook")
.port(3000)
.build();
agent.addLanguage("English", "en-US", "en-US-Standard-C");
agent.promptAddSection("Role",
"You are a knowledge assistant using webhook-based DataSphere for retrieval.");
agent.addSkill("datetime", Map.of());
agent.addSkill("math", Map.of());
agent.addSkill("datasphere", Map.of(
"document_id", documentId,
"count", count,
"distance", distance,
"mode", "webhook"));
System.out.println("DataSphere Webhook Environment Demo");
System.out.printf(" Document: %s%n", documentId);
System.out.println(" Execution: Webhook-based (traditional)");
System.out.println();
System.out.println(" Webhook: Full control, custom error handling");
System.out.println(" Serverless: No webhooks, lower latency, executes on SignalWire");
System.out.println("Starting agent on port 3000...");
agent.run();
}
}