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

docs: add sponsorship #66

Merged
merged 10 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: add use_azure_chatgpt config
  • Loading branch information
iuiaoin committed Jul 19, 2023
commit c4dfe79d9a66a82a67949c410ee228d20e42fb76
18 changes: 18 additions & 0 deletions bot/bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from common.context import Context
from config import conf
from common.singleton import singleton
from common.reply import Reply


@singleton
class Bot:
def reply(self, context: Context) -> Reply:
use_azure_chatgpt = conf().get("use_azure_chatgpt", False)
if use_azure_chatgpt:
from bot.azure_chatgpt import AzureChatGPTBot

return AzureChatGPTBot().reply(context)
else:
from bot.chatgpt import ChatGPTBot

return ChatGPTBot().reply(context)
4 changes: 2 additions & 2 deletions bot/chatgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self):
"temperature": conf().get("temperature"),
}

def reply(self, context: Context):
def reply(self, context: Context) -> Reply:
query = context.query
logger.info(f"[ChatGPT] Query={query}")
if context.type == ContextType.CREATE_IMAGE:
Expand All @@ -38,7 +38,7 @@ def reply(self, context: Context):
)
return Reply(ReplyType.TEXT, response["content"])

def reply_img(self, query):
def reply_img(self, query) -> Reply:
create_image_size = conf().get("create_image_size", "256x256")
try:
response = openai.Image.create(prompt=query, n=1, size=create_image_size)
Expand Down
4 changes: 2 additions & 2 deletions channel/wechat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from utils.log import logger
from utils import const
import os
from bot.chatgpt import ChatGPTBot
from bot.bot import Bot
from common.singleton import singleton
from config import conf
from utils.check import check_prefix, is_wx_account
Expand Down Expand Up @@ -144,7 +144,7 @@ def handle_reply(self, msg: Message, context: Context):
if e1.is_bypass:
return self.send(e1.reply, e1.message)

reply = ChatGPTBot().reply(e1.context)
reply = Bot().reply(e1.context)

e2 = PluginManager().emit(
Event(
Expand Down
1 change: 1 addition & 0 deletions config.template.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"openai_api_key": "YOUR API SECRET KEY",
"model": "gpt-3.5-turbo",
"use_azure_chatgpt": false,
"azure_deployment_id": "",
"role_desc": "You are a helpful assistant.",
"session_expired_duration": 3600,
Expand Down