Added basic ChatGPT as a skill
All checks were successful
git.cronocide.net/bluebubbles-bot/pipeline/head This commit looks good

This commit is contained in:
Daniel Dayley 2023-04-17 22:46:50 -06:00
parent de3b39f3ca
commit 74dae2c133
4 changed files with 27 additions and 8 deletions

View File

@ -41,6 +41,18 @@ The following environment variables must be set to configure the bot:
`USE_PRIVATE_API` : Whether or not to use the Private API in BlueBubbles. Default is `false`
## Configuring Skills
Each skill consumes it's own environment variables to configure and run. Here are some of the configurable options for the included skills:
### chatgpt.py
`OPENAI_API_KEY` : The API key to OpenAI, from OpenAI.
`OPENAI_ORGANIZATION` : The Organization ID from OpenAI.
`RESPONSE_PREAMBLE` : Instructions to ChatGPT for how it should respond and behave, given as a preamble for any conversation with it. A default preamble is provided (see [persona/skills/chatgpt.py](chatgpt.py).
## Justification
Initially all I wanted to do was translate Apple Music links to Spotify links and vice-versa. But building platforms is more fun than building tools.

View File

@ -123,11 +123,11 @@ if __name__ == '__main__':
if content['type'] == 'new-message' :
message = content['data']
# Determine sender and receiver
if message['isFromMe'] :
if not message['isFromMe'] :
sender = message['handle']['address']
recipients = []
else :
sender = None
sender = 'Me'
recipients = [message['handle']['address']]
# Resolve attachments
attachments = []
@ -138,10 +138,13 @@ if __name__ == '__main__':
# Get any effects or subjects
subject = ''
effect_id = ''
isfromme = False
if 'subject' in message.keys() :
subject = message['subject']
if 'expressiveSendStyleId' in message.keys() :
effect_id = message['expressiveSendStyleId']
if 'isFromMe' in message.keys() :
isfromme = message['isFromMe']
# Craft the message
persona_message = persona.Message(
text=message['text'],
@ -151,7 +154,7 @@ if __name__ == '__main__':
timestamp=date_sent,
recipients=recipients,
attachments=attachments,
meta={'subject': subject, 'effectId': effect_id}
meta={'subject': subject, 'effectId': effect_id,'isFromMe': isfromme}
)
persona_message = get_full_attachments(persona_message)
responses = current_persona.receive_message(persona_message)

View File

@ -102,10 +102,14 @@ class Persona :
def startup(self) :
"""Startup all message skill processors"""
for skill in self._skill_map.keys() :
ClassInstance = self._skill_map[skill]
skillinstance = ClassInstance()
skillinstance.startup()
self.ready_skills.update({skill:skillinstance})
try :
ClassInstance = self._skill_map[skill]
skillinstance = ClassInstance()
skillinstance.startup()
self.ready_skills.update({skill:skillinstance})
except Exception as e :
self.log.error(str(e))
continue
def receive_message(self,message: Message) :

View File

@ -54,7 +54,7 @@ setup(name='bluebubbles_bot',
description='A chatbot for a local BlueBlubbles server.',
packages=find_packages(exclude=['tests']),
package_data={"": ['skills/*.py']},
install_requires=['pyyaml','datetime','requests','fastapi[all]'],
install_requires=['pyyaml','datetime','requests','fastapi[all]','openai'],
scripts=['bin/bluebubbles_bot'],
long_description=open('README.md').read(),
zip_safe=True