@openmeter/sdk 1.0.0-beta.9 → 1.0.0-beta.91
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.
- package/README.md +62 -50
- package/dist/cjs/clients/client.cjs +117 -0
- package/dist/cjs/clients/client.d.cts +40 -0
- package/dist/cjs/clients/client.js.map +1 -0
- package/dist/cjs/clients/event.cjs +71 -0
- package/dist/cjs/clients/event.d.cts +79 -0
- package/dist/cjs/clients/event.js.map +1 -0
- package/dist/cjs/clients/meter.cjs +69 -0
- package/dist/cjs/clients/meter.d.cts +75 -0
- package/dist/cjs/clients/meter.js.map +1 -0
- package/dist/cjs/clients/portal.cjs +41 -0
- package/dist/cjs/clients/portal.d.cts +22 -0
- package/dist/cjs/clients/portal.js.map +1 -0
- package/dist/cjs/clients/subject.cjs +60 -0
- package/dist/cjs/clients/subject.d.cts +27 -0
- package/dist/cjs/clients/subject.js.map +1 -0
- package/dist/cjs/index.cjs +24 -0
- package/dist/cjs/index.d.cts +15 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/schemas/openapi.cjs +7 -0
- package/dist/cjs/schemas/openapi.d.cts +2022 -0
- package/dist/cjs/schemas/openapi.js.map +1 -0
- package/dist/cjs/test/agent.cjs +266 -0
- package/dist/cjs/test/agent.d.cts +2 -0
- package/dist/cjs/test/agent.js.map +1 -0
- package/dist/cjs/test/mocks.cjs +44 -0
- package/dist/cjs/test/mocks.d.cts +14 -0
- package/dist/cjs/test/mocks.js.map +1 -0
- package/dist/cjs/tsconfig.2fd2513a.tsbuildinfo +1 -0
- package/dist/cjs/tsconfig.ba4a040a.tsbuildinfo +1 -0
- package/dist/clients/client.d.ts +1 -1
- package/dist/clients/client.js +9 -1
- package/dist/clients/client.js.map +1 -0
- package/dist/clients/event.d.ts +5 -5
- package/dist/clients/event.js +29 -18
- package/dist/clients/event.js.map +1 -0
- package/dist/clients/meter.d.ts +9 -37
- package/dist/clients/meter.js +1 -15
- package/dist/clients/meter.js.map +1 -0
- package/dist/clients/portal.d.ts +22 -0
- package/dist/clients/portal.js +37 -0
- package/dist/clients/portal.js.map +1 -0
- package/dist/clients/subject.d.ts +27 -0
- package/dist/clients/subject.js +56 -0
- package/dist/clients/subject.js.map +1 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -0
- package/dist/schemas/openapi.d.ts +1729 -246
- package/dist/schemas/openapi.js +1 -0
- package/dist/schemas/openapi.js.map +1 -0
- package/dist/test/agent.js +108 -29
- package/dist/test/agent.js.map +1 -0
- package/dist/test/mocks.d.ts +2 -0
- package/dist/test/mocks.js +9 -0
- package/dist/test/mocks.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +43 -33
- package/dist/next.d.ts +0 -15
- package/dist/next.js +0 -46
- package/index.ts +0 -24
- package/next.ts +0 -76
package/dist/next.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
let encodingForModel;
|
|
2
|
-
export async function createOpenAIStreamCallback({ model, prompts, }, openAIStreamCallbacks) {
|
|
3
|
-
// Tiktoken is an optional dependency, so we import it conditionally
|
|
4
|
-
if (!encodingForModel) {
|
|
5
|
-
const { encodingForModel: encodingForModel_ } = await import('js-tiktoken');
|
|
6
|
-
encodingForModel = encodingForModel_;
|
|
7
|
-
}
|
|
8
|
-
const enc = encodingForModel(model);
|
|
9
|
-
let promptTokens = 0;
|
|
10
|
-
let completionTokens = 0;
|
|
11
|
-
const streamCallbacks = {
|
|
12
|
-
...openAIStreamCallbacks,
|
|
13
|
-
async onStart() {
|
|
14
|
-
for (const content of prompts) {
|
|
15
|
-
const tokens = enc.encode(content);
|
|
16
|
-
promptTokens += tokens.length;
|
|
17
|
-
}
|
|
18
|
-
if (typeof openAIStreamCallbacks?.onStart === 'function') {
|
|
19
|
-
return openAIStreamCallbacks.onStart();
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
async onToken(content) {
|
|
23
|
-
// To test tokenizaton see: https://platform.openai.com/tokenizer
|
|
24
|
-
const tokens = enc.encode(content);
|
|
25
|
-
completionTokens += tokens.length;
|
|
26
|
-
if (typeof openAIStreamCallbacks?.onToken === 'function') {
|
|
27
|
-
return openAIStreamCallbacks.onToken(content);
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
async onFinal(completion) {
|
|
31
|
-
// Mimicking OpenAI usage metadata API
|
|
32
|
-
const usage = {
|
|
33
|
-
total_tokens: promptTokens + completionTokens,
|
|
34
|
-
prompt_tokens: promptTokens,
|
|
35
|
-
completion_tokens: completionTokens,
|
|
36
|
-
};
|
|
37
|
-
if (typeof openAIStreamCallbacks?.onUsage === 'function') {
|
|
38
|
-
await openAIStreamCallbacks.onUsage(usage);
|
|
39
|
-
}
|
|
40
|
-
if (typeof openAIStreamCallbacks?.onFinal === 'function') {
|
|
41
|
-
return openAIStreamCallbacks.onFinal(completion);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
return streamCallbacks;
|
|
46
|
-
}
|
package/index.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { OpenMeterConfig } from './clients/client.js'
|
|
2
|
-
import { EventsClient } from './clients/event.js'
|
|
3
|
-
import { MetersClient } from './clients/meter.js'
|
|
4
|
-
|
|
5
|
-
export { OpenMeterConfig, RequestOptions } from './clients/client.js'
|
|
6
|
-
export { Event } from './clients/event.js'
|
|
7
|
-
export {
|
|
8
|
-
Meter,
|
|
9
|
-
MeterValue,
|
|
10
|
-
MeterAggregation,
|
|
11
|
-
WindowSize,
|
|
12
|
-
} from './clients/meter.js'
|
|
13
|
-
|
|
14
|
-
export { createOpenAIStreamCallback } from './next.js'
|
|
15
|
-
|
|
16
|
-
export class OpenMeter {
|
|
17
|
-
public events: EventsClient
|
|
18
|
-
public meters: MetersClient
|
|
19
|
-
|
|
20
|
-
constructor(config: OpenMeterConfig) {
|
|
21
|
-
this.events = new EventsClient(config)
|
|
22
|
-
this.meters = new MetersClient(config)
|
|
23
|
-
}
|
|
24
|
-
}
|
package/next.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { OpenAIStreamCallbacks } from 'ai'
|
|
2
|
-
import type { TiktokenModel } from 'js-tiktoken'
|
|
3
|
-
|
|
4
|
-
let encodingForModel: (model: TiktokenModel) => any | undefined
|
|
5
|
-
|
|
6
|
-
type OpenAIUsage = {
|
|
7
|
-
total_tokens: number
|
|
8
|
-
prompt_tokens: number
|
|
9
|
-
completion_tokens: number
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
type OpenAIStreamCallbacksWithUsage = OpenAIStreamCallbacks & {
|
|
13
|
-
onUsage?: (usage: OpenAIUsage) => Promise<void> | void
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function createOpenAIStreamCallback(
|
|
17
|
-
{
|
|
18
|
-
model,
|
|
19
|
-
prompts,
|
|
20
|
-
}: {
|
|
21
|
-
model: TiktokenModel
|
|
22
|
-
prompts: string[]
|
|
23
|
-
},
|
|
24
|
-
openAIStreamCallbacks: OpenAIStreamCallbacksWithUsage
|
|
25
|
-
) {
|
|
26
|
-
// Tiktoken is an optional dependency, so we import it conditionally
|
|
27
|
-
if (!encodingForModel) {
|
|
28
|
-
const { encodingForModel: encodingForModel_ } = await import('js-tiktoken')
|
|
29
|
-
encodingForModel = encodingForModel_
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const enc = encodingForModel(model)
|
|
33
|
-
let promptTokens = 0
|
|
34
|
-
let completionTokens = 0
|
|
35
|
-
|
|
36
|
-
const streamCallbacks: OpenAIStreamCallbacks = {
|
|
37
|
-
...openAIStreamCallbacks,
|
|
38
|
-
|
|
39
|
-
async onStart() {
|
|
40
|
-
for (const content of prompts) {
|
|
41
|
-
const tokens = enc.encode(content)
|
|
42
|
-
promptTokens += tokens.length
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (typeof openAIStreamCallbacks?.onStart === 'function') {
|
|
46
|
-
return openAIStreamCallbacks.onStart()
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
async onToken(content) {
|
|
50
|
-
// To test tokenizaton see: https://platform.openai.com/tokenizer
|
|
51
|
-
const tokens = enc.encode(content)
|
|
52
|
-
completionTokens += tokens.length
|
|
53
|
-
|
|
54
|
-
if (typeof openAIStreamCallbacks?.onToken === 'function') {
|
|
55
|
-
return openAIStreamCallbacks.onToken(content)
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
async onFinal(completion: string) {
|
|
59
|
-
// Mimicking OpenAI usage metadata API
|
|
60
|
-
const usage: OpenAIUsage = {
|
|
61
|
-
total_tokens: promptTokens + completionTokens,
|
|
62
|
-
prompt_tokens: promptTokens,
|
|
63
|
-
completion_tokens: completionTokens,
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (typeof openAIStreamCallbacks?.onUsage === 'function') {
|
|
67
|
-
await openAIStreamCallbacks.onUsage(usage)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (typeof openAIStreamCallbacks?.onFinal === 'function') {
|
|
71
|
-
return openAIStreamCallbacks.onFinal(completion)
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
}
|
|
75
|
-
return streamCallbacks
|
|
76
|
-
}
|