writesonic_test.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # import writesonic
  2. import writesonic
  3. # create account (3-4s)
  4. account = writesonic.Account.create(logging = True)
  5. # with loging:
  6. # 2023-04-06 21:50:25 INFO __main__ -> register success : '{"id":"51aa0809-3053-44f7-922a...' (2s)
  7. # 2023-04-06 21:50:25 INFO __main__ -> id : '51aa0809-3053-44f7-922a-2b85d8d07edf'
  8. # 2023-04-06 21:50:25 INFO __main__ -> token : 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ik...'
  9. # 2023-04-06 21:50:28 INFO __main__ -> got key : '194158c4-d249-4be0-82c6-5049e869533c' (2s)
  10. # simple completion
  11. response = writesonic.Completion.create(
  12. api_key = account.key,
  13. prompt = 'hello world'
  14. )
  15. print(response.completion.choices[0].text) # Hello! How may I assist you today?
  16. # conversation
  17. response = writesonic.Completion.create(
  18. api_key = account.key,
  19. prompt = 'what is my name ?',
  20. enable_memory = True,
  21. history_data = [
  22. {
  23. 'is_sent': True,
  24. 'message': 'my name is Tekky'
  25. },
  26. {
  27. 'is_sent': False,
  28. 'message': 'hello Tekky'
  29. }
  30. ]
  31. )
  32. print(response.completion.choices[0].text) # Your name is Tekky.
  33. # enable internet
  34. response = writesonic.Completion.create(
  35. api_key = account.key,
  36. prompt = 'who won the quatar world cup ?',
  37. enable_google_results = True
  38. )
  39. print(response.completion.choices[0].text) # Argentina won the 2022 FIFA World Cup tournament held in Qatar ...
粤ICP备19079148号