-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDatasphereServerlessEnv.java
More file actions
66 lines (53 loc) · 2.31 KB
/
Copy pathDatasphereServerlessEnv.java
File metadata and controls
66 lines (53 loc) · 2.31 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
/**
* DataSphere Serverless Environment Demo.
*
* Loads the DataSphere serverless skill with configuration from environment
* variables for production deployment.
*
* Required: SIGNALWIRE_SPACE, SIGNALWIRE_PROJECT_ID, SIGNALWIRE_API_TOKEN,
* DATASPHERE_DOCUMENT_ID
* Optional: DATASPHERE_COUNT, DATASPHERE_DISTANCE, DATASPHERE_TAGS
*/
import com.signalwire.sdk.agent.AgentBase;
import java.util.HashMap;
import java.util.Map;
public class DatasphereServerlessEnv {
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-serverless-env")
.route("/datasphere-env")
.port(3000)
.build();
agent.addLanguage("English", "en-US", "en-US-Standard-C");
agent.promptAddSection("Role",
"You are a knowledge assistant with access to a document library. " +
"Search the knowledge base to answer user questions.");
agent.addSkill("datetime", Map.of());
agent.addSkill("math", Map.of());
Map<String, Object> config = new HashMap<>();
config.put("document_id", documentId);
config.put("count", count);
config.put("distance", distance);
String tags = System.getenv("DATASPHERE_TAGS");
if (tags != null && !tags.isEmpty()) {
config.put("tags", java.util.Arrays.asList(tags.split(",")));
}
agent.addSkill("datasphere", config);
System.out.println("DataSphere Serverless Environment Demo");
System.out.printf(" Document: %s%n", documentId);
System.out.printf(" Count: %d, Distance: %.1f%n", count, distance);
System.out.println("Starting agent on port 3000...");
agent.run();
}
}