@nexuss0781/nar 0.1.1 → 0.1.2

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 (2) hide show
  1. package/README.md +30 -6
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -67,12 +67,13 @@ console.log(await models());
67
67
 
68
68
  ## Tool calling
69
69
 
70
- Tool call deltas are accumulated for you and arrive keyed by index.
70
+ Tool calls come back in OpenAI request shape, ready to hand straight to your runtime.
71
+ `toolCalls` and `finishReason` are populated by `chat`, `complete` and `streamEvents` alike.
71
72
 
72
73
  ```ts
73
- import { streamEvents, complete } from "@nexuss0781/nar";
74
+ import { chat } from "@nexuss0781/nar";
74
75
 
75
- for await (const event of streamEvents("What is the weather in Oslo?", {
76
+ const r = await chat("What is the weather in Oslo?", {
76
77
  tools: [{
77
78
  type: "function",
78
79
  function: {
@@ -85,13 +86,36 @@ for await (const event of streamEvents("What is the weather in Oslo?", {
85
86
  },
86
87
  },
87
88
  }],
88
- })) {
89
- for (const call of Object.values(event.toolCalls)) {
90
- if (call.name && !event.delta) console.log(call.name, call.arguments);
89
+ toolChoice: "auto",
90
+ });
91
+
92
+ if (r.finishReason === "tool_calls") {
93
+ for (const call of r.toolCalls) {
94
+ run(call.function.name, JSON.parse(call.function.arguments));
91
95
  }
92
96
  }
93
97
  ```
94
98
 
99
+ Streaming reassembles argument fragments for you. Each event carries a snapshot of the
100
+ calls accumulated so far, so an event you keep does not change underneath you:
101
+
102
+ ```ts
103
+ import { streamEvents } from "@nexuss0781/nar";
104
+
105
+ for await (const event of streamEvents(prompt, { tools })) {
106
+ for (const call of event.toolCalls) {
107
+ console.log(call.function.name, call.function.arguments);
108
+ }
109
+ }
110
+ ```
111
+
112
+ Feeding the result back for the next turn:
113
+
114
+ ```ts
115
+ messages.push({ role: "assistant", content: r.text, tool_calls: r.toolCalls });
116
+ messages.push({ role: "tool", tool_call_id: r.toolCalls[0].id, content: "12C and clear" });
117
+ ```
118
+
95
119
  NAR keeps a tool-calling conversation pinned to the model that started it, so a
96
120
  multi-turn tool loop does not silently change models mid-conversation.
97
121
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexuss0781/nar",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Minimal client for Nexuss AI Router: auto-routed free LLMs, SSE streaming, one master key, no provider handling.",
5
5
  "keywords": [
6
6
  "llm",