@j-o-r/hello-dave 0.0.3 → 0.0.4

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 (119) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +216 -56
  3. package/README.md.bak +481 -0
  4. package/README.md.bak.1774780058 +338 -0
  5. package/README.md.bak2 +455 -0
  6. package/docs.bak.1774780058/agent-manager.md +167 -0
  7. package/docs.bak.1774780058/agent-manager.md.bak +137 -0
  8. package/docs.bak.1774780058/agent-manager.md.bak2 +157 -0
  9. package/docs.bak.1774780058/codeserver-pattern.md +191 -0
  10. package/docs.bak.1774780058/path-resolution-best-practices.md +104 -0
  11. package/docs.bak.1774780058/project-overview.md +67 -0
  12. package/docs.bak.1774780058/project-overview.md.bak +67 -0
  13. package/docs.bak.1774780058/prompt-class.md +141 -0
  14. package/docs.bak.1774780058/prompt-class.md.bak +142 -0
  15. package/docs.bak.1774780058/tools-syntax-validation.md +121 -0
  16. package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +125 -0
  17. package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +125 -0
  18. package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +106 -0
  19. package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +106 -0
  20. package/docs.bak.1774780058/toolset.md +164 -0
  21. package/docs.bak.1774780058/toolset.md.bak +94 -0
  22. package/docs.bak.1774780058/toolset.md.bak3 +161 -0
  23. package/docs.bak.1774780058/toolset.md.bak4 +161 -0
  24. package/docs.bak.1774780058/toolset.md.bak5 +161 -0
  25. package/docs.bak.1774780058/toolset.md.bak6 +163 -0
  26. package/docs.bak.1774780058/toolset.md.bak_path +163 -0
  27. package/docs.bak.1774780058/toolset.md.bak_syntax +161 -0
  28. package/docs.bak.1774780058/xai-responses.md +111 -0
  29. package/docs.bak.1774780058/xai-responses.md.bak +107 -0
  30. package/docs.bak.1774780058/xai-responses.md.bak2 +107 -0
  31. package/docs.bak.1774780058/xai_collections.md +106 -0
  32. package/examples/ask_agent.js +137 -0
  33. package/examples/code_agent.js +149 -0
  34. package/examples/coderev_agent.js +136 -0
  35. package/examples/codeserver.sh +47 -0
  36. package/examples/daisy_agent.js +170 -0
  37. package/examples/docs_agent.js +148 -0
  38. package/examples/gpt_agent.js +125 -0
  39. package/examples/grok_agent.js +132 -0
  40. package/examples/grok_agent.js.bak +98 -0
  41. package/examples/grok_agent.js.bak.2 +99 -0
  42. package/examples/grok_agent.js.bak.3 +1 -0
  43. package/examples/grok_agent.js.bak.4 +124 -0
  44. package/examples/grok_agent.js.bak.5 +1 -0
  45. package/examples/grok_agent.js.bak.6 +1 -0
  46. package/examples/memory_agent.js +152 -0
  47. package/examples/npm_agent.js +202 -0
  48. package/examples/npm_agent.js.bak.3 +2 -0
  49. package/examples/npm_agent.js.bak.4 +205 -0
  50. package/examples/npm_agent.js.bak.5 +1 -0
  51. package/examples/npm_agent.js.bak.6 +1 -0
  52. package/examples/prompt_agent.js +133 -0
  53. package/examples/readme_agent.js +148 -0
  54. package/examples/spawn_agent.js +293 -0
  55. package/examples/test_agent.js +187 -0
  56. package/examples/todo_agent.js +175 -0
  57. package/{examples/codeDave.js → examples.bak.1774780058/code_agent.js} +40 -6
  58. package/{examples/CodeServer → examples.bak.1774780058/codeserver.sh} +9 -5
  59. package/examples.bak.1774780058/memory_agent.js +112 -0
  60. package/{examples/spawndave.js → examples.bak.1774780058/spawn_agent.js} +29 -6
  61. package/examples.bak.1774780058/test_agent.js +162 -0
  62. package/{examples/todoDave.js → examples.bak.1774780058/todo_agent.js} +8 -2
  63. package/lib/API/x.ai/responses.js +7 -9
  64. package/lib/AgentManager.js +3 -2
  65. package/lib/AgentServer.js +23 -19
  66. package/lib/genericToolset.js +159 -26
  67. package/lib/genericToolset.js.bak_syntax +402 -0
  68. package/lib/wsCli.js +0 -1
  69. package/package.json +4 -5
  70. package/scenarios.bak.1774780058/data/eval_node_message.json +9 -0
  71. package/scenarios.bak.1774780058/data/hist_oa.json +66 -0
  72. package/scenarios.bak.1774780058/data/o3_response1.json +96 -0
  73. package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +112 -0
  74. package/scenarios.bak.1774780058/data/tool_oa.json +96 -0
  75. package/scenarios.bak.1774780058/data/tool_xai.json +59 -0
  76. package/scenarios.bak.1774780058/data/tool_xai2.json +40 -0
  77. package/scenarios.bak.1774780058/data/xai-response-1.json +59 -0
  78. package/scenarios.bak.1774780058/data/xai-response-2.json +10 -0
  79. package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +59 -0
  80. package/scenarios.bak.1774780058/data/xai_search_response.json +58 -0
  81. package/scenarios.bak.1774780058/environment.js +10 -0
  82. package/scenarios.bak.1774780058/example.js +17 -0
  83. package/scenarios.bak.1774780058/genericToolset.test.js +182 -0
  84. package/scenarios.bak.1774780058/grok.js +113 -0
  85. package/scenarios.bak.1774780058/memory-tools.js +51 -0
  86. package/scenarios.bak.1774780058/openai-o3.js +137 -0
  87. package/scenarios.bak.1774780058/openai-prompt.js +155 -0
  88. package/scenarios.bak.1774780058/openai-session.js +148 -0
  89. package/scenarios.bak.1774780058/openai.js +102 -0
  90. package/scenarios.bak.1774780058/prompt.js +118 -0
  91. package/scenarios.bak.1774780058/promptFishbowl.js +76 -0
  92. package/scenarios.bak.1774780058/search.brave.com.js +25 -0
  93. package/scenarios.bak.1774780058/sh.js +15 -0
  94. package/scenarios.bak.1774780058/test-wsio.js +26 -0
  95. package/scenarios.bak.1774780058/testToolset.js +42 -0
  96. package/scenarios.bak.1774780058/toolset.js +16 -0
  97. package/scenarios.bak.1774780058/toolset.test.js +141 -0
  98. package/scenarios.bak.1774780058/write_file_syntax.test.js +145 -0
  99. package/scenarios.bak.1774780058/write_file_validation/README.md +30 -0
  100. package/scenarios.bak.1774780058/write_file_validation/bad.js +3 -0
  101. package/scenarios.bak.1774780058/write_file_validation/good.js +4 -0
  102. package/scenarios.bak.1774780058/write_file_validation/test.sh +43 -0
  103. package/scenarios.bak.1774780058/wsClient.js +69 -0
  104. package/scenarios.bak.1774780058/xai_responses.integration.test.js +57 -0
  105. package/scenarios.bak.1774780058/xai_responses.test.js +154 -0
  106. package/scenarios.bak.1774780058/xaicoll.js +50 -0
  107. package/scenarios.bak.1774780058/xaifiles.js +48 -0
  108. package/types/AgentManager.d.ts +4 -3
  109. package/utils/syntax_check.sh +61 -0
  110. package/utils/test.sh +46 -0
  111. /package/{examples/askDave.js → examples.bak.1774780058/ask_agent.js} +0 -0
  112. /package/{examples/coderev.js → examples.bak.1774780058/coderev_agent.js} +0 -0
  113. /package/{examples/daisy.js → examples.bak.1774780058/daisy_agent.js} +0 -0
  114. /package/{examples/docsDave.js → examples.bak.1774780058/docs_agent.js} +0 -0
  115. /package/{examples/gpt.js → examples.bak.1774780058/gpt_agent.js} +0 -0
  116. /package/{examples/grok.js → examples.bak.1774780058/grok_agent.js} +0 -0
  117. /package/{examples/npmDave.js → examples.bak.1774780058/npm_agent.js} +0 -0
  118. /package/{examples/promptDave.js → examples.bak.1774780058/prompt_agent.js} +0 -0
  119. /package/{examples/readmeDave.js → examples.bak.1774780058/readme_agent.js} +0 -0
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env node
2
+ import { Test, assert, SH } from '@j-o-r/sh'
3
+ import { generateRequest, parseResponse, request } from '../lib/API/openai.com/reponses/text.js';
4
+ import doRequest from '../lib/request.js';
5
+ import Session from '../lib/Session.js';
6
+ import ToolSet from '../lib/ToolSet.js'
7
+ import Cli from '../lib/Cli.js';
8
+ const SNAME = 'o3TestsSession'
9
+
10
+ const tools = new ToolSet('auto');
11
+ tools.add(
12
+ 'get_current_weather', // name
13
+ 'Get the current weather in a given location', // desciption
14
+ {
15
+ type: 'object',
16
+ properties: {
17
+ location: {
18
+ type: 'string',
19
+ description: 'The city and country'
20
+ }
21
+ },
22
+ required: ["location"]
23
+ },
24
+ async (params) => {
25
+ const records = [];
26
+ const response = {
27
+ location: params.location,
28
+ temperature: 24,
29
+ }
30
+ return { records, response };
31
+ }
32
+ );
33
+
34
+ tools.add(
35
+ 'get_date_time', // name
36
+ 'Get the current date and time', // desciption
37
+ {
38
+ type: 'object',
39
+ properties: {
40
+ }
41
+ },
42
+ async (_params) => {
43
+ const records = [];
44
+ const response = {
45
+ date_time: 'Friday 12 May, 2025. 12:45',
46
+ }
47
+ return { records, response };
48
+ }
49
+ );
50
+
51
+ const test = new Test(true);
52
+ test.add('parse response, toolset roundtrip', async () => {
53
+ // Load a fake reponse
54
+ const session = new Session(SNAME);
55
+ session.empty();
56
+ session.setAdaptor(request, tools, null);
57
+ session.add('system', 'Respond precise and concise', true);
58
+ session.on('message', (m) => {
59
+ console.log('*** message event **');
60
+ console.log(JSON.stringify(m, null, ' '));
61
+ });
62
+ session.on('truncated', (m) => {
63
+ console.log('*** truncated event **');
64
+ console.log(JSON.stringify(m, null, ' '));
65
+ });
66
+ const mes = await session.call('What day is today and what is the weather forecast in Amsterdam, The Netherlands');
67
+ console.log(mes);
68
+ const mesw = await session.call('What day is today and what is the weather forecast in Madrid');
69
+ console.log(mesw);
70
+ // const duration = 1500;
71
+ // const { url, headers, body } = generateRequest(prompt, tools);
72
+ // console.log(body);
73
+ // Create response
74
+ // ----- const res = await doRequest(url, 'POST', headers, body);
75
+ // ----- console.log(JSON.stringify(res, null, ' '));
76
+ // Use response
77
+ // const res = JSON.parse((await SH`cat scenarios/data/o3_response1.json`.run()));
78
+ // // console.log(res);
79
+ // const previousId = res.response.id;
80
+ // await parseResponse(duration, prompt, res, tools);
81
+ // console.log(JSON.stringify(prompt.messages, null, ' '));
82
+ // const lastMessage = prompt.getLastMessage();
83
+ // if (lastMessage.role === 'tool') {
84
+ // // @ts-ignorer
85
+ // const { url, headers, body } = generateRequest(prompt, tools, {previous_response_id: previousId});
86
+ // console.log('------ REQUEST -----');
87
+ // console.log(JSON.stringify(body, null, ' '));
88
+ // const res = await doRequest(url, 'POST', headers, body);
89
+ // console.log('------ RESPONSE -----');
90
+ // console.log(JSON.stringify(res, null, ' '));
91
+ // } else {
92
+ // throw new Error('Should have a tool call')
93
+ // }
94
+ });
95
+
96
+ test.add('Spin up a CLI', async () => {
97
+ const session = new Session(SNAME);
98
+ // prompt.empty();
99
+ session.setAdaptor(request, null, null);
100
+ session.add('system', 'Respond precise and concise', true);
101
+ const cli = new Cli({session})
102
+ cli.start();
103
+ })
104
+
105
+ // @TODO add tools
106
+ test.add('Basic create request body FAKE', async () => {
107
+ const session = new Session(SNAME);
108
+ session.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
109
+ session.add('user', 'What is your task?');
110
+ // Create simple toolset
111
+ const { url, headers, body } = generateRequest(session);
112
+ const res = await doRequest(url, 'POST', headers, body);
113
+ console.log(JSON.stringify(res, null, ' '));
114
+ })
115
+
116
+ test.add('Add a complete toolcall, a real request', async () => {
117
+ const prompt = new Session(SNAME);
118
+ prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
119
+ prompt.add('user', 'What is your task?');
120
+ const options = {
121
+ model: 'o3-mini',
122
+ reasoning: {
123
+ "effort": "medium",
124
+ "summary": "auto"
125
+ }
126
+ }
127
+ // prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
128
+ // prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
129
+ const message = await request(prompt, null, options);
130
+ console.log(message);
131
+ })
132
+
133
+ test.add('Parse reasoning into the prompt', async () => {
134
+
135
+ const res = JSON.parse((await SH`cat scenarios/data/oa_reasoning_parse.json`.run()));
136
+ const prompt = new Session(SNAME);
137
+ prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
138
+ prompt.add('user', 'What is your task?');
139
+ prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
140
+ prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
141
+ const duration = 1500
142
+ await parseResponse(duration, prompt, res, tools);
143
+ // const { url, headers, body } = generateRequest(prompt, tools);
144
+ // console.log( JSON.stringify(body, null, ' '));
145
+ console.log( JSON.stringify(prompt.messages, null, ' '));
146
+ });
147
+
148
+ await test.run([1]);
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+ import { Test, assert, SH } from '@j-o-r/sh'
3
+ import { generateRequest, parseResponse, request } from '../lib/LLMS/openai.com/reponses/text.js';
4
+ import doRequest from '../lib/request.js';
5
+ import Prompt from '../lib/Prompt.js';
6
+ import ToolSet from '../lib/ToolSet.js'
7
+
8
+ /*
9
+
10
+ ## TODO
11
+
12
+ * try out a vision model
13
+ - Prompt an image
14
+ * try audio transcription
15
+ - Extend prompt with AUDIO messages
16
+
17
+ * try openai websearch (internal toolcall)
18
+
19
+ */
20
+
21
+ // Generic TEST toolset
22
+ const tools = new ToolSet('auto');
23
+ tools.add(
24
+ 'get_current_weather', // name
25
+ 'Get the current weather in a given location', // desciption
26
+ {
27
+ type: 'object',
28
+ properties: {
29
+ location: {
30
+ type: 'string',
31
+ description: 'The city and country'
32
+ }
33
+ },
34
+ required: ["location"]
35
+ },
36
+ async (params) => {
37
+ const records = [];
38
+ const response = {
39
+ location: params.location,
40
+ temperature: 24,
41
+ }
42
+ return { records, response };
43
+ }
44
+ );
45
+
46
+ tools.add(
47
+ 'get_date_time', // name
48
+ 'Get the current date and time', // desciption
49
+ {
50
+ type: 'object',
51
+ properties: {
52
+ }
53
+ },
54
+ async (_params) => {
55
+ const records = [];
56
+ const response = {
57
+ date_time: 'Friday 12 May, 2025. 12:45',
58
+ }
59
+ return { records, response };
60
+ }
61
+ );
62
+
63
+ const test = new Test();
64
+ test.add('parse response, create request FAKE ', async () => {
65
+ // Load a fake reponse
66
+ const res = JSON.parse((await SH`cat scenarios/data/tool_oa.json`.run()));
67
+ const prompt = new Prompt();
68
+ prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
69
+ prompt.add('user', 'What is your task?');
70
+ prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
71
+ prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
72
+ const duration = 1500
73
+ await parseResponse(duration, prompt, res, tools);
74
+ const lastMessage = prompt.getLastMessage();
75
+ // console.log(lastMessage);
76
+ const { url, headers, body } = generateRequest(prompt, tools);
77
+ console.log( JSON.stringify(body, null, ' '));
78
+ });
79
+
80
+ // @TODO add tools
81
+ test.add('Basic create request body FAKE', async () => {
82
+ const prompt = new Prompt();
83
+ prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
84
+ prompt.add('user', 'What is your task?');
85
+ // Create simple toolset
86
+ const { url, headers, body } = generateRequest(prompt);
87
+ const res = await doRequest(url, 'POST', headers, body);
88
+ console.log(JSON.stringify(res, null, ' '));
89
+ })
90
+
91
+ test.add('Add a complete toolcall, a real request', async () => {
92
+ const prompt = new Prompt();
93
+ prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
94
+ prompt.add('user', 'What is your task?');
95
+ prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
96
+ prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
97
+ const message = await request(prompt, tools);
98
+ console.log(message);
99
+ })
100
+
101
+
102
+ await test.run([2]);
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+ import { assert, Test } from '@j-o-r/sh';
3
+ import Prompt from '../lib/Prompt.js';
4
+
5
+ const isNpm = process.env.npm_lifecycle_event ? true : false;
6
+ const test = new Test(isNpm);
7
+
8
+ test.add('Generic usages', async () => {
9
+ const prompt = new Prompt(6000);
10
+ prompt.add('system', 'systemprompt', true);
11
+ prompt.add('user', 'Hello');
12
+ prompt.add('assistant', 'Hi');
13
+ assert.equal(prompt.length, 3);
14
+ prompt.reset();
15
+ assert.equal(prompt.length, 1);
16
+ });
17
+ test.add('Multimodal', async () => {
18
+ const m = new Prompt(6000);
19
+ assert.equal(m.hasSystemprompt, false, 'Does not have a system prompt');
20
+ m.addMultiModal('system', [{ type: 'text', text: 'This is my sys prompt' }], true)
21
+ assert.equal(m.hasSystemprompt, true, 'Yes, we have');
22
+ m.add('user', 'What is this doing.\nMulti line example\n');
23
+ // Ad a question about an image
24
+ m.addMultiModal('user', [{ type: 'text', text: 'what about this image?' }, { type: 'image_url', url: 'http://www.example.com/image.png' }]);
25
+ assert.equal(m.length, 3, 'We have 2 messages');
26
+ const ar = m.messages;
27
+ const m2 = new Prompt(3000);
28
+ m2.import(ar);
29
+ assert.equal(m2.length, 3, 'We have 3 messages');
30
+ const ar2 = m2.messages;
31
+ // console.log(yam2);
32
+ assert.equal(ar.length, ar2.length);
33
+ assert.equal(m.system_prompt, 'This is my sys prompt');
34
+ });
35
+ test.add('Multimodal errors', async () => {
36
+ const m = new Prompt(4000);
37
+ m.addMultiModal('system', [{ type: 'text', text: 'This is my question' }], true)
38
+ assert.throws(() => {
39
+ // unkown message type 'what'
40
+ m.addMultiModal('user', [{ type: 'text', text: 'This is my question' }, { type: 'what', text: 'This is my question' }]);
41
+ });
42
+ });
43
+
44
+ test.add('Function calls and responses', async () => {
45
+ const prompt = new Prompt(2000);
46
+ prompt.add('system', 'You are an unpolite assistant named Petronela for an administrative office. Respond precise and concise', true);
47
+ prompt.add('user', 'Wat is the temperatuur in Den Haag');
48
+ /** @type {import('../lib/Prompt.js').PRFunctionRequest} */
49
+ const fr = {
50
+ type: 'function_request',
51
+ function_request: {
52
+ name: 'get_current_weather',
53
+ id: 'call_zXFv3espCtpa3zfEu9ElOkJw',
54
+ parameters: "{\"location\":\"Den·Haag\",\"unit\":\"celsius\"}"
55
+ }
56
+ }
57
+ prompt.addMultiModal('assistant', [fr]);
58
+ /** @type {import('../lib/Prompt.js').PRFunctionResponse} */
59
+ const res = {
60
+ type: 'function_response',
61
+ function_response: {
62
+ name: 'get_current_weather',
63
+ id: 'call_zXFv3espCtpa3zfEu9ElOkJw',
64
+ response: "{\"temperature\":24}"
65
+ }
66
+ }
67
+ prompt.addMultiModal('tool', [res]);
68
+ prompt.add('assistant', 'Het is 24 graden Celsius in Den Haag.');
69
+ assert.equal(prompt.length, 5);
70
+ prompt.reset();
71
+ assert.equal(prompt.length, 1);
72
+ });
73
+
74
+ test.add('add records', async () => {
75
+ const prompt = new Prompt();
76
+ /** @type {import('types/Prompt.js').PRRecord} */
77
+ const record = {
78
+ id: 'test 1',
79
+ isoDate: new Date().toISOString(),
80
+ duration: 10,
81
+ model: 'prompt test',
82
+ environment: 'scenario',
83
+ tokensIn: 0,
84
+ tokensOut: 100
85
+ };
86
+ prompt.addRecord(record);
87
+ assert.equal(prompt.records.length, 1);
88
+ const records = prompt.resetRecords();
89
+ assert.equal(prompt.records.length, 0);
90
+ assert.equal(JSON.stringify(record), JSON.stringify(records[0]));
91
+ // register multple records at once
92
+ prompt.addRecords(records);
93
+ assert.equal(prompt.records.length, 1);
94
+ });
95
+
96
+ test.add('invalid record', async () => {
97
+ assert.throws(() => {
98
+ const m = new Prompt();
99
+ // @ts-ignore
100
+ m.addRecord({ id: 'Fake' });
101
+ });
102
+ });
103
+
104
+ test.add('test message Event', () => {
105
+ return new Promise((resolve, _reject) => {
106
+ const prompt = new Prompt(6000);
107
+ prompt.on(prompt.EVENTS.message, (msg) => {
108
+ assert.strictEqual(msg.role, 'system');
109
+ resolve();
110
+ })
111
+ prompt.add('system', 'systemprompt', true);
112
+ })
113
+ })
114
+
115
+ const report = await test.run();
116
+ if (report.errors > 0) {
117
+ process.exit(1);
118
+ }
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env node
2
+ import {assert, Test } from '@j-o-r/sh';
3
+ import Prompt from '../lib/Prompt.js';
4
+
5
+ const isNpm = process.env.npm_lifecycle_event ? true : false;
6
+ const test = new Test(isNpm);
7
+ const createText = (text, nr) => {
8
+ let result = '';
9
+ const len = nr;
10
+ let i = 0;
11
+ for(;i < len; i++) {
12
+ result += `${text} `;
13
+ }
14
+ return result;
15
+ }
16
+
17
+ test.add('Create a 500 tokens prompt', async () => {
18
+ const prompt = new Prompt(500);
19
+ prompt.add('system', createText('system', 50), true); // 0
20
+ prompt.add('user', createText('user', 50), true); // 1
21
+ prompt.add('assistant', 'yes', true); // 2
22
+ prompt.add('user', createText('user2', 50)); // 3
23
+ prompt.add('assistant', createText('assistant 2', 100)); // 4
24
+ prompt.add('user', createText('user3', 50)); // 5
25
+ prompt.add('assistant', createText('assistant 3', 100)); // 6
26
+ prompt.add('user', createText('user 4', 50)); // 7
27
+ prompt.add('assistant', createText('assistant 4', 100)); // 8
28
+ assert.equal(prompt.length, 9);
29
+ const reduced = prompt.truncate();
30
+ assert.equal(prompt.length, 5);
31
+ assert.equal(reduced, true);
32
+ assert.equal(prompt.contextLength, 500);
33
+ });
34
+
35
+
36
+ test.add('Create a 500 tokens prompt with function calls',async () => {
37
+ const prompt = new Prompt(500);
38
+ prompt.add('system', createText('system', 50), true); // 0
39
+ prompt.add('user', createText('user', 50), true); // 1
40
+ prompt.add('assistant', 'yes', true); // 2
41
+ prompt.add('user', 'Wat is the temperatuur in Den Haag');
42
+ /** @type {import('../lib/Prompt.js').PRFunctionRequest} */
43
+ const fr = {
44
+ type: 'function_request',
45
+ function_request: {
46
+ name: 'get_current_weather',
47
+ id: 'call_zXFv3espCtpa3zfEu9ElOkJw',
48
+ parameters: "{\"location\":\"Den·Haag\",\"unit\":\"celsius\"}"
49
+ }
50
+ }
51
+ prompt.addMultiModal('assistant', [fr]);
52
+ /** @type {import('../lib/Prompt.js').PRFunctionResponse} */
53
+ const res = {
54
+ type: 'function_response',
55
+ function_response: {
56
+ name: 'get_current_weather',
57
+ id: 'call_zXFv3espCtpa3zfEu9ElOkJw',
58
+ response: "{\"temperature\":24}"
59
+ }
60
+ }
61
+ prompt.addMultiModal('tool', [res]);
62
+ prompt.add('assistant', 'Het is 24 graden Celsius in Den Haag.');
63
+ prompt.add('user', createText('user2', 50)); // 3
64
+ prompt.add('assistant', createText('assistant 2', 100)); // 4
65
+ prompt.add('user', createText('user3', 50)); // 5
66
+ prompt.add('assistant', createText('assistant 3', 100)); // 6
67
+ prompt.add('user', createText('user 4', 50)); // 7
68
+ prompt.add('assistant', createText('assistant 4', 100)); // 8
69
+ prompt.truncate();
70
+ assert.equal(prompt.length, 5);
71
+ });
72
+
73
+ const report = await test.run();
74
+ if (report.errors > 0) {
75
+ process.exit(1);
76
+ }
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ import { Test, assert } from '@j-o-r/sh'
3
+ import {request} from '../lib/API/brave.com/search.js';
4
+
5
+ const test = new Test();
6
+
7
+ test.add('simple brave search', async () => {
8
+ /** @type {import('../lib/search/brave.com/index.js').BRSearchOptions} */
9
+ const options = {search_lang: 'nl', summary: 1, count: 3};
10
+ const res = await request('What is the most populair behringer synth?', options);
11
+ console.log(res);
12
+ })
13
+
14
+ test.add('extended simple brave search', async () => {
15
+ /** @type {import('../lib/search/brave.com/search.js').BRSearchOptions} */
16
+ // const options = {
17
+ // summary: 1,
18
+ // count: 6,
19
+ // freshness: 'py',
20
+ // result_filter: ''
21
+ // }
22
+ const res = await request('"openapi doc" "openai response models" API calls');
23
+ console.log(res);
24
+ })
25
+ await test.run([0]);
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ import {SH} from '@j-o-r/sh'; // Note: relative path
3
+
4
+
5
+ async function main() {
6
+ try {
7
+ const res = await SH`node --check bin/dave.js`.run()
8
+ console.log(res);
9
+ } catch (error) {
10
+ console.log('------ error ------');
11
+ console.error(error)
12
+ }
13
+ }
14
+
15
+ main();
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ import wsio from './lib/wsIO.js'; // Note: relative path
3
+
4
+ const connectionUrl = 'ws://localhost:8080/ws'; // Your server
5
+ const secret = '123'; // Or your secret
6
+
7
+ async function main() {
8
+ try {
9
+ console.log('=== User Input ===');
10
+ const inputResp = await wsio(connectionUrl, secret, 'user_request', 'Hello, what is the date?');
11
+ console.log(inputResp);
12
+
13
+ console.log('\n=== Server Info ===');
14
+ const infoResp = await wsio(connectionUrl, secret, 'user_info');
15
+ console.log(infoResp);
16
+
17
+ console.log('\n=== Reset ===');
18
+ const resetResp = await wsio(connectionUrl, secret, 'user_reset');
19
+ console.log(resetResp);
20
+ } catch (error) {
21
+ console.error('Error:', error.message);
22
+ process.exit(1);
23
+ }
24
+ }
25
+
26
+ main();
@@ -0,0 +1,42 @@
1
+ import ToolSet from '../lib/ToolSet.js'
2
+ // Generic TEST toolset
3
+ const tools = new ToolSet('auto');
4
+ tools.add(
5
+ 'get_current_weather', // name
6
+ 'Get the current weather in a given location', // desciption
7
+ {
8
+ type: 'object',
9
+ properties: {
10
+ location: {
11
+ type: 'string',
12
+ description: 'The city and country'
13
+ }
14
+ },
15
+ required: ["location"]
16
+ },
17
+ async (params) => {
18
+ if (params.location.trim() === '') {
19
+ throw new Error('Missing location.');
20
+ // return { records, response };
21
+ }
22
+ const response = {current_weather:'24 C, Cloudy'};
23
+ return response;
24
+ }
25
+ );
26
+ tools.add(
27
+ 'get_date_time', // name
28
+ 'Get the current date and time', // desciption
29
+ {
30
+ type: 'object',
31
+ properties: {
32
+ }
33
+ },
34
+ async (_params) => {
35
+ const response = {
36
+ date_time: new Date().toISOString(),
37
+ }
38
+ return response;
39
+ }
40
+ );
41
+
42
+ export default tools;
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ import { Test , assert} from '@j-o-r/sh'
3
+ // import ToolSet from '../lib/ToolSet.js'
4
+ import tools from './testToolset.js';
5
+ const test = new Test();
6
+ test.add('Basic', async () => {
7
+ assert.equal(tools.has('get_current_weather'), true);
8
+ assert.equal(tools.has('i_am_not_here'), false);
9
+ const ob = await tools.call('get_current_weather', { location: 'Den haag' })
10
+ assert.equal(ob.current_weather, '24 C, Cloudy')
11
+ const list = tools.list();
12
+ assert.equal(list.length, 2);
13
+ assert.equal(list[0].name, 'get_current_weather');;
14
+ });
15
+
16
+ await test.run();