MCPcopy Index your code
hub / github.com/di-sukharev/opencommit / hasAutoParseableInput

Function hasAutoParseableInput

out/cli.cjs:81776–81781  ·  view source on GitHub ↗
(params)

Source from the content-addressed store, hash-verified

81774}
81775function shouldParseToolCall(params, toolCall) {
81776 if (!params) {
81777 return false;
81778 }
81779 const inputTool = params.tools?.find((inputTool2) => inputTool2.function?.name === toolCall.function.name);
81780 return isAutoParsableTool(inputTool) || inputTool?.function.strict || false;
81781}
81782function hasAutoParseableInput(params) {
81783 if (isAutoParsableResponseFormat(params.response_format)) {
81784 return true;

Callers 2

maybeParseChatCompletionFunction · 0.85
[(_ChatCompletionStream_params = /* @__PURE__ */ new WeakMap(), _ChatCompletionStream_choiceEventStates = /* @__PURE__ */ new WeakMap(), _ChatCompletionStream_currentChatCompletionSnapshot = /* @__PURE__ */ new WeakMap(), _ChatCompletionStream_instances = /* @__PURE__ */ new WeakSet(), _ChatCompletionStream_beginRequest = function _ChatCompletionStream_beginRequest2() { if (this.ended) return; __classPrivateFieldSet9(this, _ChatCompletionStream_currentChatCompletionSnapshot, void 0, "f"); }, _ChatCompletionStream_getChoiceEventState = function _ChatCompletionStream_getChoiceEventState2(choice) { let state2 = __classPrivateFieldGet11(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index]; if (state2) { return state2; } state2 = { content_done: false, refusal_done: false, logprobs_content_done: false, logprobs_refusal_done: false, done_tool_calls: /* @__PURE__ */ new Set(), current_tool_call_index: null }; __classPrivateFieldGet11(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index] = state2; return state2; }, _ChatCompletionStream_addChunk = function _ChatCompletionStream_addChunk2(chunk) { if (this.ended) return; const completion = __classPrivateFieldGet11(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_accumulateChatCompletion).call(this, chunk); this._emit("chunk", chunk, completion); for (const choice of chunk.choices) { const choiceSnapshot = completion.choices[choice.index]; if (choice.delta.content != null && choiceSnapshot.message?.role === "assistant" && choiceSnapshot.message?.content) { this._emit("content", choice.delta.content, choiceSnapshot.message.content); this._emit("content.delta", { delta: choice.delta.content, snapshot: choiceSnapshot.message.content, parsed: choiceSnapshot.message.parsed }); } if (choice.delta.refusal != null && choiceSnapshot.message?.role === "assistant" && choiceSnapshot.message?.refusal) { this._emit("refusal.delta", { delta: choice.delta.refusal, snapshot: choiceSnapshot.message.refusal }); } if (choice.logprobs?.content != null && choiceSnapshot.message?.role === "assistant") { this._emit("logprobs.content.delta", { content: choice.logprobs?.content, snapshot: choiceSnapshot.logprobs?.content ?? [] }); } if (choice.logprobs?.refusal != null && choiceSnapshot.message?.role === "assistant") { this._emit("logprobs.refusal.delta", { refusal: choice.logprobs?.refusal, snapshot: choiceSnapshot.logprobs?.refusal ?? [] }); } const state2 = __classPrivateFieldGet11(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot); if (choiceSnapshot.finish_reason) { __classPrivateFieldGet11(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitContentDoneEvents).call(this, choiceSnapshot); if (state2.current_tool_call_index != null) { __classPrivateFieldGet11(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitToolCallDoneEvent).call(this, choiceSnapshot, state2.current_tool_call_index); } } for (const toolCall of choice.delta.tool_calls ?? []) { if (state2.current_tool_call_index !== toolCall.index) { __classPrivateFieldGet11(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitContentDoneEvents).call(this, choiceSnapshot); if (state2.current_tool_call_index != null) { __classPrivateFieldGet11(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitToolCallDoneEvent).call(this, choiceSnapshot, state2.current_tool_call_index); } } state2.current_tool_call_index = toolCall.index; } for (const toolCallDelta of choice.delta.tool_calls ?? []) { const toolCallSnapshot = choiceSnapshot.message.tool_calls?.[toolCallDelta.index]; if (!toolCallSnapshot?.type) { continue; } if (toolCallSnapshot?.type === "function") { this._emit("tool_calls.function.arguments.delta", { name: toolCallSnapshot.function?.name, index: toolCallDelta.index, arguments: toolCallSnapshot.function.arguments, parsed_arguments: toolCallSnapshot.function.parsed_arguments, arguments_delta: toolCallDelta.function?.arguments ?? "" }); } else { assertNever(toolCallSnapshot?.type); } } } }, _ChatCompletionStream_emitToolCallDoneEvent = function _ChatCompletionStream_emitToolCallDoneEvent2(choiceSnapshot, toolCallIndex) { const state2 = __classPrivateFieldGet11(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot); if (state2.done_tool_calls.has(toolCallIndex)) { return; } const toolCallSnapshot = choiceSnapshot.message.tool_calls?.[toolCallIndex]; if (!toolCallSnapshot) { throw new Error("no tool call snapshot"); } if (!toolCallSnapshot.type) { throw new Error("tool call snapshot missing `type`"); } if (toolCallSnapshot.type === "function") { const inputTool = __classPrivateFieldGet11(this, _ChatCompletionStream_params, "f")?.tools?.find((tool) => tool.type === "function" && tool.function.name === toolCallSnapshot.function.name); this._emit("tool_calls.function.arguments.done", { name: toolCallSnapshot.function.name, index: toolCallIndex, arguments: toolCallSnapshot.function.arguments, parsed_arguments: isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCallSnapshot.function.arguments) : inputTool?.function.strict ? JSON.parse(toolCallSnapshot.function.arguments) : null }); } else { assertNever(toolCallSnapshot.type); } }, _ChatCompletionStream_emitContentDoneEvents = function _ChatCompletionStream_emitContentDoneEvents2(choiceSnapshot) { const state2 = __classPrivateFieldGet11(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot); if (choiceSnapshot.message.content && !state2.content_done) { state2.content_done = true; const responseFormat = __classPrivateFieldGet11(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getAutoParseableResponseFormat).call(this); this._emit("content.done", { content: choiceSnapshot.message.content, parsed: responseFormat ? responseFormat.$parseRaw(choiceSnapshot.message.content) : null }); } if (choiceSnapshot.message.refusal && !state2.refusal_done) { state2.refusal_done = true; this._emit("refusal.done", { refusal: choiceSnapshot.message.refusal }); } if (choiceSnapshot.logprobs?.content && !state2.logprobs_content_done) { state2.logprobs_content_done = true; this._emit("logprobs.content.done", { content: choiceSnapshot.logprobs.content }); } if (choiceSnapshot.logprobs?.refusal && !state2.logprobs_refusal_done) { state2.logprobs_refusal_done = true; this._emit("logprobs.refusal.done", { refusal: choiceSnapshot.logprobs.refusal }); } }, _ChatCompletionStream_endRequest = function _ChatCompletionStream_endRequest2() { if (this.ended) { throw new OpenAIError(`stream has ended, this shouldn't happen`); } const snapshot = __classPrivateFieldGet11(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f"); if (!snapshot) { throw new OpenAIError(`request ended without sending any chunks`); } __classPrivateFieldSet9(this, _ChatCompletionStream_currentChatCompletionSnapshot, void 0, "f"); __classPrivateFieldSet9(this, _ChatCompletionStream_choiceEventStates, [], "f"); return finalizeChatCompletion(snapshot, __classPrivateFieldGet11(this, _ChatCompletionStream_params, "f")); }, _ChatCompletionStream_getAutoParseableResponseFormat = function _ChatCompletionStream_getAutoParseableResponseFormat2() { const responseFormat = __classPrivateFieldGet11(this, _ChatCompletionStream_params, "f")?.response_format; if (isAutoParsableResponseFormat(responseFormat)) { return responseFormat; } return null; }, _ChatCompletionStream_accumulateChatCompletion = function _ChatCompletionStream_accumulateChatCompletion2(chunk) { var _a5, _b2, _c2, _d2; let snapshot = __classPrivateFieldGet11(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f"); const { choices, ...rest } = chunk; if (!snapshot) { snapshot = __classPrivateFieldSet9(this, _ChatCompletionStream_currentChatCompletionSnapshot, { ...rest, choices: [] }, "f"); } else { Object.assign(snapshot, rest); } for (const { delta, finish_reason, index, logprobs = null, ...other } of chunk.choices) { let choice = snapshot.choices[index]; if (!choice) { choice = snapshot.choices[index] = { finish_reason, index, message: {}, logprobs, ...other }; } if (logprobs) { if (!choice.logprobs) { choice.logprobs = Object.assign({}, logprobs); } else { const { content: content2, refusal: refusal2, ...rest3 } = logprobs; assertIsEmpty(rest3); Object.assign(choice.logprobs, rest3); if (content2) { (_a5 = choice.logprobs).content ?? (_a5.content = []); choice.logprobs.content.push(...content2); } if (refusal2) { (_b2 = choice.logprobs).refusal ?? (_b2.refusal = []); choice.logprobs.refusal.push(...refusal2); } } } if (finish_reason) { choice.finish_reason = finish_reason; if (__classPrivateFieldGet11(this, _ChatCompletionStream_params, "f") && hasAutoParseableInput(__classPrivateFieldGet11(this, _ChatCompletionStream_params, "f"))) { if (finish_reason === "length") { throw new LengthFinishReasonError(); } if (finish_reason === "content_filter") { throw new ContentFilterFinishReasonError(); } } } Object.assign(choice, other); if (!delta) continue; const { content, refusal, function_call, role, tool_calls, ...rest2 } = delta; assertIsEmpty(rest2); Object.assign(choice.message, rest2); if (refusal) { choice.message.refusal = (choice.message.refusal || "") + refusal; } if (role) choice.message.role = role; if (function_call) { if (!choice.message.function_call) { choice.message.function_call = function_call; } else { if (function_call.name) choice.message.function_call.name = function_call.name; if (function_call.arguments) { (_c2 = choice.message.function_call).arguments ?? (_c2.arguments = ""); choice.message.function_call.arguments += function_call.arguments; } } } if (content) { choice.message.content = (choice.message.content || "") + content; if (!choice.message.refusal && __classPrivateFieldGet11(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getAutoParseableResponseFormat).call(this)) { choice.message.parsed = partialParse(choice.message.content); } } if (tool_calls) { if (!choice.message.tool_calls) choice.message.tool_calls = []; for (const { index: index2, id, type: type2, function: fn, ...rest3 } of tool_calls) { const tool_call = (_d2 = choice.message.tool_calls)[index2] ?? (_d2[index2] = {}); Object.assign(tool_call, rest3); if (id) tool_call.id = id; if (type2) tool_call.type = type2; if (fn) tool_call.function ?? (tool_call.function = { name: fn.name ?? "", arguments: "" }); if (fn?.name) tool_call.function.name = fn.name; if (fn?.arguments) { tool_call.function.arguments += fn.arguments; if (shouldParseToolCall(__classPrivateFieldGet11(this, _ChatCompletionStream_params, "f"), tool_call)) { tool_call.function.parsed_arguments = partialParse(tool_call.function.arguments); } } } } } return snapshot; }, Symbol.asyncIterator)]Method · 0.85

Calls 2

isAutoParsableToolFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…