Conversant 项目使用教程
1. 项目目录结构及介绍
Conversant 项目的目录结构如下:
sandbox-conversant-lib/
├── conversant/
│ ├── __init__.py
│ ├── demo/
│ │ ├── streamlit_example.py
│ ├── personas/
│ │ ├── fortune-teller/
│ │ │ └── config.json
│ │ ├── your-persona-name/
│ │ │ └── config.json
├── docs/
├── static/
├── tests/
├── .gitattributes
├── .gitignore
├── pre-commit-config.yaml
├── CHANGELOG.md
├── CONTRIBUTORS.md
├── LICENSE
├── README.md
├── poetry.lock
├── pyproject.toml
目录结构介绍
- conversant/: 核心代码目录,包含对话代理的实现和相关配置。
- demo/: 包含 Streamlit 演示应用的启动文件
streamlit_example.py
。 - personas/: 包含不同角色的配置文件
config.json
,每个角色一个子目录。
- demo/: 包含 Streamlit 演示应用的启动文件
- docs/: 项目文档目录。
- static/: 静态资源目录。
- tests/: 测试代码目录。
- .gitattributes: Git 属性配置文件。
- .gitignore: Git 忽略文件配置。
- pre-commit-config.yaml: 预提交钩子配置文件。
- CHANGELOG.md: 项目变更日志。
- CONTRIBUTORS.md: 贡献者指南。
- LICENSE: 项目许可证。
- README.md: 项目介绍和使用说明。
- poetry.lock: Poetry 依赖锁定文件。
- pyproject.toml: Poetry 项目配置文件。
2. 项目启动文件介绍
Streamlit 演示应用启动文件
文件路径:conversant/demo/streamlit_example.py
该文件是 Streamlit 演示应用的启动文件,用于启动一个基于 Conversant 的对话代理演示应用。用户可以通过该应用与不同的角色进行对话。
启动步骤
-
安装 Streamlit:
pip install streamlit
-
设置 Cohere API 密钥:
export COHERE_API_KEY="YOUR_API_KEY_HERE"
-
启动 Streamlit 应用:
streamlit run conversant/demo/streamlit_example.py
3. 项目配置文件介绍
角色配置文件
文件路径:conversant/personas/your-persona-name/config.json
每个角色的配置文件包含以下内容:
{
"chatbot_config": {
"max_context_examples": 5,
"avatar": "🤖"
},
"client_config": {
"model": "large",
"max_tokens": 50,
"temperature": 0.7
},
"chat_prompt_config": {
"preamble": "Description of the persona",
"example_separator": "<CONVERSATION>\n",
"headers": {
"user": "User",
"bot": "Bot"
},
"examples": [
{
"user": "Who are you?",
"bot": "I am a chatbot."
}
]
}
}
配置文件说明
- chatbot_config: 对话代理的配置,包括上下文示例的最大长度和角色的头像。
- client_config: Cohere API 的配置,包括模型类型、最大生成令牌数和温度。
- chat_prompt_config: 对话提示的配置,包括角色的描述、示例分隔符、用户和机器人的名称以及示例对话。
通过编辑这些配置文件,用户可以自定义不同的对话角色和行为。