Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2025
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1.  
  2. Here simplified to a single curl command:
  3. curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=YOUR-API-KEY" \
  4. -H 'Content-Type: application/json' \
  5. -X POST \
  6. -d '{
  7. "contents": [{
  8. "parts":[{"text": "Who is the current Chancellor of Germany?"}]
  9. }],
  10. "tools": [{
  11. "googleSearch": {}
  12. }]
  13. }' | grep -o '"text": "[^"]*"' | sed 's/"text": "\(.*\)"/\1/'
  14.  
  15. Complete example (REST) from aistudio:
  16. #!/bin/bash
  17. set -e -E
  18. GEMINI_API_KEY="$GEMINI_API_KEY"
  19. MODEL_ID="gemini-2.0-flash"
  20. GENERATE_CONTENT_API="streamGenerateContent"
  21.  
  22. cat << EOF > request.json
  23. {
  24. "contents": [
  25. {
  26. "role": "user",
  27. "parts": [
  28. {
  29. "text": "INSERT_INPUT_HERE"
  30. },
  31. ]
  32. },
  33. ],
  34. "generationConfig": {
  35. "responseMimeType": "text/plain",
  36. },
  37. "tools": [
  38. {
  39. "googleSearch": {}
  40. },
  41. ],
  42. }
  43. EOF
  44.  
  45. curl \
  46. -X POST \
  47. -H "Content-Type: application/json" \
  48. "https://generativelanguage.googleapis.com/v1beta/models/${MODEL_ID}:${GENERATE_CONTENT_API}?key=${GEMINI_API_KEY}" -d '@request.json'
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement