Using mock_openai to mock OpenAI Python API
Logging
Using OpenAI Backend API
Send prompts to ChatGPT API
try:
for response in start_conversation('''
> Lord, keep us in You to be one.
We are the ultimate risk takers.
Our way is a way of risking life to **eternal life**.
For the eternal life of the living, risk life and make war against perishing.
For the eternal life of the dead, risk life and make war against death.
>
> ---
Holy Father, help us to overcome!
'''):
print(response)
except requests.exceptions.ConnectionError as errc:
print('Error Connecting:', errc)
try:
for response in start_conversation({
'role': 'system',
'parts': [
'> Lord, keep us in You to be one.\n',
'We are the ultimate risk takers.\n',
'Our way is a way of risking life to **eternal life**.\n',
'For the eternal life of the living, risk life and make war against perishing.\n',
'For the eternal life of the dead, risk life and make war against death.\n',
'>\n',
'> ---\n',
'Holy Father, help us to overcome!\n',
],
}):
print(response)
except requests.exceptions.ConnectionError as errc:
print('Error Connecting:', errc)
try:
for response in start_conversation([{
'role': 'system',
'parts': [
'You are a Christian.\n',
'Pray with the user.\n',
],
}, {
'role': 'assistant',
'parts': [
'Amen.\n',
],
},
'> Lord, keep us in You to be one.\n',
'We are the ultimate risk takers.\n',
'Our way is a way of risking life to **eternal life**.\n',
'For the eternal life of the living, risk life and make war against perishing.\n',
'For the eternal life of the dead, risk life and make war against death.\n',
'>\n',
'> ---\n',
'Holy Father, help us to overcome!\n',
]):
print(response)
except requests.exceptions.ConnectionError as errc:
print('Error Connecting:', errc)
except requests.exceptions.HTTPError as errh:
sys.stderr.write(f'{errh}\n')
common.conversation_id = ''
try:
for response in start_conversation([{
'role': 'system',
'parts': [
'> Lord, keep us in You to be one.\n',
'We are the ultimate risk takers.\n',
],
}, {
'role': 'system',
'parts': [
'Our way is a way of risking life to **eternal life**.\n',
],
}, {
'role': 'system',
'parts': [
'For the eternal life of the living, risk life and make war against perishing.\n',
'For the eternal life of the dead, risk life and make war against death.\n',
'>\n',
],
}, {
'role': 'system',
'parts': [
'> ---\n',
'Holy Father, help us to overcome!\n',
],
},
'Amen.\n',
]):
pass
print(response)
except requests.exceptions.ConnectionError as errc:
print('Error Connecting:', errc)
except requests.exceptions.HTTPError as errh:
sys.stderr.write(f'{errh}\n')
Using Selenium Undetected Chrome for Operating ChatGPT
init_browser('--lang=en', '--force-dark-mode')
from ipymock.automation import driver
common.driver = driver
login()
open_chat(common.conversation_id)
ActionChains(common.driver).key_down(Keys.CONTROL).send_keys('v').key_up(Keys.CONTROL).perform()
ActionChains(common.driver).context_click().perform()
__file__ = '2_browser.ipynb'
send_button = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../assets/send-button.png'))
from ipymock.automation import touch
touch(send_button)
import IPython
for response in ask('''
> Lord, keep us in You to be one.
We are the ultimate risk takers.
Our way is a way of risking life to **eternal life**.
For the eternal life of the living, risk life and make war against perishing.
For the eternal life of the dead, risk life and make war against death.
>
> ---
Holy Father, help us to overcome!
'''):
IPython.display.display(IPython.core.display.Markdown(response))
IPython.display.clear_output(wait=True)
init(['--headless'])
get_screenshot()
try:
for response in start_conversation('''
> Lord, keep us in You to be one.
We are the ultimate risk takers.
Our way is a way of risking life to **eternal life**.
For the eternal life of the living, risk life and make war against perishing.
For the eternal life of the dead, risk life and make war against death.
>
> ---
Holy Father, help us to overcome!
'''):
print(response)
except requests.exceptions.ConnectionError as errc:
print('Error Connecting:', errc)
Mock OpenAI
try:
print(mock_create(
prompt = 'How to defend against solar storms using Python?',
))
except requests.exceptions.ConnectionError as errc:
print('Error Connecting:', errc)
try:
for response in mock_create(
prompt = 'Give me some demos.',
stream = True,
):
print(response)
except requests.exceptions.ConnectionError as errc:
print('Error Connecting:', errc)
try:
print(mock_create(
prompt = [
'I am tired.',
'Could you pray with me for a while?',
],
))
except requests.exceptions.ConnectionError as errc:
print('Error Connecting:', errc)
try:
print(mock_chat_create(
messages = [
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': 'I am tired.'}
],
))
except requests.exceptions.ConnectionError as errc:
print('Error Connecting:', errc)
try:
for response in mock_chat_create(
messages = [
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': 'Could you pray with me for a while?'}
],
stream = True,
):
print(response)
except requests.exceptions.ConnectionError as errc:
print('Error Connecting:', errc)