gitdiagram源码架构分析
https://github.com/ahmedkhaleel2004/gitdiagram
整体架构分析
前端请求入口:
后端对应接口:
后端调试
后端调试:会提示api_key失败的问题:
有两种方法解决:
1、注释掉下面的行代码;
方法二:登录openai网站配置一个api key;
然后在这里写死:
直接后端调试成功:
生成的结果信息:
包含3个内容,后续重点分析file_tree;
调用逻辑梳理
获取文件列表的定义函数
定义了很多需要过滤掉的目录和文件后缀名:
调用的github接口:
api_url = f"https://api.github.com/repos/{username}/{repo}/git/trees/{branch}?recursive=1"
实际传入的3个参数:
ahmedkhaleel2004/gitdiagram,前两个参数从开源项目的github地址的两段拆出,分别对应username和repo;
ahmedkhaleel2004
gitdiagram
main
回到结果,返回的是文件列表信息,并不能够生成mermaid调用关系图;需要继续分析源;
通过调用大模型接口生成mermaid图,传入的参数有3个;
data={
"explanation": explanation,
"component_mapping": component_mapping_text,
"instructions": body.instructions,
},
explanation根据file_tree和readme生成:
component_mapping_text根据explanation和file_tree生成:
所以,component_mapping_text组件的映射关系,是由大模型生成的?本地调试验证看看。