@spendgraph/prompt 0.4.0 → 0.6.0

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 (47) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +24 -221
  3. package/dist/budget/budget.d.ts +10 -0
  4. package/dist/budget/budget.js +1 -31
  5. package/dist/budget/errors.js +1 -11
  6. package/dist/budget/index.js +1 -2
  7. package/dist/build/build.d.ts +11 -2
  8. package/dist/build/build.js +1 -57
  9. package/dist/build/index.js +1 -1
  10. package/dist/cache/cache.js +1 -128
  11. package/dist/cache/index.js +1 -1
  12. package/dist/client.d.ts +7 -1
  13. package/dist/client.js +1 -145
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.js +1 -5
  16. package/dist/internals.d.ts +2 -2
  17. package/dist/internals.js +1 -6
  18. package/dist/prompt/bind.js +1 -15
  19. package/dist/prompt/factory.d.ts +1 -1
  20. package/dist/prompt/factory.js +1 -100
  21. package/dist/prompt/index.js +1 -2
  22. package/dist/pull/index.js +1 -1
  23. package/dist/pull/pull.js +1 -19
  24. package/dist/render/index.js +1 -3
  25. package/dist/render/messages.js +1 -14
  26. package/dist/render/system.js +4 -13
  27. package/dist/render/types.js +0 -1
  28. package/dist/render/variables.d.ts +7 -0
  29. package/dist/render/variables.js +1 -20
  30. package/dist/run/across-models.d.ts +11 -1
  31. package/dist/run/across-models.js +1 -5
  32. package/dist/run/concurrency.js +1 -12
  33. package/dist/run/id.js +1 -3
  34. package/dist/run/index.js +1 -5
  35. package/dist/run/once.js +1 -21
  36. package/dist/run/sample.js +1 -28
  37. package/dist/types/dataset.js +0 -1
  38. package/dist/types/index.js +0 -1
  39. package/dist/types/payload.js +0 -1
  40. package/dist/types/prompt.d.ts +1 -1
  41. package/dist/types/prompt.js +0 -1
  42. package/dist/types/result.js +0 -1
  43. package/dist/types/rollout.js +0 -1
  44. package/dist/types/run.js +0 -1
  45. package/dist/types/trace.js +0 -1
  46. package/dist/types/version.js +0 -1
  47. package/package.json +7 -7
