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

网站建设的公司系统规划最近三天的新闻热点

网站建设的公司系统规划,最近三天的新闻热点,单位做网站,现在建设公司网站用什么软件上一节实现了 LangChain 实现给动物取名字, 实际上每次给不同的动物取名字,还得修改源代码,这周就用模块化template来实现。 1. 添加promptTemplate from langchain.llms import OpenAI # 导入Langchain库中的OpenAI模块 from langchain.p…

上一节实现了 LangChain 实现给动物取名字,
实际上每次给不同的动物取名字,还得修改源代码,这周就用模块化template来实现。

1. 添加promptTemplate

from langchain.llms import OpenAI  # 导入Langchain库中的OpenAI模块
from langchain.prompts import PromptTemplate  # 导入Langchain库中的PromptTemplate模块
from langchain.chains import LLMChain  # 导入Langchain库中的LLMChain模块
from dotenv import load_dotenv  # 导入dotenv库,用于加载环境变量load_dotenv()  # 加载.env文件中的环境变量def generate_pet_name(animal_type):llm = OpenAI(temperature=0.7)  # 创建OpenAI模型的实例,设置temperature参数为0.7以调整生成的多样性# 创建PromptTemplate实例,用于构造输入提示prompt_template_name = PromptTemplate(input_variables=['animal_type'],template="I have a {animal_type} pet and I want a cool name for it. Suggest me five cool names for my pet.")name_chain = LLMChain(llm=llm, prompt=prompt_template_name)  # 创建LLMChain实例,将OpenAI模型和PromptTemplate传入response = name_chain({'animal_type': animal_type})  # 使用LLMChain生成宠物名字return response  # 返回生成的名字# 当该脚本作为主程序运行时,执行以下代码
if __name__ == "__main__":print(generate_pet_name('cat'))  # 调用generate_pet_name函数,并打印返回的结果

运行和输出

$ python main.py
{'animal_type': 'cat', 'text': '\n\n1. Shadow \n2. Midnight \n3. Storm \n4. Luna \n5. Tiger'}
(.venv) zgpeace on zgpeaces-MBP in ~/Workspace/LLM/langchain-llm-app(1m|feature/prompt)
$ python main.py
{'animal_type': 'cow', 'text': '\n\n1. Milky\n2. Mooly\n3. Bessie\n4. Daisy\n5. Buttercup'}
(.venv) zgpeace on zgpeaces-MBP in ~/Workspace/LLM/langchain-llm-app(4m|feature/prompt*)

在这里插入图片描述

2. 添加新的参数pte_color

from langchain.llms import OpenAI  # 导入Langchain库中的OpenAI模块
from langchain.prompts import PromptTemplate  # 导入Langchain库中的PromptTemplate模块
from langchain.chains import LLMChain  # 导入Langchain库中的LLMChain模块
from dotenv import load_dotenv  # 导入dotenv库,用于加载环境变量load_dotenv()  # 加载.env文件中的环境变量def generate_pet_name(animal_type, pet_color):llm = OpenAI(temperature=0.7)  # 创建OpenAI模型的实例,设置temperature参数为0.7以调整生成的多样性# 创建PromptTemplate实例,用于构造输入提示prompt_template_name = PromptTemplate(input_variables=['animal_type', 'pet_color'],template="I have a {animal_type} pet and I want a cool name for it. Suggest me five cool names for my pet.")name_chain = LLMChain(llm=llm, prompt=prompt_template_name)  # 创建LLMChain实例,将OpenAI模型和PromptTemplate传入response = name_chain({'animal_type': animal_type, 'pet_color': pet_color})  # 使用LLMChain生成宠物名字return response  # 返回生成的名字# 当该脚本作为主程序运行时,执行以下代码
if __name__ == "__main__":print(generate_pet_name('cow', 'black'))  # 调用generate_pet_name函数,并打印返回的结果

运行结果

$ python main.py
{'animal_type': 'cow', 'pet_color': 'black', 'text': '\n\n1. Daisy\n2. Maverick\n3. Barnaby\n4. Bessie\n5. Bossy'}
(.venv) zgpeace on zgpeaces-MBP in ~/Workspace/LLM/langchain-llm-app(6m|feature/prompt*)

3. 重构代码

把逻辑放到langchain_helper.py, 清空main.py代码

4. 用Streamlit 生成网页

main.py 代码实现

import langchain_helper as lch
import streamlit as stst.title("Pets name generator")

add path environment in .zshrc

export PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin:$PATH"source .zshrc
zgpeaces-MBP at ~/Workspace/LLM/langchain-llm-app ±(feature/prompt) ✗ ❯ streamlit run main.py       👋 Welcome to Streamlit!If you’d like to receive helpful onboarding emails, news, offers, promotions,and the occasional swag, please enter your email address below. Otherwise,leave this field blank.Email:  You can find our privacy policy at https://streamlit.io/privacy-policySummary:- This open source library collects usage statistics.- We cannot see and do not store information contained inside Streamlit apps,such as text, charts, images, etc.- Telemetry data is stored in servers in the United States.- If you'd like to opt out, add the following to ~/.streamlit/config.toml,creating that file if necessary:[browser]gatherUsageStats = falseYou can now view your Streamlit app in your browser.Local URL: http://localhost:8501Network URL: http://192.168.50.10:8501For better performance, install the Watchdog module:$ xcode-select --install$ pip install watchdog

http://localhost:8501/
在这里插入图片描述

5. Streamlit 生成网页输入跟Langchain互动获取名字

main.py

import langchain_helper as lch  # 导入名为langchain_helper的模块,并使用别名lch
import streamlit as st  # 导入Streamlit库,并使用别名stst.title("Pets name generator")  # 在Streamlit应用中设置标题# 通过侧边栏选择宠物类型
animal_type = st.sidebar.selectbox("Select animal type", ["dog", "cat", "cow", "horse", "pig", "sheep"])# 根据宠物类型设置宠物颜色,使用侧边栏的文本区域输入
if animal_type in ['dog', 'cat', 'cow', 'horse', 'pig', 'sheep']:pet_color = st.sidebar.text_area(label=f"What color is your {animal_type}?", max_chars=15)
else:pet_color = st.sidebar.text_area(label="What color is your pet?", max_chars=15)# 如果有输入颜色,调用generate_pet_name函数生成宠物名字并显示
if pet_color:response = lch.generate_pet_name(animal_type, pet_color)st.text(response['pet_name'])

langchain_hepler.py 实现

from langchain.llms import OpenAI  # 导入Langchain库中的OpenAI模块
from langchain.prompts import PromptTemplate  # 导入Langchain库中的PromptTemplate模块
from langchain.chains import LLMChain  # 导入Langchain库中的LLMChain模块
from dotenv import load_dotenv  # 导入dotenv库,用于加载环境变量load_dotenv()  # 加载.env文件中的环境变量def generate_pet_name(animal_type, pet_color):llm = OpenAI(temperature=0.7)  # 创建OpenAI模型的实例,设置temperature参数为0.7以调整生成的多样性# 创建PromptTemplate实例,用于构造输入提示prompt_template_name = PromptTemplate(input_variables=['animal_type', 'pet_color'],template="I have a {animal_type} pet and I want a cool name for it. Suggest me five cool names for my pet.")name_chain = LLMChain(llm=llm, prompt=prompt_template_name, output_key='pet_name')  # 创建LLMChain实例,将OpenAI模型和PromptTemplate传入response = name_chain({'animal_type': animal_type, 'pet_color': pet_color})  # 使用LLMChain生成宠物名字return response  # 返回生成的名字# 当该脚本作为主程序运行时,执行以下代码
if __name__ == "__main__":print(generate_pet_name('cow', 'black'))  # 调用generate_pet_name函数,并打印返回的结果

在这里插入图片描述

参考

  • https://github.com/zgpeace/pets-name-langchain/tree/feature/prompt
  • https://youtu.be/lG7Uxts9SXs?si=H1CISGkoYiKRSF5V
  • Streamlit - https://streamlit.io
http://www.yayakq.cn/news/594412/

相关文章:

  • 母婴会所网站建设汽车之家网页版官网找车
  • 网站后台关键词链接怎样做洛阳做网站公司汉狮价格
  • 西安网站制作计划优秀网页设计平台
  • 南京外贸网站建设公司网站开发维护的好处
  • 济南网站开发推广google seo实战教程
  • 找图纸的网站计算机网站建设维护的目的
  • 天津做网站得公司网站开发和网络开发区别
  • 做的网站在百度上搜不出来免费的电脑编程软件
  • 学的专业是编课 网站开发英语翻译网站建设系统公司
  • 网站开发工程师ppt网络推广外包搜索手机蛙软件
  • chrome网站开发插件鞍山便民信息平台
  • 如何网站全部结构番禺网站建设gzhchl
  • 网站开发流程说明小红书官方推广
  • 如何进行网站分析温州网站建设方案表
  • 建设网站西安建筑木工模板承包报价单
  • 网站搜索排名优化人力资源公司网站建设方案
  • 合肥大型网站做小程序的公司有哪些比较好?
  • 科技类网站怎么做ppt模板之家
  • 盐城营销网站建设电子商务网站的建设步骤有
  • 做旅行网站黄骅港金沙滩门票价格
  • 个人做企业网站制作要多少钱个人信息管理系统
  • 自己制作网站需要什么广州做网站信息
  • 手机网站 文件上传北京海淀建设工程律师服务
  • 西部数码的vps云主机如何访问网站爱用建站下载
  • 杭州广众建设工程有限公司网站广告优化
  • dw做网站乱码深圳专业建站公司有哪些
  • wordpress当前页面id深圳做网站优化
  • 昆明网站开发公司电话简历模板 个人简历
  • wordpress首页添加站点统计显示网店装修步骤
  • 网站建设 服务内容 费用百度 门户网站