Skip to content

Commit

Permalink
update st demo .
Browse files Browse the repository at this point in the history
  • Loading branch information
shibing624 committed Aug 27, 2024
1 parent ec1b2c0 commit 10d645f
Show file tree
Hide file tree
Showing 15 changed files with 2,488 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Bug Report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

### Describe the bug
Please provide a clear and concise description of what the bug is. If applicable, add screenshots to help explain your problem, especially for visualization related problems.

### To Reproduce
Please provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) here. We hope we can simply copy/paste/run it. It is also nice to share a hosted runnable script (e.g. Google Colab), especially for hardware-related problems.

### Describe your attempts
- [ ] I checked the documentation and found no answer
- [ ] I checked to make sure that this is not a duplicate issue

You should also provide code snippets you tried as a workaround, StackOverflow solution that you have walked through, or your best guess of the cause that you can't locate (e.g. cosmic radiation).

### Context
- **OS** [e.g. Windows 10, macOS 10.14]:
- **Hardware** [e.g. CPU only, GTX 1080 Ti]:


### Additional Information
Other things you want the developers to know.
23 changes: 23 additions & 0 deletions .github/ISSUE_TEMPLATE/feature-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Feature Request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

- [ ] I checked to make sure that this is not a duplicate issue
- [ ] I'm submitting the request to the correct repository (for model requests

### Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

### Describe the solution you'd like
A clear and concise description of what you want to happen.

### Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

### Additional Information
Other things you want the developers to know.
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/usage-question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Usage Question
about: Ask a question about usage
title: ''
labels: question
assignees: ''

---

### Describe the Question
Please provide a clear and concise description of what the question is.

### Describe your attempts
- [ ] I walked through the tutorials
- [ ] I checked the documentation
- [ ] I checked to make sure that this is not a duplicate question

You may also provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) you tried as a workaround, or StackOverflow solution that you have walked through. (e.g. cosmic radiation).
17 changes: 17 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
# Label to use when marking an issue as stale
staleLabel: wontfix
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.(由于长期不活动,机器人自动关闭此问题,如果需要欢迎提问)
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false
53 changes: 53 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
on:
workflow_dispatch: # Manually running a workflow
name: Linux build
jobs:
test-ubuntu:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# python-version: [ 3.7, 3.8, 3.9 ]
python-version: [ 3.9 ]
steps:
- uses: actions/checkout@v2
- name: Cache pip
uses: actions/cache@v2
if: startsWith(runner.os, 'Linux')
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache huggingface models
uses: actions/cache@v2
with:
path: ~/.cache/huggingface
key: ${{ runner.os }}-huggingface-
- name: Cache text2vec models
uses: actions/cache@v2
with:
path: ~/.text2vec
key: ${{ runner.os }}-text2vec-
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install torch
run: |
python -m pip install --upgrade pip
pip install Cython
pip install torch
- name: Install from pypi
run: |
pip install -U agentica
python -c "import agentica; print(agentica.__version__)"
pip uninstall -y agentica
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install .
pip install pytest
- name: PKG-TEST
run: |
python -m pytest
72 changes: 71 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,72 @@
# weibo-roast
基于 agentica 构建了一个微博毒舌AI,疯狂 diss 微博博主
基于 agentica 构建了一个微博毒舌AI,疯狂 diss 微博博主。

微博吐槽(weibo-roast)是一个微博毒舌AI,集成了微博数据抓取、处理、分析和生成幽默毒舌评论的功能,通过weibo-crawler爬取指定用户的近20条原创微博,然后调用 GPT 模型生成对微博博主的"吐槽"。

## 快速开始

