@syntheticlab/synbad 0.0.4 → 0.0.6

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 (58) hide show
  1. package/README.md +111 -26
  2. package/dist/evals/reasoning/multiturn-reasoning-parsing.d.ts +2 -2
  3. package/dist/evals/reasoning/multiturn-reasoning-parsing.js +2 -2
  4. package/dist/evals/reasoning/reasoning-claude-tool-call.d.ts +2 -2
  5. package/dist/evals/reasoning/reasoning-claude-tool-call.js +1 -2
  6. package/dist/evals/reasoning/reasoning-parsing.d.ts +2 -2
  7. package/dist/evals/reasoning/reasoning-parsing.js +4 -4
  8. package/dist/evals/reasoning/response-in-reasoning.d.ts +45 -0
  9. package/dist/evals/reasoning/response-in-reasoning.js +59 -0
  10. package/dist/evals/tools/claude-dash.d.ts +2 -2
  11. package/dist/evals/tools/claude-dash.js +1 -2
  12. package/dist/evals/tools/crush-list-files.d.ts +2 -5
  13. package/dist/evals/tools/crush-list-files.js +6 -8
  14. package/dist/evals/tools/multi-turn-tools.d.ts +46 -0
  15. package/dist/evals/tools/multi-turn-tools.js +100 -0
  16. package/dist/evals/tools/no-fn-args.d.ts +22 -0
  17. package/dist/evals/tools/no-fn-args.js +31 -0
  18. package/dist/evals/tools/octo-list-no-optional-args.d.ts +209 -0
  19. package/dist/evals/tools/octo-list-no-optional-args.js +73 -0
  20. package/dist/evals/tools/parallel-tool.d.ts +2 -2
  21. package/dist/evals/tools/parallel-tool.js +1 -2
  22. package/dist/evals/tools/simple-tool.d.ts +2 -2
  23. package/dist/evals/tools/simple-tool.js +3 -2
  24. package/dist/evals/tools/tool-dash-underscore.d.ts +26 -0
  25. package/dist/evals/tools/tool-dash-underscore.js +37 -0
  26. package/dist/evals/tools/tool-path-corruption.d.ts +26 -0
  27. package/dist/evals/tools/tool-path-corruption.js +41 -0
  28. package/dist/source/asserts.d.ts +4 -1
  29. package/dist/source/asserts.js +36 -0
  30. package/dist/source/chat-completion.d.ts +5 -0
  31. package/dist/source/chat-completion.js +1 -0
  32. package/dist/source/evals.d.ts +9 -0
  33. package/dist/source/evals.js +53 -0
  34. package/dist/source/evals.test.d.ts +1 -0
  35. package/dist/source/evals.test.js +12 -0
  36. package/dist/source/exports.d.ts +2 -0
  37. package/dist/source/exports.js +1 -0
  38. package/dist/source/index.js +204 -38
  39. package/evals/reasoning/multiturn-reasoning-parsing.ts +3 -3
  40. package/evals/reasoning/reasoning-claude-tool-call.ts +2 -3
  41. package/evals/reasoning/reasoning-parsing.ts +5 -5
  42. package/evals/reasoning/response-in-reasoning.ts +65 -0
  43. package/evals/tools/claude-dash.ts +2 -3
  44. package/evals/tools/crush-list-files.ts +11 -13
  45. package/evals/tools/multi-turn-tools.ts +104 -0
  46. package/evals/tools/no-fn-args.ts +34 -0
  47. package/evals/tools/octo-list-no-optional-args.ts +81 -0
  48. package/evals/tools/parallel-tool.ts +2 -3
  49. package/evals/tools/simple-tool.ts +4 -3
  50. package/evals/tools/tool-dash-underscore.ts +40 -0
  51. package/evals/tools/tool-path-corruption.ts +46 -0
  52. package/package.json +10 -3
  53. package/source/asserts.ts +37 -1
  54. package/source/chat-completion.ts +6 -0
  55. package/source/evals.test.ts +13 -0
  56. package/source/evals.ts +56 -0
  57. package/source/exports.ts +2 -0
  58. package/source/index.ts +246 -38
@@ -7,10 +7,13 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
7
7
  }
8
8
  return path;
9
9
  };
10
- import { Command } from "@commander-js/extra-typings";
11
- import fs from "fs/promises";
10
+ import * as http from "http";
11
+ import * as https from "https";
12
12
  import path from "path";
13
+ import { Command } from "@commander-js/extra-typings";
13
14
  import OpenAI from "openai";
15
+ import { getReasoning } from "./chat-completion.js";
16
+ import { findTestFiles, evalName } from "./evals.js";
14
17
  const cli = new Command()
15
18
  .name("synbad")
16
19
  .description("A set of evals for LLM inference providers");
@@ -19,10 +22,12 @@ cli.command("eval")
19
22
  .requiredOption("--env-var <env var name>", "The env var to use to authenticate with the inference provider")
20
23
  .requiredOption("--base-url <base url>", "The base URL for the inference provider")
21
24
  .option("--skip-reasoning", "Skip reasoning evals (set this for non-reasoning models)")
25
+ .option("--reasoning-effort <level>", "Set the reasoning effort to high, medium, or low")
22
26
  .option("--only <eval path within synbad>", "Specific evals you want to run, e.g. evals/reasoning or evals/tools/claude-dash")
23
27
  .option("--count <num times>", "Number of times to run the eval. Any failures count as an overall failure")
28
+ .option("--stream", "Test streaming API calls")
24
29
  .requiredOption("--model <model name>", "The model name to test")
25
- .action(async ({ model, envVar, baseUrl, only, count }) => {
30
+ .action(async ({ model, envVar, baseUrl, only, count, skipReasoning, reasoningEffort, stream }) => {
26
31
  if (!process.env[envVar]) {
27
32
  console.error(`No env var named ${envVar} exists for the current process`);
28
33
  process.exit(1);
@@ -33,29 +38,111 @@ cli.command("eval")
33
38
  });
34
39
  let found = 0;
35
40
  const failures = new Set();
36
- const evalPath = only ? path.join(import.meta.dirname, "..", only) : path.join(import.meta.dirname, "../evals");
41
+ const evalPath = only ? path.join(import.meta.dirname, "..", only) : path.join(import.meta.dirname, "..", "evals");
37
42
  const maxRuns = count == null ? 1 : parseInt(count, 10);
38
- for await (const testFile of findTestFiles(evalPath)) {
43
+ for await (const testFile of findTestFiles(evalPath, !!skipReasoning)) {
39
44
  found++;
40
45
  const test = await import(__rewriteRelativeImportExtension(testFile));
41
46
  const json = test.json;
42
47
  const name = evalName(testFile);
43
48
  process.stdout.write(`Running ${name}...`);
49
+ async function respond() {
50
+ const reasoning = reasoningEffort == null ? {} : {
51
+ reasoning_effort: reasoningEffort,
52
+ };
53
+ if (!stream) {
54
+ const response = await client.chat.completions.create({
55
+ ...json,
56
+ ...reasoning,
57
+ stream: false,
58
+ model,
59
+ });
60
+ return response.choices[0].message;
61
+ }
62
+ const msg = {};
63
+ const chunkStream = await client.chat.completions.create({
64
+ ...json,
65
+ ...reasoning,
66
+ model,
67
+ stream: true,
68
+ });
69
+ let lastIndex = null;
70
+ let toolBuffer = null;
71
+ for await (const chunk of chunkStream) {
72
+ if (!chunk.choices)
73
+ continue;
74
+ const choice = chunk.choices[0];
75
+ if (!choice)
76
+ continue;
77
+ const content = choice.delta.content;
78
+ const tools = choice.delta.tool_calls;
79
+ const reasoning = getReasoning(choice.delta);
80
+ if (content) {
81
+ if (!msg.content)
82
+ msg.content = "";
83
+ msg.content += content;
84
+ }
85
+ if (tools) {
86
+ for (const toolDelta of tools) {
87
+ if (lastIndex == null)
88
+ lastIndex = toolDelta.index;
89
+ if (lastIndex !== toolDelta.index && toolBuffer != null) {
90
+ msg.tool_calls ||= [];
91
+ // @ts-ignore
92
+ msg.tool_calls.push(toolBuffer);
93
+ toolBuffer = {
94
+ index: toolDelta.index,
95
+ type: "function",
96
+ function: {},
97
+ };
98
+ }
99
+ if (!toolBuffer) {
100
+ toolBuffer = {
101
+ index: toolDelta.index,
102
+ type: "function",
103
+ function: {}
104
+ };
105
+ }
106
+ lastIndex = toolDelta.index;
107
+ if (toolDelta.id)
108
+ toolBuffer.id = toolDelta.id;
109
+ if (toolDelta.function) {
110
+ if (toolDelta.function.name) {
111
+ toolBuffer.function.name ||= "";
112
+ toolBuffer.function.name += toolDelta.function.name;
113
+ }
114
+ if (toolDelta.function.arguments) {
115
+ toolBuffer.function.arguments ||= "";
116
+ toolBuffer.function.arguments += toolDelta.function.arguments;
117
+ }
118
+ }
119
+ }
120
+ }
121
+ if (reasoning) {
122
+ if (!msg.reasoning_content)
123
+ msg.reasoning_content = "";
124
+ msg.reasoning_content += reasoning;
125
+ }
126
+ }
127
+ if (toolBuffer) {
128
+ msg.tool_calls ||= [];
129
+ // @ts-ignore
130
+ msg.tool_calls.push(toolBuffer);
131
+ }
132
+ return msg;
133
+ }
44
134
  try {
45
135
  for (let i = 0; i < maxRuns; i++) {
46
136
  if (maxRuns > 1) {
47
137
  process.stdout.write(` ${i + 1}/${maxRuns}`);
48
138
  }
49
- const response = await client.chat.completions.create({
50
- model,
51
- ...json,
52
- });
139
+ const response = await respond();
53
140
  try {
54
141
  test.test(response);
55
142
  }
56
143
  catch (e) {
57
144
  console.error("Response:");
58
- console.error(JSON.stringify(response.choices[0], null, 2));
145
+ console.error(JSON.stringify(response, null, 2));
59
146
  throw e;
60
147
  }
61
148
  }
@@ -79,36 +166,115 @@ ${passed}/${found} evals passed. Failures:
79
166
  - ${Array.from(failures).map(evalName).join("\n- ")}
80
167
  `.trim());
81
168
  });
82
- function evalName(file) {
83
- return `${path.basename(path.dirname(file))}/${path.basename(file).replace(/.js$/, "")}`;
84
- }
85
- async function* findTestFiles(dir) {
86
- try {
87
- await fs.stat(dir);
88
- }
89
- catch (e) {
90
- const pathname = `${dir}.js`;
91
- const stat = await fs.stat(pathname);
92
- if (stat.isFile()) {
93
- yield pathname;
94
- return;
95
- }
96
- throw e;
97
- }
98
- const entryNames = await fs.readdir(dir);
99
- const entries = await Promise.all(entryNames.map(async (entry) => {
100
- return {
101
- path: path.join(dir, entry),
102
- stat: await fs.stat(path.join(dir, entry)),
103
- };
104
- }));
105
- for (const entry of entries) {
106
- if (entry.stat.isFile() && entry.path.endsWith(".js")) {
107
- yield entry.path;
169
+ cli.command("proxy")
170
+ .requiredOption("-p, --port <number>", "Port to listen on")
171
+ .requiredOption("-t, --target <url>", "Target URL to proxy to")
172
+ .option("--pretty", "Pretty-print the JSON")
173
+ .action(async (options) => {
174
+ const port = parseInt(options.port, 10);
175
+ const targetUrl = new URL(options.target);
176
+ stderrLog(`🚀 Starting proxy on port ${port}`);
177
+ stderrLog(`📯 Proxying to: ${targetUrl.origin}`);
178
+ const server = http.createServer(async (req, res) => {
179
+ try {
180
+ const timestamp = new Date().toISOString();
181
+ // Log request metadata
182
+ stderrLog(`\n[${timestamp}] 📥 ${req.method} ${req.url}`);
183
+ // Construct target URL - handle target path correctly
184
+ const incomingPath = req.url || "";
185
+ const targetBasePath = targetUrl.pathname.replace(/\/$/, ''); // Remove trailing slash
186
+ const targetPath = targetBasePath + incomingPath;
187
+ const target = `${targetUrl.origin}${targetPath}`;
188
+ // Prepare request headers (remove problematic ones)
189
+ const requestHeaders = { ...req.headers };
190
+ delete requestHeaders["host"];
191
+ delete requestHeaders["content-length"];
192
+ delete requestHeaders["transfer-encoding"];
193
+ stderrLog(`[${timestamp}] ➡️ Forwarding to: ${target}`);
194
+ stderrLog(`[${timestamp}] 📦 Writing request data to stdout...`);
195
+ // Choose the right module based on target protocol
196
+ const httpModule = targetUrl.protocol === "https:" ? https : http;
197
+ const buffer = [];
198
+ // Create proxy request
199
+ const proxyReq = httpModule.request({
200
+ hostname: targetUrl.hostname,
201
+ port: targetUrl.port || (targetUrl.protocol === "https:" ? 443 : 80),
202
+ path: targetPath,
203
+ method: req.method,
204
+ headers: requestHeaders,
205
+ }, (proxyRes) => {
206
+ // Log response status and headers
207
+ stderrLog(`[${timestamp}] 📤 Response to ${req.url}: ${proxyRes.statusCode} ${proxyRes.statusMessage}`);
208
+ stderrLog(`[${timestamp}] 📦 Loading response...`);
209
+ // Filter problematic response headers
210
+ const responseHeaders = { ...proxyRes.headers };
211
+ delete responseHeaders["transfer-encoding"];
212
+ delete responseHeaders["content-length"];
213
+ res.writeHead(proxyRes.statusCode || 200, responseHeaders);
214
+ // Stream response data immediately to client
215
+ proxyRes.on("data", (chunk) => {
216
+ res.write(chunk);
217
+ });
218
+ proxyRes.on("end", () => {
219
+ stderrLog(`[${timestamp}] ✅ Response complete`);
220
+ res.end();
221
+ });
222
+ });
223
+ // Handle proxy request errors
224
+ proxyReq.on("error", (e) => {
225
+ console.error(`[${timestamp}] ❌ Proxy request error:`, e);
226
+ if (!res.headersSent) {
227
+ res.writeHead(500, { "Content-Type": "application/json" });
228
+ res.end(JSON.stringify({ error: "Proxy error", message: e.message }));
229
+ }
230
+ });
231
+ // Handle client request errors
232
+ req.on("error", (e) => {
233
+ console.error(`[${timestamp}] ❌ Client request error:`, e);
234
+ proxyReq.destroy();
235
+ if (!res.headersSent) {
236
+ res.writeHead(400, { "Content-Type": "application/json" });
237
+ res.end(JSON.stringify({ error: "Client error", message: e.message }));
238
+ }
239
+ });
240
+ req.on("data", (chunk) => {
241
+ buffer.push(chunk);
242
+ if (!options.pretty)
243
+ process.stdout.write(chunk);
244
+ proxyReq.write(chunk);
245
+ });
246
+ req.on("end", () => {
247
+ if (options.pretty)
248
+ console.log(JSON.stringify(JSON.parse(buffer.join()), null, 2));
249
+ else
250
+ process.stdout.write("\n");
251
+ console.log(`[${timestamp}] ✅ Request complete`);
252
+ proxyReq.end();
253
+ });
108
254
  }
109
- if (entry.stat.isDirectory()) {
110
- yield* findTestFiles(entry.path);
255
+ catch (e) {
256
+ const timestamp = new Date().toISOString();
257
+ console.error(`[${timestamp}] ❌ Server error:`, e);
258
+ if (!res.headersSent) {
259
+ res.writeHead(500, { "Content-Type": "application/json" });
260
+ res.end(JSON.stringify({ error: "Server error", message: e.message }));
261
+ }
111
262
  }
263
+ });
264
+ server.on("error", (e) => {
265
+ console.error("❌ Server error:", e);
266
+ });
267
+ server.listen(port, () => {
268
+ stderrLog(`✅ Server listening on http://localhost:${port}`);
269
+ stderrLog(`📡 All HTTP request data will be logged to stdout`);
270
+ stderrLog("🤓 Terminal UI messages (such as this one) will be logged to stderr");
271
+ });
272
+ });
273
+ function stderrLog(item, ...items) {
274
+ let formatted = item;
275
+ if (items.length > 0) {
276
+ formatted += " " + items.join(" ");
112
277
  }
278
+ process.stderr.write(formatted + "\n");
113
279
  }
114
280
  cli.parse();
@@ -1,8 +1,8 @@
1
1
  import * as assert from "../../source/asserts.ts";
2
- import { ChatResponse, getReasoning } from "../../source/chat-completion.ts";
2
+ import { ChatMessage, getReasoning } from "../../source/chat-completion.ts";
3
3
 
4
- export function test(response: ChatResponse) {
5
- const reasoning = getReasoning(response.choices[0].message);
4
+ export function test(message: ChatMessage) {
5
+ const reasoning = getReasoning(message);
6
6
  assert.isNotNullish(reasoning);
7
7
  }
8
8
 
@@ -1,8 +1,7 @@
1
- import { ChatResponse } from "../../source/chat-completion.ts";
1
+ import { ChatMessage } from "../../source/chat-completion.ts";
2
2
  import * as assert from "../../source/asserts.ts";
3
3
 
4
- export function test(response: ChatResponse) {
5
- const { tool_calls } = response.choices[0].message;
4
+ export function test({ tool_calls }: ChatMessage) {
6
5
  assert.isNotNullish(tool_calls);
7
6
  assert.isNotEmptyArray(tool_calls);
8
7
  assert.strictEqual(tool_calls.length, 1);
@@ -1,13 +1,13 @@
1
1
  import * as assert from "../../source/asserts.ts";
2
- import { ChatResponse, getReasoning } from "../../source/chat-completion.ts";
2
+ import { ChatMessage, getReasoning } from "../../source/chat-completion.ts";
3
3
 
4
- export function test(response: ChatResponse) {
5
- const reasoning = getReasoning(response.choices[0].message);
4
+ export function test(message: ChatMessage) {
5
+ const reasoning = getReasoning(message);
6
6
  assert.isNotNullish(reasoning);
7
7
  }
8
8
 
9
9
  export const json = {
10
- "messages": [
11
- {"role": "user", "content": "Why does 1+1=2?"}
10
+ messages: [
11
+ { role: "user", content: "Why does 1+1=2?" }
12
12
  ],
13
13
  }
@@ -0,0 +1,65 @@
1
+ import * as assert from "../../source/asserts.ts";
2
+ import { ChatMessage } from "../../source/chat-completion.ts";
3
+
4
+ export function test(message: ChatMessage) {
5
+ const content = message.content;
6
+ assert.or(
7
+ () => assert.isNotNullish(content),
8
+ () => assert.isNotEmptyArray(message.tool_calls),
9
+ );
10
+ }
11
+
12
+ export const json = {
13
+ "messages": [
14
+ {
15
+ "role": "system",
16
+ "content": "When I ask you to add a feature or resolve a problem: ALWAYS start the project explorer sub-agent to build complete understanding"
17
+ },
18
+ {
19
+ "role": "user",
20
+ "content": [
21
+ {
22
+ "type": "text",
23
+ "text": "Hello"
24
+ }
25
+ ]
26
+ }
27
+ ],
28
+ "temperature": 1,
29
+ "tools": [
30
+ {
31
+ "type": "function",
32
+ "function": {
33
+ "name": "task",
34
+ "description": "Launch a new agent to handle complex, multi-step tasks autonomously.\n\nAvailable agent types and the tools they have access to:\n- general: General-purpose agent for researching complex questions and executing multi-step tasks. Use this agent to execute multiple units of work in parallel.\n- explore: Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. \"src/components/**/*.tsx\"), search code for keywords (eg. \"API endpoints\"), or answer questions about the codebase (eg. \"how do API endpoints work?\"). When calling this agent, specify the desired thoroughness level: \"quick\" for basic searches, \"medium\" for moderate exploration, or \"very thorough\" for comprehensive analysis across multiple locations and naming conventions.\n- code-reviewer: Expert code review specialist. Proactively reviews code for quality, security, and maintainability. Use immediately after writing or modifying code.\n\nWhen using the Task tool, you must specify a subagent_type parameter to select which agent type to use.\n\nWhen to use the Task tool:\n- When you are instructed to execute custom slash commands. Use the Task tool with the slash command invocation as the entire prompt. The slash command can take arguments. For example: Task(description=\"Check the file\", prompt=\"/check-file path/to/file.py\")\n\nWhen NOT to use the Task tool:\n- If you want to read a specific file path, use the Read or Glob tool instead of the Task tool, to find the match more quickly\n- If you are searching for a specific class definition like \"class Foo\", use the Glob tool instead, to find the match more quickly\n- If you are searching for code within a specific file or set of 2-3 files, use the Read tool instead of the Task tool, to find the match more quickly\n- Other tasks that are not related to the agent descriptions above\n\n\nUsage notes:\n1. Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses\n2. When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.\n3. Each agent invocation is stateless unless you provide a session_id. Your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message to you.\n4. The agent's outputs should generally be trusted\n5. Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent\n6. If the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement.\n\n",
35
+ "parameters": {
36
+ "type": "object",
37
+ "properties": {
38
+ "description": {
39
+ "description": "A short (3-5 words) description of the task",
40
+ "type": "string"
41
+ },
42
+ "prompt": {
43
+ "description": "The task for the agent to perform",
44
+ "type": "string"
45
+ },
46
+ "subagent_type": {
47
+ "description": "The type of specialized agent to use for this task",
48
+ "type": "string"
49
+ },
50
+ "session_id": {
51
+ "description": "Existing Task session to continue",
52
+ "type": "string"
53
+ }
54
+ },
55
+ "required": [
56
+ "description",
57
+ "prompt",
58
+ "subagent_type"
59
+ ]
60
+ }
61
+ }
62
+ },
63
+ ],
64
+ "tool_choice": "auto"
65
+ }
@@ -1,8 +1,7 @@
1
- import OpenAI from "openai";
2
1
  import * as assert from "../../source/asserts.ts";
2
+ import { ChatMessage } from "../../source/chat-completion.ts";
3
3
 
4
- export function test(response: OpenAI.ChatCompletion) {
5
- const { tool_calls } = response.choices[0].message;
4
+ export function test({ tool_calls }: ChatMessage) {
6
5
  assert.isNotNullish(tool_calls);
7
6
  assert.isNotEmptyArray(tool_calls);
8
7
  }
@@ -1,22 +1,23 @@
1
- import OpenAI from "openai";
2
1
  import * as assert from "../../source/asserts.ts";
2
+ import { ChatMessage } from "../../source/chat-completion.ts";
3
3
 
4
- export function test(response: OpenAI.ChatCompletion) {
5
- const { tool_calls } = response.choices[0].message;
4
+ export function test({ tool_calls }: ChatMessage) {
6
5
  assert.isNotNullish(tool_calls);
7
6
  assert.isNotEmptyArray(tool_calls);
8
- assert.strictEqual(tool_calls.length, 1);
7
+ assert.gte(tool_calls.length, 1);
9
8
  assert.strictEqual(tool_calls[0].type, "function");
10
9
  const fn = tool_calls[0].function;
11
10
  assert.or(
12
11
  () => {
13
12
  assert.strictEqual(fn.name, "ls");
14
- const args = JSON.parse(fn.arguments);
15
- assert.or(
16
- () => assert.strictEqual(args.path, "/home/reissbaker/Hack/scratch-scripts"),
17
- () => assert.strictEqual(args.path, "."),
18
- () => assert.isNullish(args.path),
19
- );
13
+ if(fn.arguments) {
14
+ const args = JSON.parse(fn.arguments);
15
+ assert.or(
16
+ () => assert.strictEqual(args.path, "/home/reissbaker/Hack/scratch-scripts"),
17
+ () => assert.strictEqual(args.path, "."),
18
+ () => assert.isNullish(args.path),
19
+ );
20
+ }
20
21
  },
21
22
  () => {
22
23
  assert.strictEqual(fn.name, "bash");
@@ -448,7 +449,4 @@ export const json = {
448
449
  ],
449
450
  "tool_choice": "auto",
450
451
  "max_tokens": 60000,
451
- "stream_options": {
452
- "include_usage": true
453
- }
454
452
  }
@@ -0,0 +1,104 @@
1
+ import { ChatMessage } from "../../source/chat-completion.ts";
2
+ import * as assert from "../../source/asserts.ts";
3
+
4
+ export function test({ tool_calls }: ChatMessage) {
5
+ assert.isNotNullish(tool_calls);
6
+ assert.isNotEmptyArray(tool_calls);
7
+ assert.gte(tool_calls.length, 1);
8
+
9
+ assert.ok(tool_calls.some(tool_call => {
10
+ if (tool_call.type === "function" && tool_call.function.name === "get_weather") {
11
+ const location = JSON.parse(tool_call.function.arguments).location;
12
+ if (typeof location === "string") {
13
+ return location.toLowerCase().match(/las vegas/);
14
+ }
15
+ }
16
+ return false;
17
+ }), "At least one tool call must be get_weather({ location: 'las_vegas' })");
18
+ }
19
+
20
+ export const json = {
21
+ "messages": [
22
+ {
23
+ role: "user",
24
+ content: "What's the weather in Paris?"
25
+ },
26
+ {
27
+ role: "assistant",
28
+ tool_calls: [
29
+ {
30
+ id: "gw1",
31
+ type: "function",
32
+ function: {
33
+ name: "get_weather",
34
+ arguments: JSON.stringify({
35
+ location: "Paris, France",
36
+ }),
37
+ },
38
+ },
39
+ ],
40
+ },
41
+ {
42
+ role: "tool",
43
+ tool_call_id: "gw1",
44
+ content: "The weather in Paris is 24 degrees Celsius",
45
+ },
46
+ {
47
+ role: "assistant",
48
+ content: "I've looked up the weather in Paris, and it's a comfy 24 degrees Celsius today.",
49
+ },
50
+ {
51
+ role: "user",
52
+ content: "I meant Paris, Texas",
53
+ },
54
+ {
55
+ role: "assistant",
56
+ tool_calls: [
57
+ {
58
+ id: "gw2",
59
+ type: "function",
60
+ function: {
61
+ name: "get_weather",
62
+ arguments: JSON.stringify({
63
+ location: "Paris, Texas",
64
+ }),
65
+ },
66
+ },
67
+ ],
68
+ },
69
+ {
70
+ role: "tool",
71
+ tool_call_id: "gw2",
72
+ content: "The weather in Paris, Texas is 34 degrees Celsius",
73
+ },
74
+ {
75
+ role: "assistant",
76
+ content: "I've looked up the weather in Paris, Texas and it's a scorching 24 degrees Celsius today.",
77
+ },
78
+ {
79
+ role: "user",
80
+ content: "How about Las Vegas",
81
+ },
82
+ ],
83
+ "tools": [
84
+ {
85
+ "type": "function",
86
+ "function": {
87
+ "name": "get_weather",
88
+ "description": "Get current weather for a location",
89
+ "parameters": {
90
+ "type": "object",
91
+ "properties": {
92
+ "location": {
93
+ "type": "string",
94
+ "description": "City name"
95
+ }
96
+ },
97
+ "required": ["location"]
98
+ }
99
+ }
100
+ }
101
+ ],
102
+ "parallel_tool_calls": true,
103
+ "tool_choice": "auto",
104
+ }
@@ -0,0 +1,34 @@
1
+ import { ChatMessage } from "../../source/chat-completion.ts";
2
+ import * as assert from "../../source/asserts.ts";
3
+
4
+ export function test({ tool_calls }: ChatMessage) {
5
+ assert.isNotNullish(tool_calls);
6
+ assert.isNotEmptyArray(tool_calls);
7
+ assert.strictEqual(tool_calls.length, 1);
8
+ assert.strictEqual(tool_calls[0].type, "function");
9
+ }
10
+
11
+ export const json = {
12
+ "messages": [
13
+ {
14
+ "role": "user",
15
+ "content": "read the todos",
16
+ },
17
+ ],
18
+ "tools": [
19
+ {
20
+ "type": "function",
21
+ "function": {
22
+ "name": "get_todo_items",
23
+ "description": "Retrieves the current list of todo items, including their names and completion statuses.",
24
+ "parameters": {
25
+ "$schema": "http://json-schema.org/draft-07/schema#",
26
+ "type": "object",
27
+ "properties": {},
28
+ "additionalProperties": false
29
+ }
30
+ }
31
+ },
32
+ ],
33
+ "tool_choice": "auto",
34
+ }