move api key to config.ini
This commit is contained in:
parent
cf62a82474
commit
6101c260bf
1
.gitignore
vendored
1
.gitignore
vendored
@ -158,3 +158,4 @@ cython_debug/
|
|||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
config.ini
|
||||||
|
|||||||
11
plugin.py
11
plugin.py
@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
|
import configparser
|
||||||
|
import os
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
@ -51,6 +53,12 @@ class Chat(callbacks.Plugin):
|
|||||||
self.__parent = super(Chat, self)
|
self.__parent = super(Chat, self)
|
||||||
self.__parent.__init__(irc)
|
self.__parent.__init__(irc)
|
||||||
|
|
||||||
|
# Load the API key from the configuration file
|
||||||
|
config_path = os.path.join(os.path.dirname(__file__), 'config.ini')
|
||||||
|
self.config = configparser.ConfigParser()
|
||||||
|
self.config.read(config_path)
|
||||||
|
self.api_key = self.config.get('Chat', 'api_key')
|
||||||
|
|
||||||
def conversation_history(self):
|
def conversation_history(self):
|
||||||
history = irclib.IrcState.history[-30:]
|
history = irclib.IrcState.history[-30:]
|
||||||
filtered_messages = [(msg.args[0], msg.args[1]) for msg in history if msg.command == 'PRIVMSG']
|
filtered_messages = [(msg.args[0], msg.args[1]) for msg in history if msg.command == 'PRIVMSG']
|
||||||
@ -73,7 +81,6 @@ class Chat(callbacks.Plugin):
|
|||||||
str: ChatGPT's response
|
str: ChatGPT's response
|
||||||
"""
|
"""
|
||||||
|
|
||||||
api_key = "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"
|
|
||||||
model = "gpt-3.5-turbo"
|
model = "gpt-3.5-turbo"
|
||||||
|
|
||||||
system_prompt = "I am an IRC bot named magicvoice, in an IRC channel called ##huffaz. Everyone knows I am an AI and what my limitations are. The following is the last 30 messages exchanged in the channel among users, including myself."
|
system_prompt = "I am an IRC bot named magicvoice, in an IRC channel called ##huffaz. Everyone knows I am an AI and what my limitations are. The following is the last 30 messages exchanged in the channel among users, including myself."
|
||||||
@ -87,7 +94,7 @@ class Chat(callbacks.Plugin):
|
|||||||
res = requests.post(f"https://api.openai.com/v1/chat/completions", headers = {
|
res = requests.post(f"https://api.openai.com/v1/chat/completions", headers = {
|
||||||
# res = requests.post(f"http://localhost:8000/capture", headers = {
|
# res = requests.post(f"http://localhost:8000/capture", headers = {
|
||||||
"Content-Type":"application/json",
|
"Content-Type":"application/json",
|
||||||
"Authorization":f"Bearer {api_key}"
|
"Authorization":f"Bearer {self.api_key}"
|
||||||
},
|
},
|
||||||
json={
|
json={
|
||||||
"model": model,
|
"model": model,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user