A function to retrieve the directory of a program

本文提供了一种简单的方法来获取程序的运行目录。该方法对于确定配置文件的位置、图像的存储和加载路径等非常有用。通过使用GetModuleFileName函数并进行适当的字符串处理,可以确保即使在用户更改文件对话框中的目录时也能准确地获取程序所在目录。

I've needed to get the directory a program was running several times. I've used it to determine where configuration files could be found. I've used it for determining where images should be stored/loaded. I've also had to write it from scratch several times :( . I'm submitting it here so hopefully someone else doesn't have to figure it out themselves.

I've found that using _getcwd isn't accurate whenever the user is allowed to use the file dialogs to open or save files. If they move to a different directory in the file dialogs, the current working directory is changed as well

CString GetProgramDir()
{
    CString RtnVal;
    char    FileName[MAX_PATH];
    GetModuleFileName(AfxGetInstanceHandle(), FileName, MAX_PATH);
    RtnVal = FileName;
    RtnVal = RtnVal.Left(RtnVal.ReverseFind('//'));
    return RtnVal;
}

It's not much, but I've found it helpful and hope that someone else will as well.

http://www.codeproject.com/tips/programdir.asp?df=100&forumid=3336&exp=0&select=121652

LM Studio的logs报警如下 Developer Logs 2025-10-06 09:03:04 [DEBUG] Received request: POST to /v1/chat/completions with body { "messages": [ { "role": "system", "content": "Analyze if this message indicates a new conversati... <Truncated in logs> ... false). Only include these fields, no other text." }, { "role": "user", "content": "你好" } ], "model": "qwen3-coder-30b", "max_tokens": 4096, "stream": true, "stream_options": { "include_usage": true }, "temperature": 0 } 2025-10-06 09:03:04 [INFO] [LM STUDIO SERVER] Running chat completion on conversation with 2 messages. 2025-10-06 09:03:04 [INFO] [LM STUDIO SERVER] Streaming response... 2025-10-06 09:03:04 [DEBUG] Received request: POST to /v1/chat/completions with body { "messages": [ { "role": "system", "content": "You are Claude Code, Anthropic's official CLI for ... <Truncated in logs> ...unction in src/services/process.ts:712.\n</example>" }, { "role": "user", "content": [ { "type": "text", "text": "<system-reminder>\nThis is a reminder that your tod... <Truncated in logs> ...ntion this message to the user.\n</system-reminder>" }, { "type": "text", "text": "你好" } ] } ], "model": "qwen3-coder-30b", "max_tokens": 4096, "stream": true, "stream_options": { "include_usage": true }, "temperature": 1, "tools": [ { "type": "function", "function": { "name": "Task", "description": "Launch a new agent to handle complex, multi-step t... <Truncated in logs> ...the with the greeting-responder agent\"\n</example>\n", "parameters": { "type": "object", "properties": { "description": { "type": "string", "description": "A short (3-5 word) description of the task" }, "prompt": { "type": "string", "description": "The task for the agent to perform" }, "subagent_type": { "type": "string", "description": "The type of specialized agent to use for this task" } }, "required": [ "description", "prompt", "subagent_type" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "Bash", "description": "Executes a given bash command in a persistent shel... <Truncated in logs> ...Github PR: gh api repos/foo/bar/pulls/123/comments", "parameters": { "type": "object", "properties": { "command": { "type": "string", "description": "The command to execute" }, "timeout": { "type": "number", "description": "Optional timeout in milliseconds (max 600000)" }, "description": { "type": "string", "description": "Clear, concise description of what this command do... <Truncated in logs> ...s\n\nInput: mkdir foo\nOutput: Create directory 'foo'" }, "run_in_background": { "type": "boolean", "description": "Set to true to run this command in the background. Use BashOutput to read the output later." } }, "required": [ "command" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "Glob", "description": "- Fast file pattern matching tool that works with ... <Truncated in logs> ...arches in parallel if they are potentially useful.", "parameters": { "type": "object", "properties": { "pattern": { "type": "string", "description": "The glob pattern to match files against" }, "path": { "type": "string", "description": "The directory to search in. If not specified, the ... <Truncated in logs> ...avior. Must be a valid directory path if provided." } }, "required": [ "pattern" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "Grep", "description": "A powerful search tool built on ripgrep\n\n Usage:\n... <Truncated in logs> ...e `struct \\{[\\s\\S]*?field`, use `multiline: true`\n", "parameters": { "type": "object", "properties": { "pattern": { "type": "string", "description": "The regular expression pattern to search for in file contents" }, "path": { "type": "string", "description": "File or directory to search in (rg PATH). Defaults to current working directory." }, "glob": { "type": "string", "description": "Glob pattern to filter files (e.g. \"*.js\", \"*.{ts,tsx}\") - maps to rg --glob" }, "output_mode": { "type": "string", "enum": [ "content", "files_with_matches", "count" ], "description": "Output mode: \"content\" shows matching lines (suppo... <Truncated in logs> ...rts head_limit). Defaults to \"files_with_matches\"." }, "-B": { "type": "number", "description": "Number of lines to show before each match (rg -B). Requires output_mode: \"content\", ignored otherwise." }, "-A": { "type": "number", "description": "Number of lines to show after each match (rg -A). Requires output_mode: \"content\", ignored otherwise." }, "-C": { "type": "number", "description": "Number of lines to show before and after each match (rg -C). Requires output_mode: \"content\", ignored otherwise." }, "-n": { "type": "boolean", "description": "Show line numbers in output (rg -n). Requires output_mode: \"content\", ignored otherwise." }, "-i": { "type": "boolean", "description": "Case insensitive search (rg -i)" }, "type": { "type": "string", "description": "File type to search (rg --type). Common types: js,... <Truncated in logs> ...re efficient than include for standard file types." }, "head_limit": { "type": "number", "description": "Limit output to first N lines/entries, equivalent ... <Truncated in logs> ... When unspecified, shows all results from ripgrep." }, "multiline": { "type": "boolean", "description": "Enable multiline mode where . matches newlines and patterns can span lines (rg -U --multiline-dotall). Default: false." } }, "required": [ "pattern" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "ExitPlanMode", "description": "Use this tool when you are in plan mode and have f... <Truncated in logs> ...ed planning the implementation steps of the task.\n", "parameters": { "type": "object", "properties": { "plan": { "type": "string", "description": "The plan you came up with, that you want to run by... <Truncated in logs> ...ports markdown. The plan should be pretty concise." } }, "required": [ "plan" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "Read", "description": "Reads a file from the local filesystem. You can ac... <Truncated in logs> ...system reminder warning in place of file contents.", "parameters": { "type": "object", "properties": { "file_path": { "type": "string", "description": "The absolute path to the file to read" }, "offset": { "type": "number", "description": "The line number to start reading from. Only provide if the file is too large to read at once" }, "limit": { "type": "number", "description": "The number of lines to read. Only provide if the file is too large to read at once." } }, "required": [ "file_path" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "Edit", "description": "Performs exact string replacements in files. \n\nUsa... <Truncated in logs> ...ful if you want to rename a variable for instance.", "parameters": { "type": "object", "properties": { "file_path": { "type": "string", "description": "The absolute path to the file to modify" }, "old_string": { "type": "string", "description": "The text to replace" }, "new_string": { "type": "string", "description": "The text to replace it with (must be different from old_string)" }, "replace_all": { "type": "boolean", "default": false, "description": "Replace all occurences of old_string (default false)" } }, "required": [ "file_path", "old_string", "new_string" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "Write", "description": "Writes a file to the local filesystem.\n\nUsage:\n- T... <Truncated in logs> ...ts it. Avoid writing emojis to files unless asked.", "parameters": { "type": "object", "properties": { "file_path": { "type": "string", "description": "The absolute path to the file to write (must be absolute, not relative)" }, "content": { "type": "string", "description": "The content to write to the file" } }, "required": [ "file_path", "content" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "NotebookEdit", "description": "Completely replaces the contents of a specific cel... <Truncated in logs> ...te the cell at the index specified by cell_number.", "parameters": { "type": "object", "properties": { "notebook_path": { "type": "string", "description": "The absolute path to the Jupyter notebook file to edit (must be absolute, not relative)" }, "cell_id": { "type": "string", "description": "The ID of the cell to edit. When inserting a new c... <Truncated in logs> ...ith this ID, or at the beginning if not specified." }, "new_source": { "type": "string", "description": "The new source for the cell" }, "cell_type": { "type": "string", "enum": [ "code", "markdown" ], "description": "The type of the cell (code or markdown). If not sp... <Truncated in logs> ...type. If using edit_mode=insert, this is required." }, "edit_mode": { "type": "string", "enum": [ "replace", "insert", "delete" ], "description": "The type of edit to make (replace, insert, delete). Defaults to replace." } }, "required": [ "notebook_path", "new_source" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "WebFetch", "description": "\n- Fetches content from a specified URL and proces... <Truncated in logs> ...quest with the redirect URL to fetch the content.\n", "parameters": { "type": "object", "properties": { "url": { "type": "string", "format": "uri", "description": "The URL to fetch content from" }, "prompt": { "type": "string", "description": "The prompt to run on the fetched content" } }, "required": [ "url", "prompt" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "TodoWrite", "description": "Use this tool to create and manage a structured ta... <Truncated in logs> ...sures you complete all requirements successfully.\n", "parameters": { "type": "object", "properties": { "todos": { "type": "array", "items": { "type": "object", "properties": { "content": { "type": "string", "minLength": 1 }, "status": { "type": "string", "enum": [ "pending", "in_progress", "completed" ] }, "activeForm": { "type": "string", "minLength": 1 } }, "required": [ "content", "status", "activeForm" ], "additionalProperties": false }, "description": "The updated todo list" } }, "required": [ "todos" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "WebSearch", "description": "\n- Allows Claude to search the web and use the res... <Truncated in logs> ...s, do not use 2024 in the search query. Use 2025.\n", "parameters": { "type": "object", "properties": { "query": { "type": "string", "minLength": 2, "description": "The search query to use" }, "allowed_domains": { "type": "array", "items": { "type": "string" }, "description": "Only include search results from these domains" }, "blocked_domains": { "type": "array", "items": { "type": "string" }, "description": "Never include search results from these domains" } }, "required": [ "query" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "BashOutput", "description": "\n- Retrieves output from a running or completed ba... <Truncated in logs> ... Shell IDs can be found using the /bashes command\n", "parameters": { "type": "object", "properties": { "bash_id": { "type": "string", "description": "The ID of the background shell to retrieve output from" }, "filter": { "type": "string", "description": "Optional regular expression to filter the output l... <Truncated in logs> ... do not match will no longer be available to read." } }, "required": [ "bash_id" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "KillShell", "description": "\n- Kills a running background bash shell by its ID... <Truncated in logs> ... Shell IDs can be found using the /bashes command\n", "parameters": { "type": "object", "properties": { "shell_id": { "type": "string", "description": "The ID of the background shell to kill" } }, "required": [ "shell_id" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "SlashCommand", "description": "Execute a slash command within the main conversati... <Truncated in logs> ...heck the slash command file and consult the docs.\n", "parameters": { "type": "object", "properties": { "command": { "type": "string", "description": "The slash command to execute with its arguments, e.g., \"/review-pr 123\"" } }, "required": [ "command" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } } ] } 2025-10-06 09:03:04 [INFO] [LM STUDIO SERVER] Running chat completion on conversation with 2 messages. 2025-10-06 09:03:04 [INFO] [LM STUDIO SERVER] Streaming response... 2025-10-06 09:03:04 [DEBUG] Sampling params: repeat_last_n = 64, repeat_penalty = 1.050, frequency_penalty = 0.000, presence_penalty = 0.000 dry_multiplier = 0.000, dry_base = 1.750, dry_allowed_length = 2, dry_penalty_last_n = -1 top_k = 20, top_p = 0.800, min_p = 0.050, xtc_probability = 0.000, xtc_threshold = 0.100, typical_p = 1.000, top_n_sigma = -1.000, temp = 0.000 mirostat = 0, mirostat_lr = 0.100, mirostat_ent = 5.000 2025-10-06 09:03:04 [DEBUG] Sampling: logits -> logit-bias -> penalties -> dry -> top-n-sigma -> top-k -> typical -> top-p -> min-p -> xtc -> temp-ext -> dist Generate: n_ctx = 4096, n_batch = 512, n_predict = 4096, n_keep = 85 2025-10-06 09:03:04 [DEBUG] Looking for non-prefix contiguous prompt sequences of size >= 256 to reuse from cache Cache reuse summary: 1/85 of prompt (1.17647%), 1 prefix, 0 non-prefix Total prompt tokens: 85 Prompt tokens to decode: 84 BeginProcessingPrompt 2025-10-06 09:03:05 [DEBUG] FinishedProcessingPrompt. Progress: 100 2025-10-06 09:03:05 [DEBUG] Target model llama_perf stats: llama_perf_sampler_print: sampling time = 7.39 ms / 101 runs ( 0.07 ms per token, 13670.82 tokens per second) llama_perf_context_print: load time = 14685.56 ms llama_perf_context_print: prompt eval time = 884.78 ms / 84 tokens ( 10.53 ms per token, 94.94 tokens per second) llama_perf_context_print: eval time = 312.98 ms / 15 runs ( 20.87 ms per token, 47.93 tokens per second) llama_perf_context_print: total time = 1208.32 ms / 99 tokens llama_perf_context_print: graphs reused = 14 2025-10-06 09:03:05 [DEBUG] llama_memory_breakdown_print: | memory breakdown [MiB] | total free self model context compute unaccounted | llama_memory_breakdown_print: | - Vulkan0 (Pro VII) | 16368 = 15956 + (9297 = 9013 + 200 + 84) + 17592186035530 | llama_memory_breakdown_print: | - Vulkan1 (Pro VII) | 16368 = 15956 + (9068 = 8583 + 184 + 300) + 17592186035759 | llama_memory_breakdown_print: | - Host | 178 = 166 + 0 + 12 | 2025-10-06 09:03:05 [INFO] Finished streaming response 2025-10-06 09:03:05 [DEBUG] Sampling params: repeat_last_n = 64, repeat_penalty = 1.050, frequency_penalty = 0.000, presence_penalty = 0.000 dry_multiplier = 0.000, dry_base = 1.750, dry_allowed_length = 2, dry_penalty_last_n = -1 top_k = 20, top_p = 0.800, min_p = 0.050, xtc_probability = 0.000, xtc_threshold = 0.100, typical_p = 1.000, top_n_sigma = -1.000, temp = 1.000 mirostat = 0, mirostat_lr = 0.100, mirostat_ent = 5.000 2025-10-06 09:03:05 [DEBUG] Sampling: logits -> logit-bias -> penalties -> dry -> top-n-sigma -> top-k -> typical -> top-p -> min-p -> xtc -> temp-ext -> dist Generate: n_ctx = 4096, n_batch = 512, n_predict = 4096, n_keep = 12991 2025-10-06 09:03:05 [DEBUG] [LLM Engine bindings] PredictWorker::Execute - caught exception: Trying to keep the first 12991 tokens when context the overflows. However, the model is loaded with context length of only 4096 tokens, which is not enough. Try to load the model with a larger context length, or provide a shorter input 2025-10-06 09:03:05 [DEBUG] [lmstudio-llama-cpp] Error in predictTokens: Trying to keep the first 12991 tokens when context the overflows. However, the model is loaded with context length of only 4096 tokens, which is not enough. Try to load the model with a larger context length, or provide a shorter input 2025-10-06 09:03:05 [DEBUG] 1 Error predicting: _0x58de9f [Error]: Trying to keep the first 12991 tokens when context the overflows. However, the model is loaded with context length of only 4096 tokens, which is not enough. Try to load the model with a larger context length, or provide a shorter input at _0x50fca4.LLMEngineWrapper.predictTokens (D:\Program Files\LM Studio\resources\app\.webpack\lib\llmworker.js:85:30026) at async _0x30a92f.predictTokens (D:\Program Files\LM Studio\resources\app\.webpack\lib\llmworker.js:113:13964) at async _0x30a92f.handleMessage (D:\Program Files\LM Studio\resources\app\.webpack\lib\llmworker.js:113:2991) { cause: undefined, suggestion: undefined, errorData: undefined, data: undefined, displayData: undefined, title: 'Trying to keep the first 12991 tokens when context the overflows. However, the model is loaded with context length of only 4096 tokens, which is not enough. Try to load the model with a larger context length, or provide a shorter input' } 2025-10-06 09:03:05 [ERROR] Trying to keep the first 12991 tokens when context the overflows. However, the model is loaded with context length of only 4096 tokens, which is not enough. Try to load the model with a larger context length, or provide a shorter input. Error Data: n/a, Additional Data: n/a 2025-10-06 09:03:05 [DEBUG] Received request: POST to /v1/chat/completions with body { "messages": [ { "role": "system", "content": "You are Claude Code, Anthropic's official CLI for ... <Truncated in logs> ...unction in src/services/process.ts:712.\n</example>" }, { "role": "user", "content": [ { "type": "text", "text": "<system-reminder>\nThis is a reminder that your tod... <Truncated in logs> ...ntion this message to the user.\n</system-reminder>" }, { "type": "text", "text": "你好" } ] } ], "model": "qwen3-coder-30b", "max_tokens": 4096, "stream": false, "temperature": 1, "tools": [ { "type": "function", "function": { "name": "Task", "description": "Launch a new agent to handle complex, multi-step t... <Truncated in logs> ...the with the greeting-responder agent\"\n</example>\n", "parameters": { "type": "object", "properties": { "description": { "type": "string", "description": "A short (3-5 word) description of the task" }, "prompt": { "type": "string", "description": "The task for the agent to perform" }, "subagent_type": { "type": "string", "description": "The type of specialized agent to use for this task" } }, "required": [ "description", "prompt", "subagent_type" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "Bash", "description": "Executes a given bash command in a persistent shel... <Truncated in logs> ...Github PR: gh api repos/foo/bar/pulls/123/comments", "parameters": { "type": "object", "properties": { "command": { "type": "string", "description": "The command to execute" }, "timeout": { "type": "number", "description": "Optional timeout in milliseconds (max 600000)" }, "description": { "type": "string", "description": "Clear, concise description of what this command do... <Truncated in logs> ...s\n\nInput: mkdir foo\nOutput: Create directory 'foo'" }, "run_in_background": { "type": "boolean", "description": "Set to true to run this command in the background. Use BashOutput to read the output later." } }, "required": [ "command" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "Glob", "description": "- Fast file pattern matching tool that works with ... <Truncated in logs> ...arches in parallel if they are potentially useful.", "parameters": { "type": "object", "properties": { "pattern": { "type": "string", "description": "The glob pattern to match files against" }, "path": { "type": "string", "description": "The directory to search in. If not specified, the ... <Truncated in logs> ...avior. Must be a valid directory path if provided." } }, "required": [ "pattern" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "Grep", "description": "A powerful search tool built on ripgrep\n\n Usage:\n... <Truncated in logs> ...e `struct \\{[\\s\\S]*?field`, use `multiline: true`\n", "parameters": { "type": "object", "properties": { "pattern": { "type": "string", "description": "The regular expression pattern to search for in file contents" }, "path": { "type": "string", "description": "File or directory to search in (rg PATH). Defaults to current working directory." }, "glob": { "type": "string", "description": "Glob pattern to filter files (e.g. \"*.js\", \"*.{ts,tsx}\") - maps to rg --glob" }, "output_mode": { "type": "string", "enum": [ "content", "files_with_matches", "count" ], "description": "Output mode: \"content\" shows matching lines (suppo... <Truncated in logs> ...rts head_limit). Defaults to \"files_with_matches\"." }, "-B": { "type": "number", "description": "Number of lines to show before each match (rg -B). Requires output_mode: \"content\", ignored otherwise." }, "-A": { "type": "number", "description": "Number of lines to show after each match (rg -A). Requires output_mode: \"content\", ignored otherwise." }, "-C": { "type": "number", "description": "Number of lines to show before and after each match (rg -C). Requires output_mode: \"content\", ignored otherwise." }, "-n": { "type": "boolean", "description": "Show line numbers in output (rg -n). Requires output_mode: \"content\", ignored otherwise." }, "-i": { "type": "boolean", "description": "Case insensitive search (rg -i)" }, "type": { "type": "string", "description": "File type to search (rg --type). Common types: js,... <Truncated in logs> ...re efficient than include for standard file types." }, "head_limit": { "type": "number", "description": "Limit output to first N lines/entries, equivalent ... <Truncated in logs> ... When unspecified, shows all results from ripgrep." }, "multiline": { "type": "boolean", "description": "Enable multiline mode where . matches newlines and patterns can span lines (rg -U --multiline-dotall). Default: false." } }, "required": [ "pattern" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "ExitPlanMode", "description": "Use this tool when you are in plan mode and have f... <Truncated in logs> ...ed planning the implementation steps of the task.\n", "parameters": { "type": "object", "properties": { "plan": { "type": "string", "description": "The plan you came up with, that you want to run by... <Truncated in logs> ...ports markdown. The plan should be pretty concise." } }, "required": [ "plan" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "Read", "description": "Reads a file from the local filesystem. You can ac... <Truncated in logs> ...system reminder warning in place of file contents.", "parameters": { "type": "object", "properties": { "file_path": { "type": "string", "description": "The absolute path to the file to read" }, "offset": { "type": "number", "description": "The line number to start reading from. Only provide if the file is too large to read at once" }, "limit": { "type": "number", "description": "The number of lines to read. Only provide if the file is too large to read at once." } }, "required": [ "file_path" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "Edit", "description": "Performs exact string replacements in files. \n\nUsa... <Truncated in logs> ...ful if you want to rename a variable for instance.", "parameters": { "type": "object", "properties": { "file_path": { "type": "string", "description": "The absolute path to the file to modify" }, "old_string": { "type": "string", "description": "The text to replace" }, "new_string": { "type": "string", "description": "The text to replace it with (must be different from old_string)" }, "replace_all": { "type": "boolean", "default": false, "description": "Replace all occurences of old_string (default false)" } }, "required": [ "file_path", "old_string", "new_string" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "Write", "description": "Writes a file to the local filesystem.\n\nUsage:\n- T... <Truncated in logs> ...ts it. Avoid writing emojis to files unless asked.", "parameters": { "type": "object", "properties": { "file_path": { "type": "string", "description": "The absolute path to the file to write (must be absolute, not relative)" }, "content": { "type": "string", "description": "The content to write to the file" } }, "required": [ "file_path", "content" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "NotebookEdit", "description": "Completely replaces the contents of a specific cel... <Truncated in logs> ...te the cell at the index specified by cell_number.", "parameters": { "type": "object", "properties": { "notebook_path": { "type": "string", "description": "The absolute path to the Jupyter notebook file to edit (must be absolute, not relative)" }, "cell_id": { "type": "string", "description": "The ID of the cell to edit. When inserting a new c... <Truncated in logs> ...ith this ID, or at the beginning if not specified." }, "new_source": { "type": "string", "description": "The new source for the cell" }, "cell_type": { "type": "string", "enum": [ "code", "markdown" ], "description": "The type of the cell (code or markdown). If not sp... <Truncated in logs> ...type. If using edit_mode=insert, this is required." }, "edit_mode": { "type": "string", "enum": [ "replace", "insert", "delete" ], "description": "The type of edit to make (replace, insert, delete). Defaults to replace." } }, "required": [ "notebook_path", "new_source" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "WebFetch", "description": "\n- Fetches content from a specified URL and proces... <Truncated in logs> ...quest with the redirect URL to fetch the content.\n", "parameters": { "type": "object", "properties": { "url": { "type": "string", "format": "uri", "description": "The URL to fetch content from" }, "prompt": { "type": "string", "description": "The prompt to run on the fetched content" } }, "required": [ "url", "prompt" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "TodoWrite", "description": "Use this tool to create and manage a structured ta... <Truncated in logs> ...sures you complete all requirements successfully.\n", "parameters": { "type": "object", "properties": { "todos": { "type": "array", "items": { "type": "object", "properties": { "content": { "type": "string", "minLength": 1 }, "status": { "type": "string", "enum": [ "pending", "in_progress", "completed" ] }, "activeForm": { "type": "string", "minLength": 1 } }, "required": [ "content", "status", "activeForm" ], "additionalProperties": false }, "description": "The updated todo list" } }, "required": [ "todos" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "WebSearch", "description": "\n- Allows Claude to search the web and use the res... <Truncated in logs> ...s, do not use 2024 in the search query. Use 2025.\n", "parameters": { "type": "object", "properties": { "query": { "type": "string", "minLength": 2, "description": "The search query to use" }, "allowed_domains": { "type": "array", "items": { "type": "string" }, "description": "Only include search results from these domains" }, "blocked_domains": { "type": "array", "items": { "type": "string" }, "description": "Never include search results from these domains" } }, "required": [ "query" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "BashOutput", "description": "\n- Retrieves output from a running or completed ba... <Truncated in logs> ... Shell IDs can be found using the /bashes command\n", "parameters": { "type": "object", "properties": { "bash_id": { "type": "string", "description": "The ID of the background shell to retrieve output from" }, "filter": { "type": "string", "description": "Optional regular expression to filter the output l... <Truncated in logs> ... do not match will no longer be available to read." } }, "required": [ "bash_id" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "KillShell", "description": "\n- Kills a running background bash shell by its ID... <Truncated in logs> ... Shell IDs can be found using the /bashes command\n", "parameters": { "type": "object", "properties": { "shell_id": { "type": "string", "description": "The ID of the background shell to kill" } }, "required": [ "shell_id" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }, { "type": "function", "function": { "name": "SlashCommand", "description": "Execute a slash command within the main conversati... <Truncated in logs> ...heck the slash command file and consult the docs.\n", "parameters": { "type": "object", "properties": { "command": { "type": "string", "description": "The slash command to execute with its arguments, e.g., \"/review-pr 123\"" } }, "required": [ "command" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } } ] } 2025-10-06 09:03:05 [INFO] [LM STUDIO SERVER] Running chat completion on conversation with 2 messages. 2025-10-06 09:03:06 [DEBUG] Sampling params: repeat_last_n = 64, repeat_penalty = 1.050, frequency_penalty = 0.000, presence_penalty = 0.000 dry_multiplier = 0.000, dry_base = 1.750, dry_allowed_length = 2, dry_penalty_last_n = -1 top_k = 20, top_p = 0.800, min_p = 0.050, xtc_probability = 0.000, xtc_threshold = 0.100, typical_p = 1.000, top_n_sigma = -1.000, temp = 1.000 mirostat = 0, mirostat_lr = 0.100, mirostat_ent = 5.000 Sampling: logits -> logit-bias -> penalties -> dry -> top-n-sigma -> top-k -> typical -> top-p -> min-p -> xtc -> temp-ext -> dist Generate: n_ctx = 4096, n_batch = 512, n_predict = 4096, n_keep = 12991 2025-10-06 09:03:06 [DEBUG] [LLM Engine bindings] PredictWorker::Execute - caught exception: Trying to keep the first 12991 tokens when context the overflows. However, the model is loaded with context length of only 4096 tokens, which is not enough. Try to load the model with a larger context length, or provide a shorter input 2025-10-06 09:03:06 [DEBUG] [lmstudio-llama-cpp] Error in predictTokens: Trying to keep the first 12991 tokens when context the overflows. However, the model is loaded with context length of only 4096 tokens, which is not enough. Try to load the model with a larger context length, or provide a shorter input 1 Error predicting: _0x58de9f [Error]: Trying to keep the first 12991 tokens when context the overflows. However, the model is loaded with context length of only 4096 tokens, which is not enough. Try to load the model with a larger context length, or provide a shorter input at _0x50fca4.LLMEngineWrapper.predictTokens (D:\Program Files\LM Studio\resources\app\.webpack\lib\llmworker.js:85:30026) at async _0x30a92f.predictTokens (D:\Program Files\LM Studio\resources\app\.webpack\lib\llmworker.js:113:13964) at async _0x30a92f.handleMessage (D:\Program Files\LM Studio\resources\app\.webpack\lib\llmworker.js:113:2991) { cause: undefined, suggestion: undefined, errorData: undefined, data: undefined, displayData: undefined, title: 'Trying to keep the first 12991 tokens when context the overflows. However, the model is loaded with context length of only 4096 tokens, which is not enough. Try to load the model with a larger context length, or provide a shorter input' } 2025-10-06 09:03:06 [ERROR] Error: Channel Error
10-07
内容概要:本文详细介绍了一个基于Java和Vue的联邦学习隐私保护推荐系统的设计与实现。系统采用联邦学习架构,使用户数据在本地完成模型训练,仅上传加密后的模型参数或梯度,通过中心服务器进行联邦平均聚合,从而实现数据隐私保护与协同建模的双重目标。项目涵盖完整的系统架构设计,包括本地模型训练、中心参数聚合、安全通信、前后端解耦、推荐算法插件化等模块,并结合差分隐私与同态加密等技术强化安全性。同时,系统通过Vue前端实现用户行为采集与个性化推荐展示,Java后端支撑高并发服务与日志处理,形成“本地训练—参数上传—全局聚合—模型下发—个性化微调”的完整闭环。文中还提供了关键模块的代码示例,如特征提取、模型聚合、加密上传等,增强了项目的可实施性与工程参考价值。 适合人群:具备一定Java和Vue开发基础,熟悉Spring Boot、RESTful API、分布式系统或机器学习相关技术,从事推荐系统、隐私计算或全栈开发方向的研发人员。 使用场景及目标:①学习联邦学习在推荐系统中的工程落地方法;②掌握隐私保护机制(如加密传输、差分隐私)与模型聚合技术的集成;③构建高安全、可扩展的分布式推荐系统原型;④实现前后端协同的个性化推荐闭环系统。 阅读建议:建议结合代码示例深入理解联邦学习流程,重点关注本地训练与全局聚合的协同逻辑,同时可基于项目架构进行算法替换与功能扩展,适用于科研验证与工业级系统原型开发。
源码来自:https://pan.quark.cn/s/a4b39357ea24 遗传算法 - 简书 遗传算法的理论是根据达尔文进化论而设计出来的算法: 人类是朝着好的方向(最优解)进化,进化过程中,会自动选择优良基因,淘汰劣等基因。 遗传算法(英语:genetic algorithm (GA) )是计算数学中用于解决最佳化的搜索算法,是进化算法的一种。 进化算法最初是借鉴了进化生物学中的一些现象而发展起来的,这些现象包括遗传、突变、自然选择、杂交等。 搜索算法的共同特征为: 首先组成一组候选解 依据某些适应性条件测算这些候选解的适应度 根据适应度保留某些候选解,放弃其他候选解 对保留的候选解进行某些操作,生成新的候选解 遗传算法流程 遗传算法的一般步骤 my_fitness函数 评估每条染色体所对应个体的适应度 升序排列适应度评估值,选出 前 parent_number 个 个体作为 待选 parent 种群(适应度函数的值越小越好) 从 待选 parent 种群 中随机选择 2 个个体作为父方和母方。 抽取父母双方的染色体,进行交叉,产生 2 个子代。 (交叉概率) 对子代(parent + 生成的 child)的染色体进行变异。 (变异概率) 重复3,4,5步骤,直到新种群(parentnumber + childnumber)的产生。 循环以上步骤直至找到满意的解。 名词解释 交叉概率:两个个体进行交配的概率。 例如,交配概率为0.8,则80%的“夫妻”会生育后代。 变异概率:所有的基因中发生变异的占总体的比例。 GA函数 适应度函数 适应度函数由解决的问题决定。 举一个平方和的例子。 简单的平方和问题 求函数的最小值,其中每个变量的取值区间都是 [-1, ...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值