MCPcopy
hub / github.com/di-sukharev/opencommit / _runTools

Method _runTools

out/cli.cjs:81985–82073  ·  view source on GitHub ↗
(client, params, options)

Source from the content-addressed store, hash-verified

81983 }
81984 const rawContent2 = await fn.function(parsed, this);
81985 const content = __classPrivateFieldGet10(this, _AbstractChatCompletionRunner_instances, "m", _AbstractChatCompletionRunner_stringifyFunctionCallResult).call(this, rawContent2);
81986 this._addMessage({ role, name, content });
81987 if (singleFunctionToCall)
81988 return;
81989 }
81990 }
81991 async _runTools(client, params, options) {
81992 const role = "tool";
81993 const { tool_choice = "auto", stream: stream4, ...restParams } = params;
81994 const singleFunctionToCall = typeof tool_choice !== "string" && tool_choice?.function?.name;
81995 const { maxChatCompletions = DEFAULT_MAX_CHAT_COMPLETIONS } = options || {};
81996 const inputTools = params.tools.map((tool) => {
81997 if (isAutoParsableTool(tool)) {
81998 if (!tool.$callback) {
81999 throw new OpenAIError("Tool given to `.runTools()` that does not have an associated function");
82000 }
82001 return {
82002 type: "function",
82003 function: {
82004 function: tool.$callback,
82005 name: tool.function.name,
82006 description: tool.function.description || "",
82007 parameters: tool.function.parameters,
82008 parse: tool.$parseRaw,
82009 strict: true
82010 }
82011 };
82012 }
82013 return tool;
82014 });
82015 const functionsByName = {};
82016 for (const f4 of inputTools) {
82017 if (f4.type === "function") {
82018 functionsByName[f4.function.name || f4.function.function.name] = f4.function;
82019 }
82020 }
82021 const tools = "tools" in params ? inputTools.map((t2) => t2.type === "function" ? {
82022 type: "function",
82023 function: {
82024 name: t2.function.name || t2.function.function.name,
82025 parameters: t2.function.parameters,
82026 description: t2.function.description,
82027 strict: t2.function.strict
82028 }
82029 } : t2) : void 0;
82030 for (const message of params.messages) {
82031 this._addMessage(message, false);
82032 }
82033 for (let i3 = 0; i3 < maxChatCompletions; ++i3) {
82034 const chatCompletion = await this._createChatCompletion(client, {
82035 ...restParams,
82036 tool_choice,
82037 tools,
82038 messages: [...this.messages]
82039 }, options);
82040 const message = chatCompletion.choices[0]?.message;
82041 if (!message) {
82042 throw new OpenAIError(`missing message in ChatCompletion response`);

Callers 2

runToolsMethod · 0.80
runToolsMethod · 0.80

Calls 7

isAutoParsableToolFunction · 0.85
__classPrivateFieldGet10Function · 0.85
_addMessageMethod · 0.45
_createChatCompletionMethod · 0.45
keysMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected