Advertisement
Guest User

Untitled

a guest
Apr 5th, 2024
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. # CODE
  2.  
  3. genai.configure(api_key=key)
  4. model = genai.GenerativeModel('gemini-pro')
  5.  
  6. headers = {'Content-Type': 'application/json'}
  7. payload = {
  8. "contents": {
  9. "role": "USER",
  10. "parts": { "text": "What is meaning of life in 1 sentence." }
  11. }
  12. }
  13.  
  14. a = requests.post(f"https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key={key}"
  15. , headers=headers, json=payload)
  16.  
  17. print('requests')
  18. print(a.text)
  19.  
  20. print("api")
  21. response = model.generate_content("What is meaning of life in 1 sentence.")
  22. print(response.text)
  23.  
  24.  
  25. ## Response
  26.  
  27. (env) bash-3.2$ python test.py
  28. requests module:
  29.  
  30. {
  31. "candidates": [
  32. {
  33. "content": {
  34. "parts": [
  35. {
  36. "text": "The subjective pursuit of purpose and fulfillment within one's existence."
  37. }
  38. ],
  39. "role": "model"
  40. },
  41. "finishReason": "STOP",
  42. "index": 0,
  43. "safetyRatings": [
  44. {
  45. "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
  46. "probability": "NEGLIGIBLE"
  47. },
  48. {
  49. "category": "HARM_CATEGORY_HATE_SPEECH",
  50. "probability": "NEGLIGIBLE"
  51. },
  52. {
  53. "category": "HARM_CATEGORY_HARASSMENT",
  54. "probability": "NEGLIGIBLE"
  55. },
  56. {
  57. "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
  58. "probability": "NEGLIGIBLE"
  59. }
  60. ]
  61. }
  62. ],
  63. "promptFeedback": {
  64. "safetyRatings": [
  65. {
  66. "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
  67. "probability": "NEGLIGIBLE"
  68. },
  69. {
  70. "category": "HARM_CATEGORY_HATE_SPEECH",
  71. "probability": "NEGLIGIBLE"
  72. },
  73. {
  74. "category": "HARM_CATEGORY_HARASSMENT",
  75. "probability": "NEGLIGIBLE"
  76. },
  77. {
  78. "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
  79. "probability": "NEGLIGIBLE"
  80. }
  81. ]
  82. }
  83. }
  84.  
  85. api
  86. Traceback (most recent call last):
  87. File "test.py", line 32, in <module>
  88. response = model.generate_content("What is meaning of life in 1 sentence.")
  89. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  90. File "env/lib/python3.12/site-packages/google/generativeai/generative_models.py", line 232, in generate_content
  91. response = self._client.generate_content(
  92. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  93. File "env/lib/python3.12/site-packages/google/ai/generativelanguage_v1beta/services/generative_service/client.py", line 566, in generate_content
  94. response = rpc(
  95. ^^^^
  96. File "env/lib/python3.12/site-packages/google/api_core/gapic_v1/method.py", line 131, in __call__
  97. return wrapped_func(*args, **kwargs)
  98. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  99. File "env/lib/python3.12/site-packages/google/api_core/retry/retry_unary.py", line 293, in retry_wrapped_func
  100. return retry_target(
  101. ^^^^^^^^^^^^^
  102. File "env/lib/python3.12/site-packages/google/api_core/retry/retry_unary.py", line 153, in retry_target
  103. _retry_error_helper(
  104. File "env/lib/python3.12/site-packages/google/api_core/retry/retry_base.py", line 212, in _retry_error_helper
  105. raise final_exc from source_exc
  106. File "env/lib/python3.12/site-packages/google/api_core/retry/retry_unary.py", line 144, in retry_target
  107. result = target()
  108. ^^^^^^^^
  109. File "env/lib/python3.12/site-packages/google/api_core/timeout.py", line 120, in func_with_timeout
  110. return func(*args, **kwargs)
  111. ^^^^^^^^^^^^^^^^^^^^^
  112. File "env/lib/python3.12/site-packages/google/api_core/grpc_helpers.py", line 78, in error_remapped_callable
  113. raise exceptions.from_grpc_error(exc) from exc
  114. google.api_core.exceptions.DeadlineExceeded: 504 Deadline Exceeded
  115.  
  116. (env) bash-3.2$
  117.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement