Repository navigation
Expand file tree
/
Copy pathstarter_batch_node.cpp
More file actions
53 lines (45 loc) · 1.57 KB
/
Copy pathstarter_batch_node.cpp
File metadata and controls
53 lines (45 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <string>
#include "nodes/authoring.h"
namespace llm_edgeflow {
namespace custom_nodes {
namespace starter_batch {
struct Inputs {
const TextBatch* questions = nullptr;
const TextBatch* context = nullptr;
};
struct Models {
LlmCall generator;
};
// 所有请求值都只在这个普通业务函数内使用。
NodeResult<TextBatch> Run(const Inputs& inputs, const Models& models) {
TextBatch prompts;
prompts.reserve(inputs.questions->size());
for (const auto& question : *inputs.questions) {
std::string prompt;
if (inputs.context) {
for (const auto& context : *inputs.context) {
if (context.req_id == question.req_id) prompt += context.data + "\n";
}
}
prompts.emplace_back(question.req_id, question.sub_id,
prompt + question.data);
}
return models.generator.Generate(prompts);
}
auto Spec() {
return MakeNodeSpec(InputsOf<Inputs>({
Required("questions", &Inputs::questions),
Optional("context", &Inputs::context,
InputFlow::AggregateByRequest),
}),
PreservedOutput<TextBatch>("output", "questions"),
ModelsOf<Models>({
Model("generator", "bind_model", &Models::generator),
}),
&Run)
.Description("Batch starter with optional request context");
}
REGISTER_FUNCTION_NODE(starter_batch, Spec());
} // namespace starter_batch
} // namespace custom_nodes
} // namespace llm_edgeflow