Skip to content

Commit

Permalink
0.7.27
Browse files Browse the repository at this point in the history
Indigo 2023.2 API 3.4 Only
Add requirements processing
Change logging if sql connection fails, stop Plugin if fails at startup
Add increase error logging if incorrect buddy handle message fails to go (as per issue #14)

0.7.20
Add requirements for Indigo API 3.4 Library install

0.7.16
Add error checking for missing Library

0.7.15
Dont reload model api call

0.7.14
Allow curly brackets { in reply

0.7.13
With Sonoma apple decided the iMsg database would store the message data in a Apple NSString Archived object.  Taking up oodles more room.
It appears the plain text is quickly converted and then becomes NULL.
Update plugin to decode message.attributedbody using typedstream and decoded contents of NSString formatting.
Add selection of ChatGPT model available (changes depending on user account).  Allows

0.7.10
Move model to gpt-3.5-16k
Increase token count to 8000
TODO user selectable both above when time

0.7.9
Model back to gpt-3.5
& remove some while loops trying to track down occasional 'hang'

0.7.8
Change model to gpt-4 when rolls out for all.

0.7.7
Update openai library to 0.27.4

0.7.6
Add chatGPT only Buddy - these individuals can only converse with chatGPT.  They won't have any trigger or command options
If device control enabled will allow device Control, but increasingly not sure this is a great idea for this plugin

0.7.5
Handle and specifically message regarding timeout, ratelimt openai errors

0.7.4
OpenAI reports that the system prompt is largely ignored with user prompt having more 'attention'
Because of this duplicate some setup into a new user prompt

0.7.3
Fix for debugextra logging string conversion issue (also in 0.7.2)
Better checking for token usage and deletion of prompts before gets to limit
Add 2nd Pluginconfig Personal info:  Aim of this is to educate chatGPT as to who the various users/buddies are.
Should be Buddy Handle followed by | and then description written in first person.
buddyhandle|I am user Glenn.I am.. |buddyhandle2|I am user Glenns co-worker.

Probably would better be a setup file, as really need to type somewhere else and paste in...

## 0.7.1
Fix for quotes

## New 0.7.0

Add support for ChatGPT 3.5 turbo API usage.(Beta)
This can be used to control indigo devices (so marked for control), like wit.ai - however it probably needs a bit of maturing before that works 100%

Currently though the chatbot, chat, information, advice function via chatGPT works very well and enables easy access to chatGPT replies for whatever usage.
Like chatGPT warning - accuracy here depends on the subject, but for natural language processing it is great.
  • Loading branch information
Ghawken committed Jan 25, 2024
1 parent 932a98c commit ae21b7f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion iMessage.indigoPlugin/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>PluginVersion</key>
<string>0.7.26</string>
<string>0.7.27</string>
<key>ServerApiVersion</key>
<string>3.4</string>
<key>IwsApiVersion</key>
Expand Down
77 changes: 42 additions & 35 deletions iMessage.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(self, pluginId, pluginDisplayName, pluginVersion, pluginPrefs):
self.username = str(os.getlogin())
self.pathtoPlugin = os.getcwd()
self.startingUp = True
self.connection = None
self.systemVersion = int(platform.release()[:2]) ## take first two digits and make an int: 18-Mojave, 17 High ierra, 16 - Sierra
self.pluginIsInitializing = True
self.pluginIsShuttingDown = False
Expand Down Expand Up @@ -363,35 +364,30 @@ def runConcurrentThread(self):

try:
self.connectsql()
#x =0
while True:
#x=x+1
self.sleep(5)

messages = self.sql_fetchmessages()
if len(messages)>0:
self.parsemessages(messages)
if len(self.awaitingConfirmation)>0:
self.checkTimeout()
if self.lastCommandsent:
if t.time() > self.resetLastCommand:
if self.debugextra:
self.logger.debug(u'Within RunConcurrent Thread: Resetting self.lastcommandsent')
self.lastCommandsent.clear()
self.resetLastCommand = t.time()+120
if self.debugextra:
self.logger.debug(u'Now Self.lastcommandsent :'+str(self.lastCommandsent))
# if self.updateFrequency > 0:
# if t.time() > self.next_update_check:
# try:
# self.checkForUpdates()
# self.next_update_check = t.time() + self.updateFrequency
# except:
# self.logger.debug(
# u'Error checking for update - ? No Internet connection. Checking again in 24 hours')
# self.next_update_check = self.next_update_check + 86400
# if self.debugexceptions:
# self.logger.exception(u'and Caught Exception:')
try:
self.sleep(4)
messages = self.sql_fetchmessages()
if len(messages)>0:
self.parsemessages(messages)
if len(self.awaitingConfirmation)>0:
self.checkTimeout()
if self.lastCommandsent:
if t.time() > self.resetLastCommand:
if self.debugextra:
self.logger.debug(u'Within RunConcurrent Thread: Resetting self.lastcommandsent')
self.lastCommandsent.clear()
self.resetLastCommand = t.time()+120
if self.debugextra:
self.logger.debug(u'Now Self.lastcommandsent :'+str(self.lastCommandsent))
except self.StopThread:
self.logger.info(f"Stopping plugin.")
break
except:
self.logger.debug(f"Exception caught in runConcurrent thread", exc_info=True)
pass


except self.StopThread:
self.debugLog(u'Restarting/or error. Stopping thread.')
self.closesql()
Expand All @@ -403,20 +399,25 @@ def connectsql(self):
if self.debugextra:
self.debugLog(u"connectsql() method called.")
try:

self.filename = os.path.expanduser('~/Library/Messages/chat.db')
if self.debugextra:
self.logger.debug(u'ConnectSQL: Filename location for iMsg chat.db equals:'+str(self.filename))
self.connection = sqlite3.connect(self.filename)
self.logger.info(u'Connection to iMsg Database Successful.')
except:
except sqlite3.OperationalError as ex:
self.logger.error(u'Problem connecting to iMessage database....')
self.logger.error(u'Most likely you have not allowed IndigoApp and IndigoServer Full Disk Access')
self.logger.error(u'Please see instructions. This only needs to be done once.')
self.logger.error(u'Once done please restart the plugin.')
if self.debugextra:
self.logger.error(f"Error Received: == {ex} ==")
self.logger.error(u'Shutting down plugin now.')
if self.debugexceptions:
self.logger.exception(u'and here is the Caught Exception (self.debugexceptions is on:)')
self.sleep(600)
self.stopPlugin()
except Exception as ex:
self.logger.error(u'Unknown Error connecting to iMessage database....')
self.logger.exception(f"Exception:")
# self.stopPlugin()
return

def closesql(self):
Expand Down Expand Up @@ -456,9 +457,15 @@ def sql_fetchattachments(self):
return result

def sql_fetchmessages(self):
# if self.debugextra:
# self.debugLog(u"fetch messages() method called.")
cursor = self.connection.cursor()
try:
cursor = self.connection.cursor()
except AttributeError as ex:
self.logger.debug(f"Attribute error connecting to sqllite. ?Not connected. Error {ex}")
self.logger.info(f"Error connecting to Database, connection appears to not exist. Attempting to reconnect")
self.connectsql()

return dict()

using_attributedBody = False
#below is needed for older than Mojave
if self.systemVersion >=22:
Expand Down

0 comments on commit ae21b7f

Please sign in to comment.