MCPcopy
hub / github.com/AstrBotDevs/AstrBot / _apply_file_extract

Function _apply_file_extract

astrbot/core/astr_main_agent.py:301–347  ·  view source on GitHub ↗
(
    event: AstrMessageEvent,
    req: ProviderRequest,
    config: MainAgentBuildConfig,
)

Source from the content-addressed store, hash-verified

299
300
301async def _apply_file_extract(
302 event: AstrMessageEvent,
303 req: ProviderRequest,
304 config: MainAgentBuildConfig,
305) -> None:
306 file_paths = []
307 file_names = []
308 for comp in event.message_obj.message:
309 if isinstance(comp, File):
310 file_paths.append(await comp.get_file())
311 file_names.append(comp.name)
312 elif isinstance(comp, Reply) and comp.chain:
313 for reply_comp in comp.chain:
314 if isinstance(reply_comp, File):
315 file_paths.append(await reply_comp.get_file())
316 file_names.append(reply_comp.name)
317 if not file_paths:
318 return
319 if not req.prompt:
320 req.prompt = "总结一下文件里面讲了什么?"
321 if config.file_extract_prov == "moonshotai":
322 if not config.file_extract_msh_api_key:
323 logger.error("Moonshot AI API key for file extract is not set")
324 return
325 file_contents = await asyncio.gather(
326 *[
327 extract_file_moonshotai(
328 file_path,
329 config.file_extract_msh_api_key,
330 )
331 for file_path in file_paths
332 ]
333 )
334 else:
335 logger.error("Unsupported file extract provider: %s", config.file_extract_prov)
336 return
337
338 for file_content, file_name in zip(file_contents, file_names):
339 req.contexts.append(
340 {
341 "role": "system",
342 "content": (
343 "File Extract Results of user uploaded files:\n"
344 f"{file_content}\nFile Name: {file_name or 'Unknown'}"
345 ),
346 },
347 )
348
349
350def _apply_prompt_prefix(req: ProviderRequest, cfg: dict) -> None:

Callers 1

build_main_agentFunction · 0.85

Calls 4

extract_file_moonshotaiFunction · 0.90
get_fileMethod · 0.80
appendMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected