MCPcopy Create free account

hub / github.com/Hoper-J/AI-Guide-and-Demos-zh_CN / functions

Functions68 in github.com/Hoper-J/AI-Guide-and-Demos-zh_CN

↓ 5 callersMethodcheck_installation
检查是否已安装模块并提供安装提示。 参数: module_name (str): 模块名称 install_instructions (str): 如果未安装模块时,显示的安装指引
CodePlayground/utils/environment_manager.py:37
↓ 5 callersFunctionload_config
从 YAML 配置文件中加载指定脚本的默认配置。 参数: config_file (str): 配置文件的路径,默认为 'config.yaml' script_name (str): 当前脚本的名称,用于区分配置项 返回:
CodePlayground/utils/config_manager.py:5
↓ 4 callersMethodadd_message
添加一条消息到会话中。 参数: role (str): 消息角色,通常为 'user' 或 'assistant' content (str): 消息内容
CodePlayground/chat.py:72
↓ 4 callersFunctiondebug_func_metadata
调试版本的 func_metadata 实现,会用到一些 from_function 中的逻辑,比如:func.__name__,func.__doc__ ...
Demos/mcp/debug_func_metadata.py:36
↓ 3 callersFunctionread_subtitle
读取字幕文件内容,并根据参数决定是否包含时间信息。 参数: file_path (str): 字幕文件的路径 timestamped (bool): 如果为 True,返回包含时间戳的字幕文本,默认为 False 返回:
CodePlayground/summarizer.py:153
↓ 2 callersMethod__init__
(self, content: str | ContentBlock, **kwargs: Any)
Demos/mcp/debug_message_validator.py:19
↓ 2 callersMethod__init__
初始化对话会话。 参数: messages: 已加载的对话历史,默认为空列表 no_stream (bool): 是否禁用流式输出 history_path (str): 对话历史文件的路径
CodePlayground/chat.py:34
↓ 2 callersMethod_append_user_message
添加用户消息,同时检查是否存在连续用户输入, 如果检测到连续的用户输入,则输出中文警告并自动调整对话流程,确保消息角色交替以避免可能的报错: jinja2.exceptions.TemplateError: Conversation roles mu
CodePlayground/chat.py:136
↓ 2 callersMethodcheck_autoawq
检查 AutoAWQ 的安装情况。
CodePlayground/utils/environment_manager.py:99
↓ 2 callersMethodcheck_autogptq
检查 AutoGPTQ 的安装情况,并提供 CUDA 支持建议。
CodePlayground/utils/environment_manager.py:83
↓ 2 callersMethodcheck_llama_cpp
检查 Llama-cpp-python 的安装情况。
CodePlayground/utils/environment_manager.py:108
↓ 2 callersMethodcheck_pytorch_transformers
检查 PyTorch 和 Transformers 的安装情况。
CodePlayground/utils/environment_manager.py:59
↓ 2 callersFunctionformat_timestamp
格式化时间戳,去掉小数点后部分。 参数: timestamp (datetime.timedelta): Whisper 模型生成的时间戳 返回: str: 去掉小数点后部分的时间戳,格式为 'HH:MM:SS'
CodePlayground/summarizer.py:139
↓ 2 callersFunctionprint_json
打印JSON数据
Demos/mcp/debug_func_metadata.py:25
↓ 1 callersMethod_handle_stream_output
处理流式输出,将生成的内容逐步打印出来,并收集完整的回复。 参数: output: 生成器对象,来自 create_chat_completion 的流式输出。 返回: response: 完整的回
CodePlayground/chat.py:200
↓ 1 callersFunctionconfigure_logging
配置日志输出和警告过滤。 参数: verbose (bool): 是否启用详细日志
CodePlayground/chat.py:376
↓ 1 callersFunctioncreate_chat_session
根据模型路径和类型创建适当的 ChatSession 实例。 参数: model_name_or_path (str): 模型的名称或本地路径 max_length (int): 生成文本的最大长度 no_stream (bool)
CodePlayground/chat.py:291
↓ 1 callersFunctiondebug_pydantic_union_behavior
深入分析 Pydantic Union 类型选择行为 解释为什么 role='assistant' 时返回 UserMessage 而不是 AssistantMessage
Demos/mcp/debug_message_validator.py:294
↓ 1 callersFunctiondemo_message_validator
调试版本的 message_validator 演示 展示 FastMCP 中字典如何转换为 Message 对象
Demos/mcp/debug_message_validator.py:55
↓ 1 callersFunctiondemo_prompt_render_simulation
模拟 Prompt.render() 中的消息转换过程 展示用户函数返回值如何被处理成标准 MCP 消息
Demos/mcp/debug_message_validator.py:186
↓ 1 callersFunctiongenerate_after_training
训练完成后生成图像的函数
CodePlayground/sd_lora.py:572
↓ 1 callersFunctiongenerate_images
使用 DiffusionPipeline 生成图像,保存到指定文件夹并返回生成的图像列表。 参数: pipeline (DiffusionPipeline): 已加载并配置好的 Pipeline prompts (list): 文本提示列表
CodePlayground/sd_lora.py:251
↓ 1 callersFunctionget_api_key
从配置文件中获取 API 密钥。如果配置中没有 API 密钥,则提示用户输入并保存到配置文件中。 验证密钥是否有效,如果无效则提示重新输入。 返回: str: 验证后的 API 密钥
CodePlayground/utils/config_manager.py:52
↓ 1 callersFunctionget_file_type
根据文件扩展名判断文件类型。 参数: file_path (str): 文件的路径 返回: str: 文件类型,返回 'video', 'audio', 'subtitle' 或 'unknown'
CodePlayground/summarizer.py:36
↓ 1 callersMethodget_response
这是一个抽象方法,需要在子类中实现。 参数: user_input (str): 用户输入的文本
CodePlayground/chat.py:114
↓ 1 callersMethodhandle_user_input
处理用户输入,包括捕获 EOF 输入和退出命令。 返回: str: 用户输入的文本 bool: 是否应该终止会话
CodePlayground/chat.py:94
↓ 1 callersMethodload_config
加载 YAML 配置文件。 参数: config_file (str): 配置文件路径 返回: dict: 配置字典
CodePlayground/utils/environment_manager.py:17
↓ 1 callersMethodload_history
加载对话历史记录。 参数: history_path (str): 对话历史文件的路径 返回: list: 已加载的对话历史,默认为空列表
CodePlayground/chat.py:48
↓ 1 callersFunctionload_validation_prompts
加载验证提示文本。 参数: validation_prompt_path (str): 验证提示文件的路径,每一行对应一个 prompt,参考示例文件 返回: list: prompt 列表
CodePlayground/sd_lora.py:237
↓ 1 callersFunctionmain
()
CodePlayground/summarizer.py:345
↓ 1 callersFunctionmain
()
CodePlayground/chat.py:395
↓ 1 callersFunctionmain
()
CodePlayground/sd_lora.py:375
↓ 1 callersFunctionparse_args
解析命令行参数,用于训练和生成流程。 默认值取自 config.yaml 的 'train' 和 'generate' 配置。所有参数均为可选项。
CodePlayground/sd_lora.py:286
↓ 1 callersFunctionprepare_lora_model
加载完整的 Stable Diffusion 模型,包括 LoRA 层。 参数: lora_config (LoraConfig): LoRA 的配置对象 pretrained_model_name_or_path (str): Hugging F
CodePlayground/sd_lora.py:108
↓ 1 callersFunctionprepare_optimizer
为 UNet 和文本编码器的可训练参数分别设置优化器,并指定不同的学习率。 参数: unet (UNet2DConditionModel): Hugging Face 的 UNet 模型 text_encoder (CLIPTextModel):
CodePlayground/sd_lora.py:194
↓ 1 callersFunctionprocess_file
根据文件类型处理文件并生成摘要。处理包括视频文件转换为音频、音频转录为字幕等。 参数: file_path (str): 要处理的文件路径 client (OpenAI): OpenAI 客户端实例 output_dir (str
CodePlayground/summarizer.py:262
↓ 1 callersFunctionsave_config
将配置保存到 YAML 文件中。如果文件已存在,则更新其中的内容。 参数: config (dict): 要保存的配置 config_file (str): 配置文件的路径,默认为 'config.yaml' script_
CodePlayground/utils/config_manager.py:28
↓ 1 callersMethodsave_history
保存对话历史到文件。
CodePlayground/chat.py:82
↓ 1 callersMethodsetup_chat_by_model
根据传入的模型路径来判断需要检查哪些依赖。 例如: GGUF: 只需要 llama-cpp-python GPTQ: 需要 auto_gptq AWQ: 需要 autoawq
CodePlayground/utils/environment_manager.py:128
↓ 1 callersFunctionsimulate_render_conversion
模拟 render() 方法中的转换逻辑 按照 FastMCP 的实际处理顺序进行转换
Demos/mcp/debug_message_validator.py:221
↓ 1 callersMethodstart
启动对话会话,处理输入和响应,直到用户退出。
CodePlayground/chat.py:123
↓ 1 callersFunctionsummarize_text
注意,我们没有对字幕文件做更多的处理,没有滑动窗口,没有文本清理,没有语义分割。 只是使用 Prompt 指导模型生成摘要。即(美名其曰):In-context Learning. 参数: text (str): 要生成摘要的字幕或文本内容
CodePlayground/summarizer.py:194
↓ 1 callersFunctiontest
测试各种类型的函数
Demos/mcp/debug_func_metadata.py:220
↓ 1 callersFunctiontest
测试各种类型的 message_validator 行为
Demos/mcp/debug_message_validator.py:362
↓ 1 callersFunctiontranscribe_audio
使用 Whisper 模型转录音频,并保存为字幕文件(SRT 格式)。 参数: audio_path (str): 音频文件的路径 subtitle_path (str): 要保存的字幕文件的路径 decode_options (d
CodePlayground/summarizer.py:83
↓ 1 callersFunctionvideo_to_audio
使用 ffmpeg 将视频文件转换为音频文件(WAV 格式)。 参数: video_path (str): 视频文件的路径 audio_path (str): 保存音频文件的路径。如果未指定,将使用视频文件名并保存为同名的 WAV 文件
CodePlayground/summarizer.py:56
Method__getitem__
(self, idx)
CodePlayground/sd_lora.py:90
Method__init__
(self, content: str | ContentBlock, **kwargs: Any)
Demos/mcp/debug_message_validator.py:34
Method__init__
(self, content: str | ContentBlock, **kwargs: Any)
Demos/mcp/debug_message_validator.py:46
Method__init__
初始化 Llama 对话会话。 参数: llm: Llama 模型实例 max_length (int): 生成文本的最大长度 no_stream (bool): 是否禁用流式输出
CodePlayground/chat.py:152
Method__init__
初始化 Transformers 对话会话。 参数: model: Transformers 模型实例 tokenizer: 模型的分词器 max_length (int): 生成文本的最大长
CodePlayground/chat.py:224
Method__init__
(self, images_folder, captions_folder, transform, tokenizer)
CodePlayground/sd_lora.py:65
Method__init__
初始化环境管理器,并加载配置文件。 参数: config_file (str): 配置文件路径,默认为 'environment.yaml'
CodePlayground/utils/environment_manager.py:7
Method__len__
(self)
CodePlayground/sd_lora.py:105
Functionadd
(a: int, b: int)
Demos/mcp/debug_func_metadata.py:243
Functioncollate_fn
(examples)
CodePlayground/sd_lora.py:224
Functionfunc
展示各种注解情况
Demos/mcp/debug_func_metadata.py:224
Functiongenerate
()
Demos/app_flask.py:15
Functiongenerate_text
(request: PromptRequest)
Demos/app_fastapi.py:20
Functionget_cities
返回支持查询天气的城市列表
Demos/mcp/server.py:33
Functionget_city_weather
(city: str)
Demos/mcp/server.py:39
Methodget_device
(self)
CodePlayground/utils/environment_manager.py:159
Methodget_response
获取 Llama 模型对用户输入的响应(支持流式输出)。 参数: user_input (str): 用户输入的文本 返回: response (str): 完整的回复文本
CodePlayground/chat.py:167
Methodget_response
获取 Transformers 模型对用户输入的响应(支持流式输出)。 参数: user_input (str): 用户输入的文本 返回: response (str): 完整的回复
CodePlayground/chat.py:253
Functionget_weather
获取指定城市的天气信息
Demos/mcp/server.py:11
Functionprefix_func
前缀参数
Demos/mcp/debug_func_metadata.py:237
Methodsetup_chat_strict
检查 torch, transformers, autogptq, autoawq 和 llama-cpp-python 是否安装。
CodePlayground/utils/environment_manager.py:118
Functionweather
提供天气查询的对话模板
Demos/mcp/server.py:23