ChatGPT: Update README, $botnick prompt replace

This commit is contained in:
Gordon Shumway 2023-05-18 01:10:53 -04:00 committed by GitHub
parent 585ef8f2de
commit 66d60de97c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 3 deletions

View File

@ -6,4 +6,14 @@ Get an API key from https://platform.openai.com/account/api-keys (free)
@config plugins.chatgpt.api_key YOUR_KEY_HERE
@config plugins.chatgpt.prompt "You are $botnick the IRC bot. Be brief, helpful"
^^ Configurable per channel, etc. get creative
@chat <text>
^^ Command to send text to the chatgpt API
@messageparser add "(?i)(.*BOT_NICK_HERE.*)" "chat $1"
^^ replace BOT_NICK_HERE with your bot nick and add automatic replies to nick mentions

View File

@ -68,7 +68,7 @@ conf.registerChannelValue(
ChatGPT,
"prompt",
registry.String(
"You are a helpful IRC bot that responds in 400 characters or less",
"You are $botnick the IRC bot. Be brief, helpful",
_(
"""
The prompt defining your bot's personality.
@ -77,6 +77,19 @@ conf.registerChannelValue(
),
)
conf.registerChannelValue(
ChatGPT,
"model",
registry.String(
"gpt-3.5-turbo",
_(
"""
OpenAI endpoint model, default: "gpt-3.5-turbo"
"""
),
),
)
conf.registerChannelValue(
ChatGPT,
"reply_intact",

View File

@ -45,9 +45,9 @@ class ChatGPT(callbacks.Plugin):
def chat(self, irc, msg, args, text):
"""Manual Call to the ChatGPT API"""
openai.api_key = self.registryValue("api_key")
prompt = self.registryValue("prompt", msg.channel)
prompt = self.registryValue("prompt", msg.channel).replace("$botnick", irc.nick)
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
model=self.registryValue("model", msg.channel),
messages=[
{"role": "system", "content": prompt},
{"role": "user", "content": text},