terry3041 / pyChatGPT

An unofficial Python wrapper for OpenAI's ChatGPT API
GNU General Public License v3.0
1.35k stars 255 forks source link

python example wrapper with 'python3 -m pyChatGPT' ? #143

Open fredmo opened 1 year ago

fredmo commented 1 year ago

As I remark the api python is n't working but the "python3 -m pyChatGPT" is still functional,

I tried to do this wrapper :


from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals

import pexpect
import time
import sys

p = pexpect.spawnu('python3 -m pyChatGPT')
p.logfile = open("mylog", "w")
p.timeout=300

p.expect('Please enter your session token:')
p.sendline('**Here is my session**')

#p.expect('Please enter your conversation id')
p.expect('if you want to continue old chat')

p.sendline('**uuid**')

p.expect('You')
#p.interact()
time.sleep(5)

Question=sys.argv[1]

p.sendline(Question)
p.expect(Question)

p.expect('ChatGPT:')
time.sleep(1)
p.expect('You')

#print("before :")
print(p.before)

If useful, it s now functional ( sometimes ), but if the "question" is on several lines, it takes only the first line :(