@coasys/ad4m 0.10.0 → 0.10.1-dev-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/lib/index.cjs +3785 -843
  2. package/lib/index.js +3777 -839
  3. package/lib/src/Ad4mClient.js +2 -1
  4. package/lib/src/Literal.js +4 -1
  5. package/lib/src/ai/AIClient.d.ts +8 -2
  6. package/lib/src/ai/AIClient.js +25 -14
  7. package/lib/src/ai/AIResolver.d.ts +25 -6
  8. package/lib/src/ai/AIResolver.js +102 -18
  9. package/lib/src/index.d.ts +4 -3
  10. package/lib/src/index.js +4 -3
  11. package/lib/src/model/Ad4mModel.d.ts +730 -0
  12. package/lib/src/model/Ad4mModel.js +1399 -0
  13. package/lib/src/{subject → model}/Subject.d.ts +2 -2
  14. package/lib/src/{subject → model}/Subject.js +18 -18
  15. package/lib/src/model/decorators.d.ts +502 -0
  16. package/lib/src/model/decorators.js +683 -0
  17. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +2 -2
  18. package/lib/src/neighbourhood/NeighbourhoodClient.js +13 -10
  19. package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +2 -2
  20. package/lib/src/neighbourhood/NeighbourhoodProxy.js +4 -4
  21. package/lib/src/neighbourhood/NeighbourhoodProxy.test.d.ts +1 -0
  22. package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +73 -0
  23. package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +2 -2
  24. package/lib/src/neighbourhood/NeighbourhoodResolver.js +6 -4
  25. package/lib/src/perspectives/PerspectiveClient.d.ts +23 -11
  26. package/lib/src/perspectives/PerspectiveClient.js +147 -51
  27. package/lib/src/perspectives/PerspectiveProxy.d.ts +494 -54
  28. package/lib/src/perspectives/PerspectiveProxy.js +684 -67
  29. package/lib/src/perspectives/PerspectiveResolver.d.ts +24 -9
  30. package/lib/src/perspectives/PerspectiveResolver.js +151 -46
  31. package/lib/src/runtime/RuntimeClient.d.ts +8 -2
  32. package/lib/src/runtime/RuntimeClient.js +64 -0
  33. package/lib/src/runtime/RuntimeResolver.d.ts +27 -1
  34. package/lib/src/runtime/RuntimeResolver.js +138 -0
  35. package/lib/src/schema.gql +55 -16
  36. package/lib/src/typeDefs.js +55 -16
  37. package/package.json +4 -3
  38. package/src/Ad4mClient.test.ts +51 -19
  39. package/src/Ad4mClient.ts +3 -1
  40. package/src/Literal.ts +4 -1
  41. package/src/ai/AIClient.ts +35 -14
  42. package/src/ai/AIResolver.ts +78 -16
  43. package/src/index.ts +4 -3
  44. package/src/model/Ad4mModel.ts +1651 -0
  45. package/src/{subject → model}/Subject.ts +16 -16
  46. package/src/{subject/SDNADecorators.ts → model/decorators.ts} +384 -50
  47. package/src/neighbourhood/NeighbourhoodClient.ts +13 -10
  48. package/src/neighbourhood/NeighbourhoodProxy.test.ts +100 -0
  49. package/src/neighbourhood/NeighbourhoodProxy.ts +4 -4
  50. package/src/neighbourhood/NeighbourhoodResolver.ts +2 -2
  51. package/src/perspectives/PerspectiveClient.ts +156 -51
  52. package/src/perspectives/PerspectiveProxy.ts +766 -82
  53. package/src/perspectives/PerspectiveResolver.ts +134 -23
  54. package/src/runtime/RuntimeClient.ts +71 -2
  55. package/src/runtime/RuntimeResolver.ts +91 -1
  56. package/lib/src/subject/SDNADecorators.d.ts +0 -188
  57. package/lib/src/subject/SDNADecorators.js +0 -360
  58. package/lib/src/subject/SubjectEntity.d.ts +0 -102
  59. package/lib/src/subject/SubjectEntity.js +0 -267
  60. package/src/subject/SubjectEntity.ts +0 -315
  61. package/yarn-error.log +0 -90
  62. /package/lib/src/{subject → model}/util.d.ts +0 -0
  63. /package/lib/src/{subject → model}/util.js +0 -0
  64. /package/src/{subject → model}/util.ts +0 -0
@@ -28,8 +28,13 @@ export class AIClient {
28
28
  }
29
29
  local {
30
30
  fileName
31
- tokenizerSource
32
- modelParameters
31
+ tokenizerSource {
32
+ repo
33
+ revision
34
+ fileName
35
+ }
36
+ huggingfaceRepo
37
+ revision
33
38
  }
