@nine-lab/nine-ux 0.1.263 → 0.1.265
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/dist/nine-ux.js +15054 -2
- package/dist/nine-ux.umd.js +89 -2250
- package/package.json +1 -1
- package/dist/few_shot-BSabkxp9.js +0 -132
- package/dist/index-B0j2a9bx.js +0 -89660
package/package.json
CHANGED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { B as p, c as n, r as o, P as u } from "./index-B0j2a9bx.js";
|
|
2
|
-
class l extends p {
|
|
3
|
-
constructor(e) {
|
|
4
|
-
if (super(e), Object.defineProperty(this, "lc_serializable", {
|
|
5
|
-
enumerable: !0,
|
|
6
|
-
configurable: !0,
|
|
7
|
-
writable: !0,
|
|
8
|
-
value: !1
|
|
9
|
-
}), Object.defineProperty(this, "examples", {
|
|
10
|
-
enumerable: !0,
|
|
11
|
-
configurable: !0,
|
|
12
|
-
writable: !0,
|
|
13
|
-
value: void 0
|
|
14
|
-
}), Object.defineProperty(this, "exampleSelector", {
|
|
15
|
-
enumerable: !0,
|
|
16
|
-
configurable: !0,
|
|
17
|
-
writable: !0,
|
|
18
|
-
value: void 0
|
|
19
|
-
}), Object.defineProperty(this, "examplePrompt", {
|
|
20
|
-
enumerable: !0,
|
|
21
|
-
configurable: !0,
|
|
22
|
-
writable: !0,
|
|
23
|
-
value: void 0
|
|
24
|
-
}), Object.defineProperty(this, "suffix", {
|
|
25
|
-
enumerable: !0,
|
|
26
|
-
configurable: !0,
|
|
27
|
-
writable: !0,
|
|
28
|
-
value: ""
|
|
29
|
-
}), Object.defineProperty(this, "exampleSeparator", {
|
|
30
|
-
enumerable: !0,
|
|
31
|
-
configurable: !0,
|
|
32
|
-
writable: !0,
|
|
33
|
-
value: `
|
|
34
|
-
|
|
35
|
-
`
|
|
36
|
-
}), Object.defineProperty(this, "prefix", {
|
|
37
|
-
enumerable: !0,
|
|
38
|
-
configurable: !0,
|
|
39
|
-
writable: !0,
|
|
40
|
-
value: ""
|
|
41
|
-
}), Object.defineProperty(this, "templateFormat", {
|
|
42
|
-
enumerable: !0,
|
|
43
|
-
configurable: !0,
|
|
44
|
-
writable: !0,
|
|
45
|
-
value: "f-string"
|
|
46
|
-
}), Object.defineProperty(this, "validateTemplate", {
|
|
47
|
-
enumerable: !0,
|
|
48
|
-
configurable: !0,
|
|
49
|
-
writable: !0,
|
|
50
|
-
value: !0
|
|
51
|
-
}), Object.assign(this, e), this.examples !== void 0 && this.exampleSelector !== void 0)
|
|
52
|
-
throw new Error("Only one of 'examples' and 'example_selector' should be provided");
|
|
53
|
-
if (this.examples === void 0 && this.exampleSelector === void 0)
|
|
54
|
-
throw new Error("One of 'examples' and 'example_selector' should be provided");
|
|
55
|
-
if (this.validateTemplate) {
|
|
56
|
-
let t = this.inputVariables;
|
|
57
|
-
this.partialVariables && (t = t.concat(Object.keys(this.partialVariables))), n(this.prefix + this.suffix, this.templateFormat, t);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
_getPromptType() {
|
|
61
|
-
return "few_shot";
|
|
62
|
-
}
|
|
63
|
-
static lc_name() {
|
|
64
|
-
return "FewShotPromptTemplate";
|
|
65
|
-
}
|
|
66
|
-
async getExamples(e) {
|
|
67
|
-
if (this.examples !== void 0)
|
|
68
|
-
return this.examples;
|
|
69
|
-
if (this.exampleSelector !== void 0)
|
|
70
|
-
return this.exampleSelector.selectExamples(e);
|
|
71
|
-
throw new Error("One of 'examples' and 'example_selector' should be provided");
|
|
72
|
-
}
|
|
73
|
-
async partial(e) {
|
|
74
|
-
const t = this.inputVariables.filter((i) => !(i in e)), a = {
|
|
75
|
-
...this.partialVariables ?? {},
|
|
76
|
-
...e
|
|
77
|
-
}, r = {
|
|
78
|
-
...this,
|
|
79
|
-
inputVariables: t,
|
|
80
|
-
partialVariables: a
|
|
81
|
-
};
|
|
82
|
-
return new l(r);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Formats the prompt with the given values.
|
|
86
|
-
* @param values The values to format the prompt with.
|
|
87
|
-
* @returns A promise that resolves to a string representing the formatted prompt.
|
|
88
|
-
*/
|
|
89
|
-
async format(e) {
|
|
90
|
-
const t = await this.mergePartialAndUserVariables(e), a = await this.getExamples(t), r = await Promise.all(a.map((s) => this.examplePrompt.format(s))), i = [this.prefix, ...r, this.suffix].join(this.exampleSeparator);
|
|
91
|
-
return o(i, this.templateFormat, t);
|
|
92
|
-
}
|
|
93
|
-
serialize() {
|
|
94
|
-
if (this.exampleSelector || !this.examples)
|
|
95
|
-
throw new Error("Serializing an example selector is not currently supported");
|
|
96
|
-
if (this.outputParser !== void 0)
|
|
97
|
-
throw new Error("Serializing an output parser is not currently supported");
|
|
98
|
-
return {
|
|
99
|
-
_type: this._getPromptType(),
|
|
100
|
-
input_variables: this.inputVariables,
|
|
101
|
-
example_prompt: this.examplePrompt.serialize(),
|
|
102
|
-
example_separator: this.exampleSeparator,
|
|
103
|
-
suffix: this.suffix,
|
|
104
|
-
prefix: this.prefix,
|
|
105
|
-
template_format: this.templateFormat,
|
|
106
|
-
examples: this.examples
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
static async deserialize(e) {
|
|
110
|
-
const { example_prompt: t } = e;
|
|
111
|
-
if (!t)
|
|
112
|
-
throw new Error("Missing example prompt");
|
|
113
|
-
const a = await u.deserialize(t);
|
|
114
|
-
let r;
|
|
115
|
-
if (Array.isArray(e.examples))
|
|
116
|
-
r = e.examples;
|
|
117
|
-
else
|
|
118
|
-
throw new Error("Invalid examples format. Only list or string are supported.");
|
|
119
|
-
return new l({
|
|
120
|
-
inputVariables: e.input_variables,
|
|
121
|
-
examplePrompt: a,
|
|
122
|
-
examples: r,
|
|
123
|
-
exampleSeparator: e.example_separator,
|
|
124
|
-
prefix: e.prefix,
|
|
125
|
-
suffix: e.suffix,
|
|
126
|
-
templateFormat: e.template_format
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
export {
|
|
131
|
-
l as FewShotPromptTemplate
|
|
132
|
-
};
|