Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit eb36622

Browse files
Un-stringify examples (#58)
1 parent add98d8 commit eb36622

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

examples/hmplugin1/assembly/index.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function getPeople(): Person[] {
2525
return people;
2626
}
2727

28-
export function queryPeople1(): string {
28+
export function queryPeople1(): Person[] {
2929
const query = `
3030
{
3131
people(func: type(Person)) {
@@ -39,13 +39,13 @@ export function queryPeople1(): string {
3939
const response = dql.query<PeopleData>(query);
4040
const people = response.data.people;
4141
people.forEach((p) => p.updateFullName());
42-
return JSON.stringify(people);
42+
return people;
4343
}
4444

4545
export function queryPeopleWithVars(
4646
firstName: string,
4747
lastName: string,
48-
): string {
48+
): Person[] {
4949
const query = `
5050
query peopleWithVars($firstName: string, $lastName: string) {
5151
people(func: eq(Person.firstName, $firstName)) @filter(eq(Person.lastName, $lastName)) {
@@ -63,10 +63,10 @@ export function queryPeopleWithVars(
6363
const response = dql.query<PeopleData>(query, parameters);
6464
const people = response.data.people;
6565
people.forEach((p) => p.updateFullName());
66-
return JSON.stringify(people);
66+
return people;
6767
}
6868

69-
export function queryPeople2(): string {
69+
export function queryPeople2(): Person[] {
7070
const statement = `
7171
query {
7272
people: queryPerson {
@@ -87,7 +87,7 @@ export function queryPeople2(): string {
8787
console.log(`End: ${tracing.endTime.toISOString()}`);
8888
console.log(`Duration: ${duration}ms`);
8989

90-
return JSON.stringify(results.data.people);
90+
return results.data.people;
9191
}
9292

9393
export function newPerson1(firstName: string, lastName: string): string {
@@ -151,15 +151,18 @@ export function getRandomPerson(): Person {
151151
return results.data.people[0];
152152
}
153153

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);
156159
}
157160

158161
export function testMultipleClassifier(
159162
modelId: string,
160163
ids: string,
161164
texts: string,
162-
): string {
165+
): ClassificationObject[] {
163166
// convert ids to array
164167
const idArr = JSON.parse<string[]>(ids);
165168
// convert texts to array
@@ -177,18 +180,18 @@ export function testMultipleClassifier(
177180
result: response.get(idArr[i]),
178181
});
179182
}
180-
return JSON.stringify(resultObjs);
183+
return resultObjs;
181184
}
182185

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);
185188
}
186189

187190
export function testEmbeddings(
188191
modelId: string,
189192
ids: string,
190193
texts: string,
191-
): string {
194+
): EmbeddingObject[] {
192195
// convert ids to array
193196
const idArr = JSON.parse<string[]>(ids);
194197
// convert texts to array
@@ -206,7 +209,7 @@ export function testEmbeddings(
206209
embedding: response.get(idArr[i]),
207210
});
208211
}
209-
return JSON.stringify(resultObjs);
212+
return resultObjs;
210213
}
211214

212215
export function testTextGenerator(
@@ -254,16 +257,12 @@ class GQLAggregateValues {
254257
count: u32 = 0;
255258
}
256259

257-
258-
@json
259260
class ClassificationObject {
260261
id!: string;
261262
text!: string;
262263
result!: ClassificationResult;
263264
}
264265

265-
266-
@json
267266
class EmbeddingObject {
268267
id!: string;
269268
text!: string;

0 commit comments

Comments
 (0)