2023-04-06 22:57:16 +03:00
|
|
|
# import writesonic
|
|
|
|
import writesonic
|
|
|
|
|
|
|
|
# create account (3-4s)
|
2023-04-27 17:43:59 +03:00
|
|
|
account = writesonic.Account.create(logging=True)
|
2023-04-06 22:57:16 +03:00
|
|
|
|
2023-04-27 22:10:43 +03:00
|
|
|
# with loging:
|
2023-04-27 17:43:59 +03:00
|
|
|
# 2023-04-06 21:50:25 INFO __main__ -> register success : '{"id":"51aa0809-3053-44f7-922a...' (2s)
|
|
|
|
# 2023-04-06 21:50:25 INFO __main__ -> id : '51aa0809-3053-44f7-922a-2b85d8d07edf'
|
|
|
|
# 2023-04-06 21:50:25 INFO __main__ -> token : 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ik...'
|
|
|
|
# 2023-04-06 21:50:28 INFO __main__ -> got key : '194158c4-d249-4be0-82c6-5049e869533c' (2s)
|
2023-04-06 22:57:16 +03:00
|
|
|
|
|
|
|
# simple completion
|
2023-04-27 22:10:43 +03:00
|
|
|
response = writesonic.Completion.create(api_key=account.key, prompt='hello world')
|
2023-04-06 22:57:16 +03:00
|
|
|
|
2023-04-27 17:43:59 +03:00
|
|
|
print(response.completion.choices[0].text) # Hello! How may I assist you today?
|
2023-04-06 22:57:16 +03:00
|
|
|
|
|
|
|
# conversation
|
|
|
|
|
|
|
|
response = writesonic.Completion.create(
|
2023-04-27 17:43:59 +03:00
|
|
|
api_key=account.key,
|
|
|
|
prompt='what is my name ?',
|
|
|
|
enable_memory=True,
|
2023-04-27 22:10:43 +03:00
|
|
|
history_data=[{'is_sent': True, 'message': 'my name is Tekky'}, {'is_sent': False, 'message': 'hello Tekky'}],
|
2023-04-06 22:57:16 +03:00
|
|
|
)
|
|
|
|
|
2023-04-27 17:43:59 +03:00
|
|
|
print(response.completion.choices[0].text) # Your name is Tekky.
|
2023-04-06 22:57:16 +03:00
|
|
|
|
|
|
|
# enable internet
|
|
|
|
|
|
|
|
response = writesonic.Completion.create(
|
2023-04-27 22:10:43 +03:00
|
|
|
api_key=account.key, prompt='who won the quatar world cup ?', enable_google_results=True
|
2023-04-06 22:57:16 +03:00
|
|
|
)
|
|
|
|
|
2023-04-27 17:43:59 +03:00
|
|
|
print(response.completion.choices[0].text) # Argentina won the 2022 FIFA World Cup tournament held in Qatar ...
|