package/dist/run/index.js CHANGED
@@ -1,5 +1 @@
1
- export { runAcrossModels } from "./across-models.js";
2
- export { mapLimit } from "./concurrency.js";
3
- export { newRolloutId } from "./id.js";
4
- export { runOnce } from "./once.js";
5
- export { sampleRuns } from "./sample.js";
1
+ import{runAcrossModels as e}from"./across-models.js";import{mapLimit as p}from"./concurrency.js";import{newRolloutId as f}from"./id.js";import{runOnce as s}from"./once.js";import{sampleRuns as l}from"./sample.js";export{p as mapLimit,f as newRolloutId,e as runAcrossModels,s as runOnce,l as sampleRuns};
package/dist/run/once.js CHANGED
@@ -1,21 +1 @@
1
- import { newRolloutId } from "./id.js";
2
- export async function runOnce(prompts, promptId, values, opts = {}, budget) {
3
- budget?.assertAffordable();
4
- const rolloutId = opts.rolloutId ?? newRolloutId();
5
- const res = await prompts.run(promptId, {
6
- rolloutId,
7
- values,
8
- model: opts.model,
9
- temperature: opts.temperature,
10
- maxTokens: opts.maxTokens,
11
- seed: opts.seed ?? 0,
12
- caseId: opts.caseId,
13
- candidateId: opts.candidateId,
14
- parentId: opts.parentId,
15
- generation: opts.generation,
16
- record: opts.record ?? true,
17
- });
18
- if (!res.deduped)
19
- budget?.add(res.rollout.costMicros ?? 0);
20
- return res.rollout;
21
- }
1
+ import{newRolloutId as c}from"./id.js";async function u(a,n,o,e={},d){d?.assertAffordable();const t=e.rolloutId??c(),r=await a.run(n,{rolloutId:t,values:o,model:e.model,temperature:e.temperature,maxTokens:e.maxTokens,seed:e.seed??0,caseId:e.caseId,candidateId:e.candidateId,parentId:e.parentId,generation:e.generation,record:e.record??!0});return r.deduped||d?.add(r.rollout.costMicros??0),r.rollout}export{u as runOnce};
@@ -1,28 +1 @@
1
- import { BudgetExceededError } from "../budget/index.js";
2
- import { mapLimit } from "./concurrency.js";
3
- import { runOnce } from "./once.js";
4
- export async function sampleRuns(prompts, promptId, values, opts = {}, budget) {
5
- const k = Math.max(1, opts.k ?? 5);
6
- const seeds = Array.from({ length: k }, (_, i) => i);
7
- return mapLimit(seeds, opts.concurrency ?? 4, async (seed) => {
8
- try {
9
- return await runOnce(prompts, promptId, values, { ...opts, seed, rolloutId: undefined }, budget);
10
- }
11
- catch (err) {
12
- if (err instanceof BudgetExceededError)
13
- throw err;
14
- return {
15
- id: null,
16
- model: opts.model ?? "",
17
- status: "failed",
18
- output: "",
19
- error: err.message,
20
- costMicros: 0,
21
- latencyMs: 0,
22
- inputTokens: 0,
23
- outputTokens: 0,
24
- seed,
25
- };
26
- }
27
- });
28
- }
1
+ import{BudgetExceededError as m}from"../budget/index.js";import{mapLimit as s}from"./concurrency.js";import{runOnce as d}from"./once.js";async function y(n,o,u,t={},c){const a=Math.max(1,t.k??5),i=Array.from({length:a},(e,r)=>r);return s(i,t.concurrency??4,async e=>{try{return await d(n,o,u,{...t,seed:e,rolloutId:void 0},c)}catch(r){if(r instanceof m)throw r;return{id:null,model:t.model??"",status:"failed",output:"",error:r.message,costMicros:0,latencyMs:0,inputTokens:0,outputTokens:0,seed:e}}})}export{y as sampleRuns};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -6,7 +6,7 @@ import type { Recordable, TraceHandle, TraceOptions, TraceOutcome } from "./trac
6
6
  * Where a prompt came from, and so what a rollout may reference.
7
7
  *
8
8
  * `server` has a row and a version behind it. `custom` was written in code and
9
- * has neither, which is why its `trace` records usage and not a rollout.
9
+ * has neither, which is why its `call` records usage and not a rollout.
10
10
  */
11
11
  export type PromptSource = "server" | "custom";
12
12
  /** A prompt: its fields, its version, and how to run it. */
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
package/dist/types/run.js CHANGED
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@spendgraph/prompt",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Pull a stored prompt or build one in code, render it, and record what it cost.",
5
- "license": "MIT",
5
+ "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/fnLog0/spendgraph.git",
@@ -42,16 +42,16 @@
42
42
  "README.md"
43
43
  ],
44
44
  "scripts": {
45
- "build": "tsc -p tsconfig.json --emitDeclarationOnly && tsc -p tsconfig.json --declaration false --removeComments",
45
+ "build": "rm -rf dist && tsc -p tsconfig.json --emitDeclarationOnly && tsc -p tsconfig.json --declaration false --removeComments && node ../../scripts/minify.mjs dist",
46
46
  "test": "npm run build && vitest run",
47
- "pretest": "npm run build --workspace @spendgraph/tools"
47
+ "pretest": "npm run build --workspace @spendgraph/tools --workspace @spendgraph/llms"
48
48
  },
49
49
  "dependencies": {
50
- "@spendgraph/sdk": "^0.4.0"
50
+ "@spendgraph/sdk": "^0.6.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@spendgraph/llms": "^0.4.0",
54
- "@spendgraph/tools": "^0.4.0",
53
+ "@spendgraph/llms": "^0.6.0",
54
+ "@spendgraph/tools": "^0.6.0",
55
55
  "typescript": "^5"
56
56
  },
57
57
  "engines": {