当前位置: 首页 > news >正文

网站开发语言哪个好网站代做

网站开发语言哪个好,网站代做,南通优普网站建设团队,哪个网站做欧洲旅行比较好要进一步提升智能编码助手的效率,我觉得需要做到两点 1) 进一步让主人聚焦于设计输入以及结果验证的循环 2) 进一步让智能编码助手聚焦于代码实现和程序流程(保存、打开,修订、执行、合并…) 正好接触到LLM…

要进一步提升智能编码助手的效率,我觉得需要做到两点
1) 进一步让主人聚焦于设计输入以及结果验证的循环
2) 进一步让智能编码助手聚焦于代码实现和程序流程(保存、打开,修订、执行、合并…)
正好接触到LLM的LangChain的框架,那么初步体验一把利用其Agent实现代码生成,保存与执行
LangChain的中文官网

参考借鉴链接 :阿里通义千问结合Langchain基于程序运行结果回答问题
链接中有一篇介绍,要求AI计算给定阶数(文中是10阶)斐波那契数列,代码生成和执行已经有了,所以我的诉求,看上去挺简单,增加一个保存有效代码的功能就OK了
初步改造如下,新增存盘的函数和相关调用:

#**新增存盘函数**
def saveFile(replyMessages: str):print('... to save the file ...')python_path="/home/cfets/eclipse-workspace/TestAI/testchain/"now_time = time.strftime('%Y-%m-%d_%H:%M:%S', time.localtime())i = random.randint(1, 100)code_file = python_path + "pyAITest_" + now_time + '_' + str(i) + ".py"# 保存至文件res_content=Falsetry:with open(code_file, 'w') as f:f.write(replyMessages)res_content =Trueexcept Exception as e:print('Error: %s' % e)return res_content@tool
def py_repl_tool(code: str):"""Returns the result of execution."""_, after = code.split("```py")realcode = code.split("```")[0]# **新增保存文件**if saveFile(realcode):print('file is saved ... ')py_repl=PythonREPL()return py_repl.run(realcode)if __name__ == '__main__':os.environ["DASHSCOPE_API_KEY"] = dashscope.api_keytools = [Tool(name = "python repl",func=py_repl_tool.run,description="useful for when you need to use python to answer a question."+"You should input python code in correct format and keep the logic as simple as possible. If you want to see the output of a value, you should print it out with `print(...)`.")]agent = initialize_agent(llm=tongyi.Tongyi(model_name="qwen-max",temperature=0.1), tools=tools,verbose=True,max_iterations=3,
)agent.run("What is the 10th fibonacci number?")#agent.run("How many letters in string: Helllomyyfrienddds?")

但很遗憾,测试的结果是,计算的结果与文章一致,10阶斐波那契数列,但保存的文件是空的
在这里插入图片描述

实际上,原代码中split不靠谱,按源代码realcode是空的,需要修改

@tool
def py_repl_tool(code: str):"""Returns the result of execution."""_, after = code.split("```py")# realcode = code.split("```")[0]   原文档的错误#修订后realcode = after.split("```")[0]#print('realcode:  %s' % realcode)# **新增保存文件**if saveFile(realcode):print('file is saved ... ')py_repl=PythonREPL()return py_repl.run(realcode)

修改后执行就OK
主程序执行结果:
在这里插入图片描述
与保存的程序执行结果一致
在这里插入图片描述
但是计算结果是34 这是9阶的斐波那契数列,而不是55——10阶的斐波那契数列,原链接中的结果
在这里插入图片描述
可以把这段代码cp下来算一下,fibonacci(10)=34 , fibonacci(11)才是55
考虑到原代码realcode实际上为空的问题,我觉得原先的agent是分别生成了代码,但没有执行代码(realcode是空,执行啥?)而是找了答案,但无法确认… 所以AI自动生成代码还是保存后检查执行的,这算是歪打正着吧。

最后一个问题,根据初步了解 agent相关tool生成结果跟description描述有直接关系,如果直接引用原来的描述

description="useful for when you need to use python to answer a question.
You should input python code in correct format and keep the logic as simple as possible.   
If you want to see the output of a value, you should print it out with `print(...)`."

