Skip to content

Commit

Permalink
chore: fix typo in docs and add request header for function calls (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Nov 13, 2023
1 parent 12de980 commit 22ce244
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ If you pass a `parse` function, it will automatically parse the `arguments` for
and returns any parsing errors to the model to attempt auto-recovery.
Otherwise, the args will be passed to the function you provide as a string.

If you pass `function_call: {name: …}` or `tool_call: {function: {name: …}}` instead of `auto`,
If you pass `function_call: {name: …}` or `tool_choice: {function: {name: …}}` instead of `auto`,
it returns immediately after calling that function (and only loops to auto-recover parsing errors).

```ts
Expand Down
2 changes: 1 addition & 1 deletion examples/tool-call-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async function main() {
console.log(runner.messages);

console.log();
console.log('final chat competion');
console.log('final chat completion');
console.dir(result, { depth: null });
}

Expand Down
8 changes: 7 additions & 1 deletion src/lib/ChatCompletionStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ export class ChatCompletionStream
options?: Core.RequestOptions,
): ChatCompletionStream {
const runner = new ChatCompletionStream();
runner._run(() => runner._runChatCompletion(completions, { ...params, stream: true }, options));
runner._run(() =>
runner._runChatCompletion(
completions,
{ ...params, stream: true },
{ ...options, headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' } },
),
);
return runner;
}

Expand Down
14 changes: 12 additions & 2 deletions src/lib/ChatCompletionStreamingRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ export class ChatCompletionStreamingRunner
options?: RunnerOptions,
): ChatCompletionStreamingRunner {
const runner = new ChatCompletionStreamingRunner();
runner._run(() => runner._runFunctions(completions, params, options));
runner._run(() =>
runner._runFunctions(completions, params, {
...options,
headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'runFunctions' },
}),
);
return runner;
}

Expand All @@ -53,7 +58,12 @@ export class ChatCompletionStreamingRunner
options?: RunnerOptions,
): ChatCompletionStreamingRunner {
const runner = new ChatCompletionStreamingRunner();
runner._run(() => runner._runTools(completions, params, options));
runner._run(() =>
runner._runTools(completions, params, {
...options,
headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'runTools' },
}),
);
return runner;
}
}

0 comments on commit 22ce244

Please sign in to comment.