34
39
  modelType
35
40
  }
@@ -102,8 +107,13 @@ export class AIClient {
102
107
  }
103
108
  local {
104
109
  fileName
105
- tokenizerSource
106
- modelParameters
110
+ tokenizerSource {
111
+ repo
112
+ revision
113
+ fileName
114
+ }
115
+ huggingfaceRepo
116
+ revision
107
117
  }
108
118
  modelType
109
119
  }
@@ -283,15 +293,26 @@ export class AIClient {
283
293
  return decompressed;
284
294
  }
285
295
 
286
- async openTranscriptionStream(modelId: string, streamCallback: (text: string) => void): Promise<string> {
296
+ async openTranscriptionStream(
297
+ modelId: string,
298
+ streamCallback: (text: string) => void,
299
+ params?: {
300
+ startThreshold?: number;
301
+ startWindow?: number;
302
+ endThreshold?: number;
303
+ endWindow?: number;
304
+ timeBeforeSpeech?: number;
305
+ }
306
+ ): Promise<string> {
287
307
  const { aiOpenTranscriptionStream } = unwrapApolloResult(await this.#apolloClient.mutate({
288
308
  mutation: gql`
289
- mutation AiOpenTranscriptionStream($modelId: String!) {
290
- aiOpenTranscriptionStream(modelId: $modelId)
309
+ mutation AiOpenTranscriptionStream($modelId: String!, $params: VoiceActivityParamsInput) {
310
+ aiOpenTranscriptionStream(modelId: $modelId, params: $params)
291
311
  }
292
312
  `,
293
313
  variables: {
294
- modelId
314
+ modelId,
315
+ params
295
316
  }
296
317
  }));
297
318
 
@@ -336,19 +357,19 @@ export class AIClient {
336
357
  return aiCloseTranscriptionStream;
337
358
  }
338
359
 
339
- async feedTranscriptionStream(streamId: string, audio: Float32Array): Promise<void> {
340
- const { feedTranscriptionStream } = unwrapApolloResult(await this.#apolloClient.mutate({
360
+ async feedTranscriptionStream(streamIds: string | string[], audio: Float32Array): Promise<void> {
361
+ const { aiFeedTranscriptionStream } = unwrapApolloResult(await this.#apolloClient.mutate({
341
362
  mutation: gql`
342
- mutation AiFeedTranscriptionStream($streamId: String!, $audio: [Float!]!) {
343
- aiFeedTranscriptionStream(streamId: $streamId, audio: $audio)
363
+ mutation AiFeedTranscriptionStream($streamIds: [String!]!, $audio: [Float!]!) {
364
+ aiFeedTranscriptionStream(streamIds: $streamIds, audio: $audio)
344
365
  }
345
366
  `,
346
367
  variables: {
347
- streamId,
368
+ streamIds: Array.isArray(streamIds) ? streamIds : [streamIds],
348
369
  audio: audio
349
370
  }
350
371
  }));
351
372
 
352
- return feedTranscriptionStream;
373
+ return aiFeedTranscriptionStream;
353
374
  }
354
375
  }
@@ -24,15 +24,30 @@ export class ModelApi {
24
24
  }
25
25
 
26
26
  @ObjectType()
