Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/aschenmo_aschenmo-academic.json
T

1 line
9.3 KiB
JSON

{"repo": "aschenmo/aschenmo-academic", "files": {"anything-llm-master/server/utils/agents/aibitat/providers/deepseek.js": {"aeff540ca5b93ecf934c2f766658dd707ae5bc24": {"t": 1785745556.7012382, "n": 4398, "h": "5281d18d3b387e09", "c": "const OpenAI = require(\"openai\");\nconst Provider = require(\"./ai-provider.js\");\nconst InheritMultiple = require(\"./helpers/classes.js\");\nconst UnTooled = require(\"./helpers/untooled.js\");\nconst { tooledStream, tooledComplete } = require(\"./helpers/tooled.js\");\nconst { RetryError } = require(\"../error.js\");\nconst { toValidNumber } = require(\"../../../http/index.js\");\n\nclass DeepSeekProvider extends InheritMultiple([Provider, UnTooled]) {\n model;\n\n constructor(config = {}) {\n super();\n const { model = \"deepseek-chat\" } = config;\n const client = new OpenAI({\n baseURL: \"https://api.deepseek.com/v1\",\n apiKey: process.env.DEEPSEEK_API_KEY ?? null,\n maxRetries: 3,\n });\n\n this._client = client;\n this.model = model;\n this.verbose = true;\n this.maxTokens = process.env.DEEPSEEK_MAX_TOKENS\n ? toValidNumber(process.env.DEEPSEEK_MAX_TOKENS, 1024)\n : 1024;\n }\n\n get client() {\n return this._client;\n }\n\n get supportsAgentStreaming() {\n return true;\n }\n\n /**\n * All current DeepSeek models (deepseek-chat and deepseek-reasoner)\n * support native OpenAI-compatible tool calling.\n * @returns {boolean}\n */\n supportsNativeToolCalling() {\n return true;\n }\n\n get #isThinkingModel() {\n return this.model === \"deepseek-reasoner\";\n }\n\n get #tooledOptions() {\n return this.#isThinkingModel ? { injectReasoningContent: true } : {};\n }\n\n async #handleFunctionCallChat({ messages = [] }) {\n return await this.client.chat.completions\n .create({\n model: this.model,\n messages,\n max_tokens: this.maxTokens,\n })\n .then((result) => {\n if (!result.hasOwnProperty(\"choices\"))\n throw new Error(\"DeepSeek chat: No results!\");\n if (result.choices.length === 0)\n throw new Error(\"DeepSeek chat: No results length!\");\n return result.choices[0].message.content;\n })\n .catch((_) => {\n return null;\n });\n }\n\n async #handleFunctionCallStream({ messages = [] }) {\n return await this.client.chat.completions.create({\n model: this.model,\n stream: true,\n messages,\n });\n }\n\n async stream(messages, functions = [], eventHandler = null) {\n const useNative = functions.length > 0 && this.supportsNativeToolCalling();\n\n if (!useNative) {\n return await UnTooled.prototype.stream.call(\n this,\n messages,\n functions,\n this.#handleFunctionCallStream.bind(this),\n eventHandler\n );\n }\n\n this.providerLog(\n \"Provider.stream (tooled) - will process this chat completion.\"\n );\n\n try {\n return await tooledStream(\n this.client,\n this.model,\n messages,\n functions,\n eventHandler,\n this.#tooledOptions\n );\n } catch (error) {\n console.error(error.message, error);\n if (error instanceof OpenAI.AuthenticationError) throw error;\n if (\n error instanceof OpenAI.RateLimitError ||\n error instanceof OpenAI.InternalServerError ||\n error instanceof OpenAI.APIError\n ) {\n throw new RetryError(error.message);\n }\n throw error;\n }\n }\n\n async complete(messages, functions = []) {\n const useNative = functions.length > 0 && this.supportsNativeToolCalling();\n\n if (!useNative) {\n return await UnTooled.prototype.complete.call(\n this,\n messages,\n functions,\n this.#handleFunctionCallChat.bind(this)\n );\n }\n\n try {\n const result = await tooledComplete(\n this.client,\n this.model,\n messages,\n functions,\n this.getCost.bind(this),\n this.#tooledOptions\n );\n\n if (result.retryWithError) {\n return this.complete([...messages, result.retryWithError], functions);\n }\n\n return result;\n } catch (error) {\n if (error instanceof OpenAI.AuthenticationError) throw error;\n if (\n error instanceof OpenAI.RateLimitError ||\n error instanceof OpenAI.InternalServerError ||\n error instanceof OpenAI.APIError\n ) {\n throw new RetryError(error.message);\n }\n throw error;\n }\n }\n\n /**\n * Get the cost of the completion.\n *\n * @param _usage The completion to get the cost for.\n * @returns The cost of the completion.\n */\n getCost(_usage) {\n return 0;\n }\n}\n\nmodule.exports = DeepSeekProvider;\n"}, "82c1cd0cee7a11d2c6f9e2ca819523dc086f0a9b": {"t": 1785754181.4899442, "n": 4398, "h": "5281d18d3b387e09", "c": "const OpenAI = require(\"openai\");\nconst Provider = require(\"./ai-provider.js\");\nconst InheritMultiple = require(\"./helpers/classes.js\");\nconst UnTooled = require(\"./helpers/untooled.js\");\nconst { tooledStream, tooledComplete } = require(\"./helpers/tooled.js\");\nconst { RetryError } = require(\"../error.js\");\nconst { toValidNumber } = require(\"../../../http/index.js\");\n\nclass DeepSeekProvider extends InheritMultiple([Provider, UnTooled]) {\n model;\n\n constructor(config = {}) {\n super();\n const { model = \"deepseek-chat\" } = config;\n const client = new OpenAI({\n baseURL: \"https://api.deepseek.com/v1\",\n apiKey: process.env.DEEPSEEK_API_KEY ?? null,\n maxRetries: 3,\n });\n\n this._client = client;\n this.model = model;\n this.verbose = true;\n this.maxTokens = process.env.DEEPSEEK_MAX_TOKENS\n ? toValidNumber(process.env.DEEPSEEK_MAX_TOKENS, 1024)\n : 1024;\n }\n\n get client() {\n return this._client;\n }\n\n get supportsAgentStreaming() {\n return true;\n }\n\n /**\n * All current DeepSeek models (deepseek-chat and deepseek-reasoner)\n * support native OpenAI-compatible tool calling.\n * @returns {boolean}\n */\n supportsNativeToolCalling() {\n return true;\n }\n\n get #isThinkingModel() {\n return this.model === \"deepseek-reasoner\";\n }\n\n get #tooledOptions() {\n return this.#isThinkingModel ? { injectReasoningContent: true } : {};\n }\n\n async #handleFunctionCallChat({ messages = [] }) {\n return await this.client.chat.completions\n .create({\n model: this.model,\n messages,\n max_tokens: this.maxTokens,\n })\n .then((result) => {\n if (!result.hasOwnProperty(\"choices\"))\n throw new Error(\"DeepSeek chat: No results!\");\n if (result.choices.length === 0)\n throw new Error(\"DeepSeek chat: No results length!\");\n return result.choices[0].message.content;\n })\n .catch((_) => {\n return null;\n });\n }\n\n async #handleFunctionCallStream({ messages = [] }) {\n return await this.client.chat.completions.create({\n model: this.model,\n stream: true,\n messages,\n });\n }\n\n async stream(messages, functions = [], eventHandler = null) {\n const useNative = functions.length > 0 && this.supportsNativeToolCalling();\n\n if (!useNative) {\n return await UnTooled.prototype.stream.call(\n this,\n messages,\n functions,\n this.#handleFunctionCallStream.bind(this),\n eventHandler\n );\n }\n\n this.providerLog(\n \"Provider.stream (tooled) - will process this chat completion.\"\n );\n\n try {\n return await tooledStream(\n this.client,\n this.model,\n messages,\n functions,\n eventHandler,\n this.#tooledOptions\n );\n } catch (error) {\n console.error(error.message, error);\n if (error instanceof OpenAI.AuthenticationError) throw error;\n if (\n error instanceof OpenAI.RateLimitError ||\n error instanceof OpenAI.InternalServerError ||\n error instanceof OpenAI.APIError\n ) {\n throw new RetryError(error.message);\n }\n throw error;\n }\n }\n\n async complete(messages, functions = []) {\n const useNative = functions.length > 0 && this.supportsNativeToolCalling();\n\n if (!useNative) {\n return await UnTooled.prototype.complete.call(\n this,\n messages,\n functions,\n this.#handleFunctionCallChat.bind(this)\n );\n }\n\n try {\n const result = await tooledComplete(\n this.client,\n this.model,\n messages,\n functions,\n this.getCost.bind(this),\n this.#tooledOptions\n );\n\n if (result.retryWithError) {\n return this.complete([...messages, result.retryWithError], functions);\n }\n\n return result;\n } catch (error) {\n if (error instanceof OpenAI.AuthenticationError) throw error;\n if (\n error instanceof OpenAI.RateLimitError ||\n error instanceof OpenAI.InternalServerError ||\n error instanceof OpenAI.APIError\n ) {\n throw new RetryError(error.message);\n }\n throw error;\n }\n }\n\n /**\n * Get the cost of the completion.\n *\n * @param _usage The completion to get the cost for.\n * @returns The cost of the completion.\n */\n getCost(_usage) {\n return 0;\n }\n}\n\nmodule.exports = DeepSeekProvider;\n"}}}}