@@ -25,7 +25,7 @@ export function getPeople(): Person[] {
25
25
return people ;
26
26
}
27
27
28
- export function queryPeople1 ( ) : string {
28
+ export function queryPeople1 ( ) : Person [ ] {
29
29
const query = `
30
30
{
31
31
people(func: type(Person)) {
@@ -39,13 +39,13 @@ export function queryPeople1(): string {
39
39
const response = dql . query < PeopleData > ( query ) ;
40
40
const people = response . data . people ;
41
41
people . forEach ( ( p ) => p . updateFullName ( ) ) ;
42
- return JSON . stringify ( people ) ;
42
+ return people ;
43
43
}
44
44
45
45
export function queryPeopleWithVars (
46
46
firstName : string ,
47
47
lastName : string ,
48
- ) : string {
48
+ ) : Person [ ] {
49
49
const query = `
50
50
query peopleWithVars($firstName: string, $lastName: string) {
51
51
people(func: eq(Person.firstName, $firstName)) @filter(eq(Person.lastName, $lastName)) {
@@ -63,10 +63,10 @@ export function queryPeopleWithVars(
63
63
const response = dql . query < PeopleData > ( query , parameters ) ;
64
64
const people = response . data . people ;
65
65
people . forEach ( ( p ) => p . updateFullName ( ) ) ;
66
- return JSON . stringify ( people ) ;
66
+ return people ;
67
67
}
68
68
69
- export function queryPeople2 ( ) : string {
69
+ export function queryPeople2 ( ) : Person [ ] {
70
70
const statement = `
71
71
query {
72
72
people: queryPerson {
@@ -87,7 +87,7 @@ export function queryPeople2(): string {
87
87
console . log ( `End: ${ tracing . endTime . toISOString ( ) } ` ) ;
88
88
console . log ( `Duration: ${ duration } ms` ) ;
89
89
90
- return JSON . stringify ( results . data . people ) ;
90
+ return results . data . people ;
91
91
}
92
92
93
93
export function newPerson1 ( firstName : string , lastName : string ) : string {
@@ -151,15 +151,18 @@ export function getRandomPerson(): Person {
151
151
return results . data . people [ 0 ] ;
152
152
}
153
153
154
- export function testClassifier ( modelId : string , text : string ) : string {
155
- return JSON . stringify ( model . classifyText ( modelId , text ) ) ;
154
+ export function testClassifier (
155
+ modelId : string ,
156
+ text : string ,
157
+ ) : ClassificationResult {
158
+ return model . classifyText ( modelId , text ) ;
156
159
}
157
160
158
161
export function testMultipleClassifier (
159
162
modelId : string ,
160
163
ids : string ,
161
164
texts : string ,
162
- ) : string {
165
+ ) : ClassificationObject [ ] {
163
166
// convert ids to array
164
167
const idArr = JSON . parse < string [ ] > ( ids ) ;
165
168
// convert texts to array
@@ -177,18 +180,18 @@ export function testMultipleClassifier(
177
180
result : response . get ( idArr [ i ] ) ,
178
181
} ) ;
179
182
}
180
- return JSON . stringify ( resultObjs ) ;
183
+ return resultObjs ;
181
184
}
182
185
183
- export function testEmbedding ( modelId : string , text : string ) : string {
184
- return JSON . stringify ( model . computeTextEmbedding ( modelId , text ) ) ;
186
+ export function testEmbedding ( modelId : string , text : string ) : f64 [ ] {
187
+ return model . computeTextEmbedding ( modelId , text ) ;
185
188
}
186
189
187
190
export function testEmbeddings (
188
191
modelId : string ,
189
192
ids : string ,
190
193
texts : string ,
191
- ) : string {
194
+ ) : EmbeddingObject [ ] {
192
195
// convert ids to array
193
196
const idArr = JSON . parse < string [ ] > ( ids ) ;
194
197
// convert texts to array
@@ -206,7 +209,7 @@ export function testEmbeddings(
206
209
embedding : response . get ( idArr [ i ] ) ,
207
210
} ) ;
208
211
}
209
- return JSON . stringify ( resultObjs ) ;
212
+ return resultObjs ;
210
213
}
211
214
212
215
export function testTextGenerator (
@@ -254,16 +257,12 @@ class GQLAggregateValues {
254
257
count : u32 = 0 ;
255
258
}
256
259
257
-
258
- @json
259
260
class ClassificationObject {
260
261
id ! : string ;
261
262
text ! : string ;
262
263
result ! : ClassificationResult ;
263
264
}
264
265
265
-
266
- @json
267
266
class EmbeddingObject {
268
267
id ! : string ;
269
268
text ! : string ;
0 commit comments