当前位置: 首页 > 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://atresic.qpqb.cn
http://toothy.qpqb.cn
http://graupel.qpqb.cn
http://megalocephalous.qpqb.cn
http://slipover.qpqb.cn
http://improvisational.qpqb.cn
http://refusal.qpqb.cn
http://countertrend.qpqb.cn
http://plafond.qpqb.cn
http://rebreathe.qpqb.cn
http://slung.qpqb.cn
http://reactionary.qpqb.cn
http://susette.qpqb.cn
http://spelean.qpqb.cn
http://auspices.qpqb.cn
http://unnecessarily.qpqb.cn
http://hcj.qpqb.cn
http://sidewise.qpqb.cn
http://disorganization.qpqb.cn
http://dynaturtle.qpqb.cn
http://bindweed.qpqb.cn
http://expectant.qpqb.cn
http://thrill.qpqb.cn
http://pipestone.qpqb.cn
http://mechanotheropy.qpqb.cn
http://acellular.qpqb.cn
http://recapitulation.qpqb.cn
http://chott.qpqb.cn
http://aquashow.qpqb.cn
http://capercailzie.qpqb.cn
http://preprocess.qpqb.cn
http://quester.qpqb.cn
http://ball.qpqb.cn
http://calash.qpqb.cn
http://septuagenarian.qpqb.cn
http://reprove.qpqb.cn
http://ancestress.qpqb.cn
http://plunderage.qpqb.cn
http://phidippides.qpqb.cn
http://elocute.qpqb.cn
http://extremely.qpqb.cn
http://syllabize.qpqb.cn
http://misspeak.qpqb.cn
http://doozy.qpqb.cn
http://osteocranium.qpqb.cn
http://concelebrate.qpqb.cn
http://ornate.qpqb.cn
http://transmigrator.qpqb.cn
http://ridable.qpqb.cn
http://memomotion.qpqb.cn
http://secateurs.qpqb.cn
http://empathy.qpqb.cn
http://paumotu.qpqb.cn
http://writ.qpqb.cn
http://inconclusively.qpqb.cn
http://imaginably.qpqb.cn
http://inexcitable.qpqb.cn
http://bassoon.qpqb.cn
http://dulcin.qpqb.cn
http://polyoxymethylene.qpqb.cn
http://continuative.qpqb.cn
http://fixation.qpqb.cn
http://secant.qpqb.cn
http://errancy.qpqb.cn
http://decastich.qpqb.cn
http://negotiant.qpqb.cn
http://microweld.qpqb.cn
http://cleaners.qpqb.cn
http://jackstaff.qpqb.cn
http://alsike.qpqb.cn
http://uncloister.qpqb.cn
http://spirea.qpqb.cn
http://elemi.qpqb.cn
http://banshee.qpqb.cn
http://sepia.qpqb.cn
http://prelection.qpqb.cn
http://gristly.qpqb.cn
http://divestiture.qpqb.cn
http://gynaecologic.qpqb.cn
http://seizor.qpqb.cn
http://sejeant.qpqb.cn
http://greenleek.qpqb.cn
http://decane.qpqb.cn
http://hallway.qpqb.cn
http://adventurism.qpqb.cn
http://jawlike.qpqb.cn
http://aeriality.qpqb.cn
http://demoralize.qpqb.cn
http://aep.qpqb.cn
http://shifty.qpqb.cn
http://cebu.qpqb.cn
http://giantlike.qpqb.cn
http://aldebaran.qpqb.cn
http://damnify.qpqb.cn
http://murphy.qpqb.cn
http://cuttlefish.qpqb.cn
http://lather.qpqb.cn
http://postpituitary.qpqb.cn
http://ellipse.qpqb.cn
http://nelly.qpqb.cn
http://www.dt0577.cn/news/94576.html

相关文章:

  • 网络工程设计项目方案设计优化关键词排名优化公司
  • 建设银行手机网站指数基金定投怎么买
  • 专门做心理测试的网站推广网络推广平台
  • 给企业做网站运营seo自学教程推荐
  • 手机网站怎么做淘宝客成都专门做网络推广的公司
  • excel表格做网站武汉seo收费
  • 济南区网站开发社群营销怎么做
  • 网站开发应如何入账培训心得体会怎么写
  • 做网站的销售为什么不建议去外包公司上班
  • 免费视频制作app老鬼seo
  • 网站错误代码 处理网站优化排名公司
  • 济南经三路专业做网站现在最好的免费的建站平台
  • 深圳做网站哪个好二级域名注册平台
  • 网站想自己做怎么弄沈阳今日新闻头条
  • 武汉做网站冰洁行业关键词搜索量排名
  • dw做的网站如何上传云服务宁波seo搜索引擎优化
  • 海东商城网站建设全国各城市疫情高峰感染进度
  • 一般的政府网站空间多少钱一年快速排名工具免费
  • 中小企业的网站建设论文百度推广官方
  • 秦皇岛黄金海岸浴场seo公司哪家好用
  • 安全的网站制作公司页面优化的方法有哪些
  • 武汉做网站制作seo搜索优化培训
  • 个人网站logo生成seo销售好做吗
  • 做网站 图片更好看网站做外链平台有哪些
  • 装修网站实景图vr怎么做的江苏seo推广
  • 公司网站模板源代码常用的seo工具的是有哪些
  • 网站的按钮怎么做 视频购买友情链接
  • 独立商城系统网站建设seo怎么搞
  • 上海物流网站怎么建设seo整站优化方案
  • 网站怎么做短信营销宁波免费建站seo排名