![demo](https://github.com/user-attachments/assets/bbcf26bd-2072-429c-9b50-876adfa6d9e8)


```shell
pip install -r requirements.txt
cp .env.example .env
python app.py
```

## 高级用法

- 修改 `prompts.py` 中的提示以自定义 AI 生成的内容
- 修改 `app.py` 中的 `model` , 推荐效果 sonnet > Qwen1.5 72B > deepseek-coder

## Contact

- Issue(建议)
[![GitHub issues](https://img.shields.io/github/issues/shibing624/agentica.svg)](https://github.com/shibing624/agentica/issues)
- 邮件我:xuming: [email protected]
- 微信我: 加我*微信号:xuming624, 备注:姓名-公司-NLP* 进NLP交流群。

<img src="https://github.com/shibing624/weibo-roast/blob/main/docs/wechat.jpeg" width="200" />

<img src="https://github.com/shibing624/weibo-roast/blob/main/docs/wechat_group.jpg" width="200" />


## Citation

如果你在研究中使用了`agentica`,请按如下格式引用:

APA:

```
Xu, M. weibo-roast: Weibo Roast AI (Version 0.0.1) [Computer software]. https://github.com/shibing624/weibo-roast
```

BibTeX:

```
@misc{Xu_weibo-roast,
title={weibo-roast: Weibo Roast AI},
author={Xu Ming},
year={2024},
howpublished={\url{https://github.com/shibing624/weibo-roast}},
}
```

## License

授权协议为 [The Apache License 2.0](/LICENSE),可免费用做商业用途。请在产品说明中附加`weibo-roast`的链接和授权协议。
## Contribute

项目代码还很粗糙,如果大家对代码有所改进,欢迎提交回本项目,在提交之前,注意以下两点:

-`tests`添加相应的单元测试
- 使用`python -m pytest`来运行所有单元测试,确保所有单测都是通过的

之后即可提交PR。

## 致谢

- [weibo-crawler](https://github.com/dataabc/weibo-crawler)
- [WeiboSuperSpider](https://github.com/Python3Spiders/WeiboSuperSpider)
- [agentica](https://github.com/shibing624/agantica)
- [WeiboRoast](https://github.com/Huanshere/WeiboRoast/tree/main)
72 changes: 72 additions & 0 deletions ask_llm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
"""
@author:XuMing([email protected])
@description:
"""

from agentica import Message
from agentica import Assistant, DeepseekLLM
from agentica.tools.file import FileTool
from loguru import logger

assistant = Assistant(
llm=DeepseekLLM(),
tools=[FileTool()],
add_datetime_to_instructions=True,
show_tool_calls=True,
read_chat_history=True,
debug_mode=False,
)
logger.debug(f"assistant loaded, assistant={assistant}")


def llm_response(messages, response_json=False):
if response_json:
llm = DeepseekLLM(response_format={"type": "json_object"})
else:
llm = DeepseekLLM()
if isinstance(messages, str):
messages = [Message(role="user", content=messages)]
elif isinstance(messages, list):
llm_messages = []
# If messages are provided, simply use them
if messages is not None and len(messages) > 0:
for _m in messages:
if isinstance(_m, Message):
llm_messages.append(_m)
elif isinstance(_m, dict):
llm_messages.append(Message.model_validate(_m))
messages = llm_messages
return llm.response_stream(messages)


def assistant_response(prompt):
r = assistant.run(prompt)
print(r, "".join(r))
return r


if __name__ == '__main__':
prompt = "一句话介绍alpaca?"
r = llm_response(prompt)
print(r)
for i in r:
print(i)

prompt = """
按照以下格式,输入待评分的文本,返回敏感度评分结果。
- 响应格式
用JSON格式返回评分结果。
- 示例
```json
{{"sensitive": 1}}
```
### 问题
alpaca是哺乳动物吗?"
"""
print(llm_response(prompt, response_json=True))
prompt = "一句话介绍北京"
r = assistant_response(prompt)
print(r, "".join(r))
Binary file added docs/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/wechat.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/wechat_group.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
LOG_LEVEL=DEBUG

DEEPSEEK_API_KEY=
MOONSHOT_API_KEY=

OPENAI_API_KEY=
OPENAI_BASE_URL=
Loading