@agent-smith/task 0.0.2 → 0.0.3

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.
@@ -62,19 +62,24 @@ interface TaskVariableDef {
62
62
  type: string | Array<string>;
63
63
  description: string;
64
64
  }
65
+ interface TaskOptionalVariableDef extends TaskVariableDef {
66
+ default?: any;
67
+ }
68
+ interface TaskVariables {
69
+ required?: Record<string, TaskVariableDef>;
70
+ optional?: Record<string, TaskOptionalVariableDef>;
71
+ }
65
72
  interface TaskDef {
66
73
  name: string;
67
- description: string;
68
74
  prompt: string;
75
+ description: string;
76
+ model: ModelSpec;
77
+ ctx: number;
69
78
  template?: TemplateSpec;
70
79
  inferParams?: InferenceParams;
71
- model: ModelSpec;
72
80
  models?: Record<string, ModelSpec>;
73
81
  shots?: Array<HistoryTurn>;
74
- variables?: {
75
- required?: Record<string, TaskVariableDef>;
76
- optional?: Record<string, TaskVariableDef>;
77
- };
82
+ variables?: TaskVariables;
78
83
  tools?: Array<ToolSpec>;
79
84
  toolsList?: Array<string>;
80
85
  }
@@ -83,4 +88,4 @@ interface TaskOutput {
83
88
  errors: Record<string, string>;
84
89
  template?: PromptTemplate;
85
90
  }
86
- export { ModelSpec, TaskInput, TaskDef, TemplateSpec, TaskConf, TaskOutput, TaskVariableDef, };
91
+ export { ModelSpec, TaskInput, TaskDef, TemplateSpec, TaskConf, TaskOutput, TaskVariableDef, TaskOptionalVariableDef, TaskVariables, };
package/dist/main.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { Task } from "./task.js";
2
- import { ModelSpec, TaskInput, TaskDef, TemplateSpec, TaskConf, TaskOutput, TaskVariableDef } from "./interfaces.js";
3
- export { Task, ModelSpec, TaskInput, TaskDef, TemplateSpec, TaskConf, TaskOutput, TaskVariableDef, };
2
+ import { ModelSpec, TaskInput, TaskDef, TemplateSpec, TaskConf, TaskOutput, TaskVariableDef, TaskOptionalVariableDef, TaskVariables } from "./interfaces.js";
3
+ export { Task, ModelSpec, TaskInput, TaskDef, TemplateSpec, TaskConf, TaskOutput, TaskVariableDef, TaskOptionalVariableDef, TaskVariables, };
package/dist/task.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ToolSpec } from '@locallm/types';
2
- import { Agent } from "../../agent/dist/agent.js";
2
+ import { Agent } from "@agent-smith/agent";
3
3
  import { TaskConf, TaskDef, TaskInput, TaskOutput } from "./interfaces.js";
4
4
  declare class Task {
5
5
  def: TaskDef;
package/dist/task.js CHANGED
@@ -21,10 +21,14 @@ class Task {
21
21
  throw new Error("Please provide a prompt parameter");
22
22
  }
23
23
  let model = this.def.model;
24
+ let ctx = this.def.ctx;
24
25
  const useTemplates = this.agent.lm.providerType !== "openai";
25
26
  if (conf) {
26
27
  if (conf?.model) {
27
28
  model = conf.model;
29
+ if (model?.ctx) {
30
+ ctx = model.ctx;
31
+ }
28
32
  }
29
33
  if (conf?.modelname) {
30
34
  let found = false;
@@ -33,18 +37,26 @@ class Task {
33
37
  if (modelName == conf.modelname) {
34
38
  found = true;
35
39
  const m = _mod;
40
+ if (m?.ctx) {
41
+ ctx = m.ctx;
42
+ }
36
43
  model = m;
37
44
  break;
38
45
  }
39
46
  }
40
47
  }
41
48
  if (!found) {
42
- throw new Error(`No model found for ${conf.modelname}. Available models:\n${params?.models}`);
49
+ if (this.agent.lm.providerType == "ollama") {
50
+ model = { name: conf.modelname };
51
+ }
52
+ else {
53
+ throw new Error(`No model found for ${conf.modelname}. Available models:\n${params?.models}`);
54
+ }
43
55
  }
44
56
  }
45
57
  }
46
58
  if (this.agent.lm.providerType == "ollama") {
47
- await this.agent.lm.loadModel(model.name, model.ctx);
59
+ await this.agent.lm.loadModel(model.name, ctx);
48
60
  }
49
61
  this.def = applyVariables(this.def, params);
50
62
  let tpl = new PromptTemplate("none");
@@ -72,16 +84,16 @@ class Task {
72
84
  options.tools = agentToolsList;
73
85
  }
74
86
  if (conf?.debug) {
75
- console.log("-----------", model.name, "/", model.template, "-----------");
87
+ console.log("-----------", model.name, "- Template:", tpl.name, "- Ctx:", ctx, "-----------");
76
88
  console.log(finalPrompt);
77
89
  console.log("----------------------------------------------");
78
90
  console.log("Infer params:", this.def.inferParams);
79
91
  console.log("----------------------------------------------");
80
92
  }
81
- if (!this.def.inferParams?.extra) {
82
- this.def.inferParams["extra"] = {};
83
- }
84
93
  if (this.agent.lm.providerType == "ollama") {
94
+ if (!this.def.inferParams?.extra) {
95
+ this.def.inferParams["extra"] = {};
96
+ }
85
97
  // tell Ollama to apply no template
86
98
  this.def.inferParams["extra"]["raw"] = true;
87
99
  }
package/dist/templates.js CHANGED
@@ -2,6 +2,11 @@ import { PromptTemplate } from "modprompt";
2
2
  import { useTemplateForModel } from "@agent-smith/tfm";
3
3
  const tfm = useTemplateForModel();
4
4
  function formatTaskTemplate(taskDef, templateName) {
5
+ //console.log("FTTaskdef", taskDef);
6
+ //console.log("FTTpl", templateName);
7
+ if (!taskDef?.model) {
8
+ throw new Error("Provide a model to run the task " + taskDef.name);
9
+ }
5
10
  if ((!taskDef.model?.template)) {
6
11
  const gt = tfm.guess(taskDef.model.name);
7
12
  if (gt == "none") {
package/dist/variables.js CHANGED
@@ -11,7 +11,8 @@ function applyVariables(taskDef, taskInput) {
11
11
  if (taskDef.variables?.optional) {
12
12
  for (const name of Object.keys(taskDef.variables.optional)) {
13
13
  if (!(name in taskInput)) {
14
- taskDef.prompt = taskDef.prompt.replaceAll(`{${name}}`, "");
14
+ const v = taskDef.variables.optional[name]?.default ?? "";
15
+ taskDef.prompt = taskDef.prompt.replaceAll(`{${name}}`, v);
15
16
  }
16
17
  }
17
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-smith/task",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "A toolkit to create human friendly agents: the language model tasks module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,7 @@
14
14
  "docs": "typedoc --entryPointStrategy expand"
15
15
  },
16
16
  "dependencies": {
17
- "@agent-smith/agent": "^0.0.2",
17
+ "@agent-smith/agent": "^0.0.3",
18
18
  "@agent-smith/tfm": "^0.1.2",
19
19
  "@locallm/api": "0.4.2",
20
20
  "modprompt": "^0.12.0",