Using mock_openai to mock OpenAI Python 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')
selenium undetected chrome
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)