stakwork / sphinx-ios

Client app for communication over the lightning network.
MIT License
18 stars 11 forks source link

ChatGPT contact in Sphinx #201

Closed tomastiminskas closed 11 months ago

tomastiminskas commented 1 year ago

Question:

STAKWORK:

  1. Create RSA encryption key pair so users can send message to ChatGPT encrypted (key size 2048 bits)
  2. New GET endpoint to get encryption_public_key base64 string from Stakwork and price_per_message
  3. New POST endpoint to send message/question to ChatGPT (?) Params:
    • message: encrypted message using Stakwork encryption public key
    • user_public_key: user encryption public key so stakwork can encrypt response for user

RELAY:

  1. Call to Stakwork at start time to get encryption public key from it and price per message
  2. Create ChatGPT contact with fake lightning public key (this can be saved in a constant and use it to identify ChatGPT contact) and the encryption public key got from Stakwork GET endpoint in step 1 (as contact_key on contacts table). Also create the chat with this contact and store the price_per_message on it
  3. When app hits send message endpoint if relay detects the message is to ChatGPT contact (using contact pub key), then it will hit Stakwork endpoint instead of actually sending the message as to any other contact. On endpoint response it will create the message as received and will notify the app through socket

APP:

  1. Disabled other features than text message on this chat (we need a way on the app to identify this contact)
  2. Show pricePerMessage and any other special information on this chat (that is different from any other contact)

If we remove encryption on the process, we can store messages encrypted in relay, but they will go from phone to relay and from relay to Stakwork unencrypted. Same with the response, they will travel unencrypted but will be encrypted before being stored in relay db and sent to device. This would simplify the process a lot.

uncleJim21 commented 1 year ago

This is a great idea. It looks like you're already doing this @tomastiminskas but it would be worthwhile to keep this "recipe" scalable & interoperable for other possible services (for example suppose we want Midjourney as a contact next). This is a great step toward making AI accessible to everyone even without a credit card.

Other thought: do we need some sort of throttling? I understand we are charging sats but my understanding is ChatGPT does have a hard limit after a certain point. Maybe we need a pool of accounts that we can route to to minimize the likelihood of issues.

tomastiminskas commented 1 year ago

@jimBeaux27 we have a paid chatGPT account in Stakwork so we will be using that one. As it's paid, we will charge the user for it as well.

@pitoi whenever you have time, please take a look at this ticket and let me know your thoughts.

uncleJim21 commented 1 year ago

Just because it's paid does not mean it has no limitations. I understand that it is possible that you reach the limit of bandwidth in what you can ask ChatGPT in a given time window. If there are hundreds of people on the same account, even if it's paid that could be an issue. Even if it has a cost to them it is possible you have a "rich bastard" that just spams requests.

One workaround is to have a pool of accounts to help scale or to limit the # of requests in a given window. I have implemented something similar to this on a different application if you'd like to discuss.

tomastiminskas commented 1 year ago

@jimBeaux27 we discussed this with Paul and we will remove encryption of the process. Messages will be stored encrypted in user relay, but they will go unencrypted from relay to Stakwork. Same with the response from Stakwork to relay.

In the other hand, if we will charge the user for each question, instead of hitting an endpoint on Stakwork we would need to send a keysend with a new type and the amount needed. So Stakwork will process it if the amount is correct and will send another keysend to user node with the response.

@Evanfeenstra @gonzaloaune not sure if Stakwork has a relay instance running that could handle this. Thoughts?

gonzaloaune commented 1 year ago

Stakwork does not have the ability to send / receive keysends since it doesn't have its own Relay.

We do make payments via Keysend but that's just a custom endpoint we have in Hub for the purpose of paying people.

tomastiminskas commented 1 year ago

We might need to use LSAT as we use on Second Brain so user can pay for it, then send the proof of payment when sending the question to ChatGPT through the Stakwork endpoint, so Stakwork can verify the pmt and send the response on the endpoint response. Or an error message if pmt was not verified.

Maybe we can do a call when @Evanfeenstra is back to discuss this and find the best approach

kevkevinpal commented 1 year ago

we do have this endpoint that gives access to chatGPT4 workflow on stakwork that needs a lsat

http://<redacted>/chatGPT

we also have these endpoints on relay that we could use on the ios app

  app.get('/lsats', lsats.listLsats)
  app.get('/lsats/:identifier', lsats.getLsat)
  app.post('/lsats', lsats.saveLsat)
  app.put('/lsats/:identifier', lsats.updateLsat)
  app.delete('/lsats/:identifier', lsats.deleteLsat)
  app.get('/active_lsat', lsats.getActiveLsat)

Not sure if on the app we can add the endpoint for stakwork and then use these endpoints to do the request, only thing is that stakwork responds only to a webhook url cause the response takes time and I'm not sure if its possible for the app itself to get the response

gonzaloaune commented 1 year ago

we were discussing with @tomastiminskas maybe have a dedicated relay + lnd for Stakwork (or use the one we use now to pay workers) and Stak will have special skills to communicate with it, that way Stak can respond by replying to that Relay and it can issue keysend commands to specific pubkeys.