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

德语网站制作wordpress模板 图片站

德语网站制作,wordpress模板 图片站,免费服务器申请,网站怎么做seo、背景 楼主决定提升与LLM交互的质量,之前是直接prompt->answer的范式,现在我希望能用上ReAct策略和能够检索StackOverflow,让同一款LLM发挥出更大的作用。 难点 1. 怎样调用StackOverflow step1 pip install stackspi step 2 from la…

背景

楼主决定提升与LLM交互的质量,之前是直接prompt->answer的范式,现在我希望能用上ReAct策略和能够检索StackOverflow,让同一款LLM发挥出更大的作用。

难点

1. 怎样调用StackOverflow

step1 pip install stackspi

step 2

from langchain.agents import load_toolstools = load_tools(["stackexchange"],llm=llm
)

注:stackoverflow是stackexchange的子网站 

2. 交互次数太多token输入超出了llm限制

approach 1 使用ConversationSummaryBufferMemory

这种记忆方式会把之前的对话内容总结一下,限制在设定的token个数内

from langchain.memory import ConversationSummaryBufferMemorymemory = ConversationSummaryBufferMemory(llm = llm, # 这里的llm的作用是总结max_token_limit=4097,memory_key="chat_history"
)

approach 2 设置参数max_iterations

agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools, max_iterations=4, # 限制最大交互次数,防止token超过上限verbose=True
)

3. llm总是回复无法回答

很多教程把温度设置成0,说是为了得到最准确的答案,但是我发现这样设置,agent会变得特别谨慎,直接说它不知道,温度调高以后问题解决了。

测试问题

What parts does a JUnit4 unit test case consist of?

代码

from constants import PROXY_URL,KEYimport warnings
warnings.filterwarnings("ignore")import langchain
langchain.debug = Truefrom langchain.agents import load_tools
from langchain.chat_models import ChatOpenAIfrom langchain.agents import AgentExecutor, ZeroShotAgent
from langchain.chains import LLMChain
from langchain.memory import ConversationSummaryBufferMemoryllm = ChatOpenAI(temperature=0.7, # 如果参数调得很低,会导致LLM特别谨慎,最后不给答案model_name="gpt-3.5-turbo-0613", openai_api_key=KEY,openai_api_base=PROXY_URL
)memory = ConversationSummaryBufferMemory(llm = llm, # 这里的llm的作用是总结max_token_limit=4097,memory_key="chat_history"
)prefix = """You should be a proficient and helpful assistant in java unit testing with JUnit4 framework. You have access to the following tools:"""
suffix = """Begin!"{chat_history}
Question: {input}
{agent_scratchpad}"""tools = load_tools(["stackexchange"],llm=llm
)prompt = ZeroShotAgent.create_prompt(tools,prefix=prefix,suffix=suffix,input_variables=["input", "chat_history", "agent_scratchpad"],
) # 这里集成了ReActllm_chain = LLMChain(llm=llm, prompt=prompt)agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools, max_iterations=4, # 限制最大交互次数,防止token超过上限verbose=True
)agent_chain = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True, memory=memory
)def ask_agent(question):answer = agent_chain.run(input=question)return answerdef main():test_question = "What parts does a JUnit4 unit test case consist of?"test_answer = ask_agent(test_question)return test_answerif __name__ == "__main__":main()

最后输出

[chain/end] [1:chain:AgentExecutor] [75.12s] Exiting Chain run with output:
{
  "output": "A JUnit4 unit test case consists of the following parts:\n1. 
Test class: This is a class that contains the test methods.\n2. Test methods: These are the methods that contain the actual test code. They are annotated with the @Test annotation.\n3. Assertions: These are used to verify 
the expected behavior of the code being tested. JUnit provides various assertion methods for this purpose.\n4. Annotations: JUnit provides several annotations that can be used to configure the test case, such as @Before, @After, @BeforeClass, and @AfterClass.\n\nOverall, a JUnit4 unit test case 
is a class that contains test methods with assertions, and can be configured using annotations."
}

http://www.yayakq.cn/news/309254/

相关文章:

  • 做企业网站的轻量级cms新编asp.net 2.0网站开发从入门到精通 代码
  • 免费的旅游网站模板代理注册公司代理费多少钱
  • wordpress成长记录网站模版1688黄页大全
  • 做rom网站房产网站制作流程
  • 绍兴网站建设方案策划做网站优化的注意事项
  • 建设一个社交网站需要多少钱如何做建材网站的线下推广
  • 如何学建设网站首页故事式软文范例100字
  • 中国优秀网站网站优化标题
  • 网站怎么做竞价推广杭州做搜索引擎网站的公司
  • 博客网站wordpresswordpress调整配置出错了
  • 济南建设工程信息网站企业中标信息查询网
  • 喀什百度做网站多少钱优化学校网站建设方案
  • 扁平化网站特效wplounge wordpress主题
  • 宠物网站建设方案书p2p理财网站开发框架
  • 网站开发过程中遇到的问题wordpress 网站logo
  • 服装公司网站设计手机和pc端网站建设
  • 大学网站的设计方案wordpress mysql配置
  • 湛江网站设计海外购物网站哪个最好
  • 创建网站英语在线制作电子公章免费公章在线生成
  • 网站建设服务器的选择方案有网站支付怎么做的
  • 会展相关app和网站的建设情况网站首页制作浩森宇特
  • 重庆网站外包国防教育网站建设方案
  • 企业网站源码 aspwordpress dokuwiki
  • 给境外合法网站做数据云匠网app
  • 阿里巴巴网站威海哪里做?o2o系统
  • 网站建设流程总结微信h5
  • 网站正建设中免费网站建设排行榜
  • 营销型网站建站推广二手商品网站制作
  • 襄阳旅游景点网站建设崆峒区城乡建设局网站
  • 杭州做营销型网站如何快速优化网站