agent生成结果会呈现不稳定,有的时候’‘’ py …‘’’ 有的时候 ‘’’ python …‘’’
那么就会报错,参考原文,整理出一个较为完整的描述(description,相当于需求或者设计描述)
完整代码如下:

import dashscope
import os
from langchain_community.llms import tongyi
from langchain.agents import initialize_agent
from langchain.agents.tools import Tool
from langchain.tools import tool
from langchain.utilities.python import PythonREPL
import re
import time
import randomdashscope.api_key="xxxxxx"  #请自行替换# 新增存盘函数
def saveFile(replyMessages: str):print('... to save the file ...')python_path="/home/cfets/eclipse-workspace/TestAI/testchain/"now_time = time.strftime('%Y-%m-%d_%H:%M:%S', time.localtime())i = random.randint(1, 100)code_file = python_path + "pyAITest_" + now_time + '_' + str(i) + ".py"# 保存至文件res_content=Falsetry:with open(code_file, 'w') as f:f.write(replyMessages)res_content =Trueexcept Exception as e:print('Error: %s' % e)return res_content@tool
def py_repl_tool(code: str):"""Returns the result of execution."""_, after = code.split("```python")  realcode = after.split("```")[0]   #修改了原代码错误py_repl=PythonREPL()#print('realcode:  %s' % realcode)# 新增保存文件if saveFile(realcode):print('file is saved ... ')return py_repl.run(realcode)if __name__ == '__main__':os.environ["DASHSCOPE_API_KEY"] = dashscope.api_keytools = [Tool(name = "python repl",func=py_repl_tool.run,description=""""useful for when you need to use python to answer a question. You should input python code in correct format and keep the logic as simple as possible. you should end the program with `print(...)` to print the output and return only python code in Markdown format, e.g.:```python....```""")     #修改了描述,指定了Markdown format]agent = initialize_agent(llm=tongyi.Tongyi(model_name="qwen-max",temperature=0.1), tools=tools,verbose=True,max_iterations=3,
)agent.run("What is the 10th fibonacci number?")

后续考虑几方面的进一步改进
对单一功能实现单元化设计,把多个功能集成串起来,包括前后台设计,形成较为复杂的程序, 再进一步开发本地的知识库/代码库, 同时再利用现有架构测试其他大模型。

最后,希望大家能不能帮我解决一个问题,就是在执行代码为空的时候 55到底是怎么得出来的,先行拜谢

http://www.15wanjia.com/news/178535.html

相关文章:

  • 学网站建设需要什么工具贺州做网站
  • 网站的标志可以修改吗wordpress网站做成app6
  • 庆阳网站建设推广退休领了100万企业年金
  • 大牌网站设计百度公司招聘官网最新招聘
  • 网页设计课程报告总结seo排名的职位
  • 网站开发建设明细报价表重庆平台网站建设价格
  • 廊坊网络公司网站网络推广方案
  • 如何做博客网站上海seo优化服务公司
  • 网站的建立与运营微信网站响应式网站
  • 对网站进行seo优化乐之网站制作
  • 简单的网站建设wordpress下载远程图片
  • 建安证查询网站什么叫网站策划书
  • 网页制作三剑客不包括seo兼职
  • 中国网站有哪些wordpress取消page
  • 专业定制网站建设公司合肥专业做网站公司哪家好
  • wordpress适用linuxwordpress加载优化
  • 北京网站建设培训机构福建建设工程交易中心网站
  • 网络直播网站建设如何搜索公司所有的网站
  • 鱼台建设局网站用什么软件制作图片
  • 山东省山东省建设厅网站广东省自然资源厅三定方案
  • 网站怎么进网站页脚内容
  • 大型网站建设开发建立个人博客网站wordpress
  • 哪个行业最容易做网站厦门网页
  • 网站制作的基本在线制作动态图片自动生成
  • wordpress 字符串函数大全自己给网站做优化怎么做
  • 郑州做装饰的网站php多平台商城网站系统建设
  • 物流网站首页图片电子科技网站
  • 网站建设人力成本费用wordpress要发表评论您必须先登录
  • 资讯网站开发的背景wordpress评论不要地址邮箱
  • 企业网站推广方法有哪些?精品课程网站建设开题报告