-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSupportExample.java
More file actions
52 lines (44 loc) · 1.57 KB
/
FileSupportExample.java
File metadata and controls
52 lines (44 loc) · 1.57 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
package ai.rhesis.sdk.examples;
import ai.rhesis.sdk.RhesisClient;
import ai.rhesis.sdk.entities.File;
import ai.rhesis.sdk.entities.Test;
import ai.rhesis.sdk.enums.TestType;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
public class FileSupportExample {
public static void main(String[] args) throws Exception {
RhesisClient client = RhesisClient.builder().apiKey(System.getenv("RHESIS_API_KEY")).build();
// 1. Create a dummy file
Path tempFile = Files.createTempFile("rhesis-test", ".txt");
Files.writeString(tempFile, "Hello, Rhesis!");
// 2. Create a test
Test test =
Test.builder()
.behavior("File Test Behavior")
.category("SDK")
.topic("Files")
.testType(TestType.SINGLE_TURN)
.metadata(Map.of())
.files(List.of(tempFile.toString()))
.build();
Test created = client.tests().create(test);
System.out.println("Created test: " + created.id());
// 4. List files on test
List<File> files = client.tests().getFiles(created.id());
System.out.println("Test has " + files.size() + " files");
// 5. Download file content
if (!files.isEmpty()) {
byte[] content = client.files().download(files.get(0).id());
System.out.println(
"Downloaded content: " + new String(content, java.nio.charset.StandardCharsets.UTF_8));
}
// Clean up
for (File f : files) {
client.files().delete(f.id());
}
client.tests().delete(created.id());
Files.delete(tempFile);
}
}