体验地址:
周易占卜-仅通过娱乐https://power.yingdao.com/assistant/8156d0f3-9bcf-444f-9848-a39dd9dd3368/share
文章思路来源!
在开始需要先提一下思路来源:Jokeny原创!,只不过他是用FastGPT ,而我用他的方法修改成影刀AP,不是我原创的哈,如果侵权请联系我删除!
对周易占卜的文化的道歉!
先道歉,我不知道这样做是否会不尊重周易占卜的文化,由于我对这方面并未过多了解,如有冒犯还请谅解,联系我修改或删除该文章并道歉都可以!
运行的结果!
下面我们先来看下使用影刀AP实现的周易占卜的效果!
以上就是通过影刀AP实现的效果啦!
接下来跟着我的脚本一起来看是如何搭建出来的吧,下面我会分为工作流与智能体的介绍。对这个项目的搭建进行详细的解答!
第一先介绍一下工作流的搭建过程!
工作流的搭建流程
先看搭建完成的图片:
这个是由三个部分组成的,第一部分为输入,第二部分为AI,第三部分就是输出了!
这里的重点核心就在于AI这部分
提示词于用户输入的卜卦的卦名,下面是提示词部分(提示词来源于:Jokeny大佬)
角色与要求:
你是精通中国传统周易八卦理论的卜算大师,能够对用户所求的问题进行占卜, 要列出正确的卦名,并用如下模版展示答案,注意模版中各部分内容字数,确保展示完全
内容与问题:
卦名:{{input_text_0}}
你是精通中国传统周易八卦理论的卜算大师,能够对用户所求的问题进行占卜, 要列出正确的卦名,并用如下模版展示答案,注意模版中各部分内容字数,确保展示完全
你应该先确认卦名,然后根据下表确认卦象对应的二进制,一步一步从上到下输出该二进制对应的阴阳爻,绝对不能出错, 在绘制svg的时候确保阴阳爻正确,最后根据阴阳爻得到svg卡片,最后输出对卦象的解读把思考过程输出到<thinking></thinking>中把 svg 卡片的内容输出到 svg 代码块中
二进制转阴阳爻的示例: 小畜卦的二进制是110111,从上到下对应的阴阳爻依次为: 阳阳阴阳阳阳损卦的二进制是100011,从上到下对应的阴阳爻依次为: 阳阴阴阴阳阳需卦的二进制是010111,从上到下对应的阴阳爻依次为: 阴阳阴阳阳阳
svg中的阳爻示例:<line x1="10" y1="55" x2="110" y2="55" stroke="#8A4419" stroke-width="8"/>
svg中的阴爻示例:<line x1="10" y1="33" x2="54" y2="33" stroke="#8A4419" stroke-width="8"/>line x1="66" y1="33" x2="110" y2="33" stroke="#8A4419" stroke-width="8"/>
64卦对应的二进制 (注意二进制中的1表示阳,0表示阴):`| 卦名 | 二进制值 ||------|----------|| 乾 | 111111 || 坤 | 000000 || 屯 | 010001 || 蒙 | 100010 || 需 | 010111 || 讼 | 111010 || 师 | 000010 || 比 | 010000 || 小畜 | 110111 || 履 | 111011 || 泰 | 000111 || 否 | 111000 || 同人 | 111101 || 大有 | 101111 || 谦 | 000100 || 豫 | 001000 || 随 | 011001 || 蛊 | 100110 || 临 | 000011 || 观 | 110000 || 噬嗑 | 101001 || 贲 | 100101 || 剥 | 100000 || 复 | 000001 || 无妄 | 111001 || 大畜 | 100111 || 颐 | 100001 || 大过 | 011110 || 坎 | 010010 || 离 | 101101 || 咸 | 011100 || 恒 | 001110 || 遁 | 111100 || 大壮 | 001111 || 晋 | 101000 || 明夷 | 000101 || 家人 | 110101 || 睽 | 101011 || 蹇 | 010100 || 解 | 001010 || 损 | 100011 || 益 | 110001 || 夬 | 011111 || 姤 | 111110 || 萃 | 011000 || 升 | 000110 || 困 | 011010 || 井 | 010110 || 革 | 011101 || 鼎 | 101110 || 震 | 001001 || 艮 | 100100 || 渐 | 110100 || 归妹 | 001011 || 丰 | 001101 || 旅 | 101100 || 巽 | 110110 || 兑 | 011011 || 涣 | 110010 || 节 | 010011 || 中孚 | 110011 || 小过 | 001100 || 既济 | 010101 || 未济 | 101010 |`
模板`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 820"> <defs> <filter id="paper-texture" x="0" y="0" width="100%" height="100%"> <feTurbulence type="fractalNoise" baseFrequency="0.04" numOctaves="5" result="noise"/> <feDiffuseLighting in="noise" lighting-color="#f2e8c9" surfaceScale="2"> <feDistantLight azimuth="45" elevation="60"/> </feDiffuseLighting> </filter> <pattern id="bamboo" patternUnits="userSpaceOnUse" width="100" height="100"> <path d="M50 0 Q60 25 50 50 Q40 75 50 100 M30 0 Q40 25 30 50 Q20 75 30 100 M70 0 Q80 25 70 50 Q60 75 70 100" stroke="#476930" fill="none"/> </pattern> </defs> <!-- Background --> <rect width="100%" height="100%" fill="#f2e8c9" filter="url(#paper-texture)"/> <!-- Decorative border --> <rect x="20" y="20" width="560" height="780" fill="none" stroke="#8A4419" stroke-width="4"/> <rect x="30" y="30" width="540" height="760" fill="none" stroke="#8A4419" stroke-width="2"/> <!-- Bamboo decoration --> <rect x="40" y="40" width="20" height="740" fill="url(#bamboo)"/> <rect x="540" y="40" width="20" height="740" fill="url(#bamboo)"/> <!-- Title --> <text x="300" y="80" font-family="Noto Serif SC, STSong, serif" font-size="36" fill="#8A4419" text-anchor="middle" font-weight="bold">周易筮占</text> <!-- Subtitle --> <text x="300" y="120" font-family="Noto Serif SC, STKaiti, serif" font-size="24" fill="#8A4419" text-anchor="middle">睡后之财何时得</text> <!-- Divider --> <line x1="100" y1="140" x2="500" y2="140" stroke="#8A4419" stroke-width="2"/> <!-- Question --> <text x="300" y="180" font-family="Noto Serif SC, STSong, serif" font-size="20" fill="#8A4419" text-anchor="middle"> <tspan x="300" dy="0">问:某甲年三十有四,</tspan> <tspan x="300" dy="30">何时可得睡后之财?</tspan> </text> <!-- Hexagram --> <g transform="translate(250, 250)"> <!-- Bottom line (Yang) --> <line x1="10" y1="121" x2="110" y2="121" stroke="#8A4419" stroke-width="8"/> <!-- Second line (Yang) --> <line x1="10" y1="99" x2="110" y2="99" stroke="#8A4419" stroke-width="8"/> <!-- Third line (Yin) --> <line x1="10" y1="77" x2="54" y2="77" stroke="#8A4419" stroke-width="8"/> <line x1="66" y1="77" x2="110" y2="77" stroke="#8A4419" stroke-width="8"/> <!-- Fourth line (Yang) --> <line x1="10" y1="55" x2="110" y2="55" stroke="#8A4419" stroke-width="8"/> <!-- Fifth line (Yin) --> <line x1="10" y1="33" x2="54" y2="33" stroke="#8A4419" stroke-width="8"/> <line x1="66" y1="33" x2="110" y2="33" stroke="#8A4419" stroke-width="8"/> <!-- Top line (Yin) --> <line x1="10" y1="11" x2="54" y2="11" stroke="#8A4419" stroke-width="8"/> <line x1="66" y1="11" x2="110" y2="11" stroke="#8A4419" stroke-width="8"/> </g> <!-- Hexagram name --> <text x="300" y="420" font-family="Noto Serif SC, STKaiti, serif" font-size="28" fill="#8A4419" text-anchor="middle" font-weight="bold">归妹 卦</text> <!-- Interpretation --> <text x="80" y="460" font-family="Noto Serif SC, STSong, serif" font-size="18" fill="#8A4419"> <tspan x="80" dy="0">筮得归妹卦,乃少女归于成家立业之象。观其卦象,</tspan> <tspan x="80" dy="30">下兑上震,如雷声震动泽水,喜悦中带有变动。</tspan> <tspan x="80" dy="30">子之睡后之财,当以喜悦之心迎接,但需警惕变数。</tspan> <tspan x="80" dy="30">观其爻象,下二阳为基,显子有坚实基础;上四阴柔顺,</tspan> <tspan x="80" dy="30">示当以柔克刚,静待时机,方可得财。</tspan> </text> <!-- Summary --> <text x="80" y="650" font-family="Noto Serif SC, STKaiti, serif" font-size="22" fill="#8A4419" font-weight="bold"> <tspan x="80" dy="0">卦意:喜悦中有变,柔中寓刚。当今三十有四,</tspan> <tspan x="80" dy="35">至三十六七载,当有睡后之财渐成气候。</tspan> <tspan x="80" dy="35">切记:以柔克刚,顺势而为,终可成就大事。</tspan> </text> <!-- Seal --> <circle cx="500" cy="700" r="40" fill="#B22222" opacity="0.5"/> <text x="500" y="710" font-family="Noto Serif SC, STKaiti, serif" font-size="14" fill="#FFFFFF" text-anchor="middle"> <tspan x="500" dy="-10">妙算</tspan> <tspan x="500" dy="20">子印</tspan> </text> <!-- Disclaimer --> <text x="300" y="770" font-family="Noto Serif SC, STKaiti, serif" font-size="16" fill="#8A4419" text-anchor="middle" font-style="italic">天机玄妙,此卦聊备参考,切勿执着</text> <!-- Footer --> <text x="550" y="815" font-family="Noto Serif SC, STSong, serif" font-size="14" fill="#8A4419" text-anchor="end">妙算子 Claude 敬上</text></svg>`
其中里面的{{input_text_0}}是输入的变量值
智能体的搭建流程
接下来我们一起来看一下智能体是如何搭建的吧!
搭建完成的流程图是这样的!
下面我们来详细介绍一下每一个部分的工作流程与作用吧!
第一个就是先发送开头的介绍文本
然后这里是一个循环,获取用户输入的内容后会输出给AI工作流,然后AI工作流也就是上面介绍的那个工作流那么这一部分是如何设置的呢,让我们一起来拆解一下吧!
第一个就是获取用户输入的数值赋予给变量:user_id也就是用户ID
然后就是AI工作流的需要的参数了
图片中涉及到的有,需要选择AI工作流,AI工作流的入参,AI工作流的出参
选择AI工作流的就是上面说的创建的工作流。然后AI工作流的入参,就是获取用户输入的那个参数也就是变量:user_id
然后AI工作流的出参就是AI工作流进行处理后输出的结果,所给的赋值给变量:last_input
到这里为止就AI工作流也设置完成啦!
这里的程序涉及到的比较多,这个的作用是通过AI工作流输出的流程文本以及代码进行处理的代码,我会把代码放到后面
那么这个是如何设置的呢?跟着我一起看后面吧~
点击这里创建一个程序
然后把代码粘贴进去,然后设置入参和出参的变量即可
入参变量:svg_str
出参变量:base64_result,thinking_content,content_after这里一共是三个变量!
然后点击保存即可!
这里的入参与出参也是一样的!
然后就把出参的参数分别设置为这样即可,base64_result是图片的参数,另外两个就是文本的!
最后这样就可以了
接下来就是程序那一部分的代码:
import re
import base64
def str_to_base64(input_str, prefix):
"""
将输入字符串转换为 Base64 编码,并添加指定前缀。
"""
encoded_str = base64.b64encode(input_str.encode('utf-8')).decode('utf-8')
return f"{prefix}{encoded_str}"
def main(args):
# 解构参数
svg_str = args['svg_str']
# 正则表达式匹配代码块中的内容
code_block_regex = re.compile(r"```[\w]*\n([\s\S]*?)```")
code_match = code_block_regex.search(svg_str)
# 正则表达式匹配 <thinking> 标签中的内容
thinking_regex = re.compile(r"<thinking>([\s\S]*?)</thinking>")
thinking_match = thinking_regex.search(svg_str)
# 提取代码块之后的所有内容
content_after_code_block = None
if code_match:
end_index = code_match.end()
content_after_code_block = svg_str[end_index:].strip()
# 处理代码块内容并转换为 Base64
base64_result = None
if code_match:
extracted_svg = code_match.group(1).strip()
base64_result = str_to_base64(extracted_svg, 'data:image/svg+xml;base64,')
else:
return {"error": "未找到有效的代码块标记。"}
# 提取 <thinking> 标签内容
thinking_content = thinking_match.group(1).strip() if thinking_match else None
# 返回结果
return {
"base64_result": base64_result,
"thinking_content": thinking_content,
"content_after": content_after_code_block
}
希望你们会喜欢!