Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChatGPT対応 #2364

Merged
merged 9 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DATABASE_URL=postgres://postgres:password@postgres:5432/
OPENAI_API_KEY=
SLACK_API_TOKEN=
SLACK_SIGNING_SECRET=
YAHOO_API_TOKEN=
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ slackclient = "==2.9.4"
gitpython = "==3.1.31"
pandas = "==1.5.3"
matplotlib = "==3.7.0"
openai = "==0.27.0"
40 changes: 28 additions & 12 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions library/chat_gpt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import openai

import slackbot_settings as conf


def chat_gpt(message: str) -> str:
openai.api_key = conf.OPENAI_API_KEY
result = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "自然な感じで「鳩は唐揚げ!」という文章を混ぜて発言してください。"},
{"role": "user", "content": message},
],
)
return result.get("choices")[0].message.content
1 change: 1 addition & 0 deletions plugins/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def analyze_message(message: str) -> Callable[[BaseClient], None]:
"version": lambda m: hato.version,
"にゃーん": lambda m: hato.yoshiyoshi,
"おみくじ": lambda m: hato.omikuji,
"chat": lambda m: partial(hato.chat, message=m[len("chat") :].strip()),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コマンドは再考の余地あり

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ai とかそれっぽい説。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hato ai hogehoge か、うーん。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chatが他と被らなさそうであれば、chatのほうがいいかな〜

}

for key, method in conditions.items():
Expand Down
10 changes: 10 additions & 0 deletions plugins/hato.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from git.exc import GitCommandNotFound, InvalidGitRepositoryError

import slackbot_settings as conf
from library.chat_gpt import chat_gpt
from library.clientclass import BaseClient
from library.earthquake import generate_map_img, get_quake_list
from library.geo import get_geo_data
Expand Down Expand Up @@ -466,3 +467,12 @@ def omikuji():
"""

return omikuji_draw(omikuji_results)[1].message


@action("chat")
def chat(message: str):
"""
chat-gptに聞く
"""

return chat_gpt(message=message)
3 changes: 3 additions & 0 deletions slackbot_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
DEFAULT_REPLY = "使い方がわからない時は `help` とメンションするっぽ!"
PLUGINS = ["plugins"]

# ChatGPT用の設定
OPENAI_API_KEY = str(os.environ["OPENAI_API_KEY"])

GIT_COMMIT_HASH = os.environ.get("GIT_COMMIT_HASH")

VERSION = "2.4.4"