27
- export class LocalModel {
27
+ export class TokenizerSource {
28
28
  @Field()
29
- fileName: string;
29
+ repo: string;
30
30
 
31
31
  @Field()
32
- tokenizerSource: string;
32
+ revision: string;
33
33
 
34
34
  @Field()
35
- modelParameters: string;
35
+ fileName: string;
36
+ }
37
+
38
+ @ObjectType()
39
+ export class LocalModel {
40
+ @Field()
41
+ fileName: string;
42
+
43
+ @Field({ nullable: true })
44
+ tokenizerSource?: TokenizerSource;
45
+
46
+ @Field({ nullable: true })
47
+ huggingfaceRepo?: string;
48
+
49
+ @Field({ nullable: true })
50
+ revision?: string;
36
51
  }
37
52
 
38
53
  export type ModelType = "LLM" | "EMBEDDING" | "TRANSCRIPTION";
@@ -71,15 +86,30 @@ export class ModelApiInput {
71
86
  }
72
87
 
73
88
  @InputType()
74
- export class LocalModelInput {
89
+ export class TokenizerSourceInput {
75
90
  @Field()
76
- fileName: string;
91
+ repo: string;
77
92
 
78
93
  @Field()
79
- tokenizerSource: string;
94
+ revision: string;
80
95
 
81
96
  @Field()
82
- modelParameters: string;
97
+ fileName: string;
98
+ }
99
+
100
+ @InputType()
101
+ export class LocalModelInput {
102
+ @Field()
103
+ fileName: string;
104
+
105
+ @Field({ nullable: true })
106
+ tokenizerSource?: TokenizerSourceInput;
107
+
108
+ @Field({ nullable: true })
109
+ huggingfaceRepo?: string;
110
+
111
+ @Field({ nullable: true })
112
+ revision?: string;
83
113
  }
84
114
 
85
115
  @InputType()
@@ -97,6 +127,24 @@ export class ModelInput {
97
127
  modelType: ModelType;
98
128
  }
99
129
 
130
+ @InputType()
131
+ export class VoiceActivityParamsInput {
132
+ @Field(() => Float, { nullable: true })
133
+ startThreshold?: number;
134
+
135
+ @Field(() => Float, { nullable: true })
136
+ startWindow?: number;
137
+
138
+ @Field(() => Float, { nullable: true })
139
+ endThreshold?: number;
140
+
141
+ @Field(() => Float, { nullable: true })
142
+ endWindow?: number;
143
+
144
+ @Field(() => Float, { nullable: true })
145
+ timeBeforeSpeech?: number;
146
+ }
147
+
100
148
  @Resolver()
101
149
  export default class AIResolver {
102
150
  @Query(returns => [Model])
@@ -113,8 +161,13 @@ export default class AIResolver {
113
161
  },
114
162
  local: {
115
163
  fileName: "test-model.bin",
116
- tokenizerSource: "test-tokenizer",
117
- modelParameters: "{}"
164
+ tokenizerSource: {
165
+ repo: "test-repo",
166
+ revision: "main",
167
+ fileName: "tokenizer.json"
168
+ },
169
+ huggingfaceRepo: "test-repo",
170
+ revision: "main"
118
171
  },
119
172
  modelType: "LLM"
120
173
  }
@@ -165,8 +218,13 @@ export default class AIResolver {
165
218
  },
166
219
  local: {
167
220
  fileName: "test-model.bin",
168
- tokenizerSource: "test-tokenizer",
169
- modelParameters: "{}"
221
+ tokenizerSource: {
222
+ repo: "test-repo",
223
+ revision: "main",
224
+ fileName: "tokenizer.json"
225
+ },
226
+ huggingfaceRepo: "test-repo",
227
+ revision: "main"
170
228
  },
171
229
  modelType: modelType
172
230
  }
@@ -279,7 +337,8 @@ export default class AIResolver {
279
337
 
280
338
  @Mutation(() => String)
281
339
  aiOpenTranscriptionStream(
282
- @Arg("modelId") modelId: string
340
+ @Arg("modelId") modelId: string,
341
+ @Arg("params", () => VoiceActivityParamsInput, { nullable: true }) params?: VoiceActivityParamsInput
283
342
  ): string {
284
343
  return "streamId"
285
344
  }
@@ -293,12 +352,15 @@ export default class AIResolver {
293
352
 
294
353
  @Mutation(() => String)
295
354
  aiFeedTranscriptionStream(
296
- @Arg("streamId") streamId: string,
355
+ @Arg("streamIds", type => [String]) streamIds: string[],
297
356
  @Arg("audio", () => [Float]) audio: number[],
298
357
  @PubSub() pubSub: any
299
358
  ): boolean {
300
- pubSub.publish(AI_TRANSCRIPTION_TEXT_TOPIC, { streamId });
301
- return true
359
+ // Publish for each stream ID
360
+ for (const streamId of streamIds) {
361
+ pubSub.publish(AI_TRANSCRIPTION_TEXT_TOPIC, { streamId });
362
+ }
363
+ return true;
302
364
  }
303
365
 
304
366
  @Subscription({ topics: AI_TRANSCRIPTION_TEXT_TOPIC, nullable: false })
package/src/index.ts CHANGED
@@ -19,14 +19,15 @@ export * from "./perspectives/PerspectiveProxy";
19
19
  export * from "./perspectives/PerspectiveDiff";
20
20
  export * from "./perspectives/LinkQuery";
21
21
  export * from "./SmartLiteral";
22
- export * from "./subject/SDNADecorators";
23
- export * from "./subject/Subject";
22
+ export * from "./model/decorators";
23
+ export * from "./model/Subject";
24
24
  export * from "./neighbourhood/Neighbourhood";
25
25
  export * from "./neighbourhood/NeighbourhoodProxy";
26
26
  export * from "./typeDefs";
27
27
  export * from "./DID";
28
28
  export * from "./utils";
29
- export * from './subject/SubjectEntity'
30
29
  export * from "./agent/AgentClient";
31
30
  export * from "./ai/AIClient"
32
31
  export * from "./ai/Tasks"
32
+ export * from "./runtime/RuntimeResolver"
33
+ export * from './model/Ad4mModel'