2 Star 2 Fork 1

imClumsyPanda/chatchat-lite

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.py 2.21 KB
一键复制 编辑 原始数据 按行查看 历史
imClumsyPanda 提交于 2024-12-04 17:27 . add agent_chat
from typing import Literal
from langchain_openai import ChatOpenAI
from streamlit_flow import streamlit_flow
from streamlit_flow.elements import StreamlitFlowNode, StreamlitFlowEdge
from streamlit_flow.state import StreamlitFlowState
from streamlit_flow.layouts import TreeLayout
PLATFORMS = ["ollama", "xinference", "fastchat", "openai"]
def get_models(platform_type: Literal[tuple(PLATFORMS)]):
if platform_type == "ollama":
import ollama
models = [model["model"] for model in ollama.list()["models"]]
return models
elif platform_type == "xinference":
from xinference_client import Client
client = Client()
models = client.list_models()
return models
def get_chatllm(
platform_type: Literal[tuple(PLATFORMS)],
model: str,
temperature: float = 0.9
):
if platform_type == "ollama":
# from langchain_ollama import ChatOllama
# return ChatOllama
return ChatOpenAI(
temperature=temperature,
model_name=model,
streaming=True,
base_url="http://127.0.0.1:11434/v1",
api_key="EMPTY",
)
elif platform_type == "xinference":
from langchain_community.llms import Xinference
return Xinference
def show_graph(graph):
flow_state = StreamlitFlowState(
nodes=[StreamlitFlowNode(
id=node.id,
pos=(0,0),
data={"content": node.id},
node_type="input" if node.id == "__start__"
else "output" if node.id == "__end__"
else "default",
) for node in graph.nodes.values()],
edges=[StreamlitFlowEdge(
id=str(enum),
source=edge.source,
target=edge.target,
animated=True,
) for enum, edge in enumerate(graph.edges)],
)
streamlit_flow('example_flow',
flow_state,
layout=TreeLayout(direction='down'), fit_view=True
)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/imclumsypanda/chatchat-lite.git
git@gitee.com:imclumsypanda/chatchat-lite.git
imclumsypanda
chatchat-lite
chatchat-lite
master

搜索帮助