Skip to content

Commit

Permalink
feat: add 本周星座運勢(限繁中指令), add group chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Lin-jun-xiang committed Nov 2, 2023
1 parent 83fa86e commit a22dafa
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 353 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/translate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
with:
token: ${{ secrets.Action_Bot }} # Based on step2 name
g4f_provider: g4f.Provider.DeepAi # You can change this provider
langs: "en,zh-TW,zh-CN,French,Arabic" # You can define any langs
langs: "en,zh-TW" # You can define any langs
106 changes: 0 additions & 106 deletions README.Arabic.md

This file was deleted.

106 changes: 0 additions & 106 deletions README.French.md

This file was deleted.

106 changes: 0 additions & 106 deletions README.zh-CN.md

This file was deleted.

13 changes: 13 additions & 0 deletions README.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@

恭喜您完成了自己的第一個 LINE Bot! 試著跟它說話看看吧,它會回覆你喔!


### 特殊指令

| 指令 | 說明 |
| --- | ----- |
| `@chat` | 在輸入框輸入 `@chat` + 訊息,就可以在 line 群組中呼叫 chatgpt |
| `@chat 星座運勢 <星座名稱>` | 在輸入框輸入 `@chat 星座運勢 天蠍座`,就可以獲得本周天蠍座(任意星座皆可)運勢,該功能僅限用繁體中文 |


![](img/2023-11-02-10-00-32.png)


### 進階 - 個性化 Bot

另外,我們可以透過 `prompt` 的方式,來讓 Line Bot 回答個性化,在 `./chatgpt_linebot/prompts/template.py` 中我們可以定義 `template`,例如:
Expand All @@ -97,6 +109,7 @@

**Bot回答**: 寶貝,早上起床了嗎?我已經在床上等著你了,想著你的身體就覺得好餓呀。今天早餐該吃什麼呢?是不是要來點辣辣的煎蛋捲,像你那迷人的身材一樣火辣呢?😏🍳


---

## 參考
Expand Down
2 changes: 2 additions & 0 deletions chatgpt_linebot/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from chatgpt_linebot.modules.gpt import chat_completion
from chatgpt_linebot.modules.horoscope import Horoscope
22 changes: 22 additions & 0 deletions chatgpt_linebot/modules/gpt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import g4f
from chatgpt_linebot.memory import Memory


def chat_completion(id: int, memory: Memory) -> str:
"""Use OpenAI API via gpt4free providers"""
try:
response = g4f.ChatCompletion.create(
model=g4f.models.default,
messages=memory.get(id),
)
memory.append(id, 'system', response)
print(response)

except Exception as e:
response = (
"There're something wrong in openai api, please try again.😱\n"
"Or connect to developer: https://github.com/Lin-jun-xiang/chatgpt-line-bot/issues"
)
print(e)

return response
Loading

0 comments on commit a22dafa

Please sign in to comment.