1 Star 0 Fork 0

贺辉0912/bigmodel

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gradio04_chatglm6b_2.py 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
andy.he 提交于 2024-03-02 17:18 . 1
from langchain_community.llms import HuggingFacePipeline
from langchain.prompts import PromptTemplate
from langchain_core.prompts import ChatPromptTemplate
import gradio as gr
from langchain_core.prompts import ChatPromptTemplate
from langchain.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_community.llms import HuggingFacePipeline
from langchain_core.prompts.chat import AIMessagePromptTemplate
from langchain.prompts import HumanMessagePromptTemplate
hf = HuggingFacePipeline.from_model_id(
model_id="THUDM/chatglm3-6b",
task="text-generation",
verbose=True,
device=0,
model_kwargs={"trust_remote_code":True},
pipeline_kwargs={"max_new_tokens": 5000},
)
# from ChatGLM_new import zhipu_llm
# hf = zhipu_llm
prompt = ChatPromptTemplate.from_messages([
HumanMessagePromptTemplate.from_template("深圳的天气怎么样"),
AIMessagePromptTemplate.from_template("深圳今天的天气非常好"),
HumanMessagePromptTemplate.from_template("最近有什么好看的电影"),
AIMessagePromptTemplate.from_template("非诚勿扰不错"),
HumanMessagePromptTemplate.from_template("{user_input}"),
])
chain = prompt | hf
def greet2(name):
response = chain.invoke({"user_input": name})
return response
def alternatingly_agree(message, history):
return greet2(message)
gr.ChatInterface(alternatingly_agree).launch()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/he-hui-0912/bigmodel.git
git@gitee.com:he-hui-0912/bigmodel.git
he-hui-0912
bigmodel
bigmodel
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385