通用技术 调用 GPT3.5 生成思维导图用例

JoyMao · 2023年06月15日 · 最后由 奇迹的迹奇 回复于 2023年09月27日 · 6072 次阅读

开头:这里不是说 GPT3.5 有画图的功能,而是是让 GPT3.5 按照一定的提示语,生成满足特定 mindmap 格式结构的数据,借助特定工具渲染出来。

这个功能目前已经在我们的测试用例工具中提供,用户在用例描述中放入特定需求,就可以调用 AI 来生成思维导图了:

一个用法就是那些时间较紧的任务,可以通过它快速生成思维导图,然后执行用例提 bug。

还可以通过它快速搭建 1 个思维导图框架,方便丰富完善。

注:不是所有需求都合适,只有 “人” 认为可以画思维导图的才合适,而且需要有明确的主题;不然生成的内容肯定不是你想要的

核心就提供一个准确提示语,能让 AI 准确的生成满足你的工具中用的思维导图要求的 json,以下是多次调试后,准确率很高的提示语(针对 gg-editor 的思维导图):

def getTSPMindmapMsg(caseRulesDescription):
    """
    按规则给出思维导图的提示信息
    """
    sample = """
        请根据需求,直接给出思维导图的json格式数据(不需要注释、说明):roots是中心主题列表,格式为list,只有1个中心主题;
        每个主题中:
        label属性是主题内容,格式为string;
        id属性从1开始,每个主题递增1,格式为string;
        side属性均为"right",格式为string;
        children属性是子主题列表,格式为list,每个子主题同样有属性lable、id、side、children。
        需求如下:
        {rulesDescription}
        """
    # print sample.format(rulesDescription=caseRulesDescription)
    return {
        'role': 'user',
        'content': sample.format(rulesDescription=caseRulesDescription).strip()
    }

补充项:
调用 OpenAI 的 AI 接口(https://api.openai.com/v1/chat/completions)就不赘述了,如果这里想防止生成的 json 格式不满足特定的 mindmap 的格式,可以增加一个 json schema 的校验。
如果愿意的话,校验异常的情况下,可以通过追加对话的方式,将 json schema 校验结果告诉 AI 再次调整(设定重试次数?)
比如这里 gg-editor 思维导图的 json-schema:

{
        "$schema": "http://json-schema.org/draft-07/schema#",
        "title": "gg-editor mindmap json schema",
        "description": "validate gpt returns",
        "type": "object",
        "definitions":{
            "node":{
                    "type": "object",
                    "properties": {
                        "side": {
                            "description": "node position",
                            "type": "string"
                        },
                        "id": {
                            "description": "node id",
                            "type": "string"
                        },
                        "label": {
                            "description": "node title,the theme",
                            "type": "string"
                        },
                        "children": {
                            "description": "roots nodes",
                            "type": "array",
                            "items": {
                                "$ref":"#/definitions/node"
                            }
                        }
                    },
                    "required": ["side", "id", "label"]
                }
        },
        "properties": {
            "roots": {
                "description": "roots nodes",
                "type": "array",
                "items": {
                    "$ref":"#/definitions/node"
                },
                "minItems": 1,
                "maxItems": 1
            },
        },
        "required": ["roots"]
    }
共收到 4 条回复 时间 点赞

mark,感觉前置话术挺重要的而且固定,如果 ai 听得懂很稳定的话是很值得分享的,至于需求那就五花八门了。顺便借楼问下,有没有那个论坛专门分享类似成功案例的

Vanessa 回复

没有特别去找过特定的论坛,但 github 上有相关项目是关于 chatgpt prompt 的:https://github.com/f/awesome-chatgpt-prompts
我们这个例子中的提示语是不断完善出来的,把大家日常中遇到的各种异常都存下来,逐渐调试出来的。

lsq54264 回复

您好 是如何通过问答结果直接放置到脑图中的呢?

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册