728x90

ValueError: The `response.parts` quick accessor only works for a single candidate, but none were returned. Check the `response.prompt_feedback` to see if the prompt was blocked.

 

์›์ธ : ์ž˜๋ชป๋œ request๋กœ prompt ์‘๋‹ต์ด ์ฐจ๋‹จ๋œ case ํ˜น์€ safety setting error 

 request ๋ณด๋‚ด๊ธฐ ์ „์— parameter๋ฅผ ๋‹ค ๊ธฐ์ž…ํ•ด์ค€๋‹ค. ํ˜„์žฌ๋กœ์„œ๋Š” max_tokens

  • candidate_count : ์ถœ๋ ฅ ์ˆ˜ 
  • top_p : log_probabilities๋“ค์˜ argmax ๊ฐ’์„ ์—ญ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ๋’ค ๋‹จ์–ด ๋‹จ์œ„๋กœ ์žฌ๊ตฌ์„ฑ (๊ธ€๋ €๋‹ค_argmax : 0.7, ํž˜๋“ค๋‹ค_argmax: 0.3)
    • ์˜ค๋Š˜ ์•„์นจ ๋จน๊ธฐ๋Š” ๊ธ€๋ €๋‹ค
    • ์˜ค๋Š˜ ์•„์นจ ๋จน๊ธฐ๋Š” ํž˜๋“ค๋‹ค.
generation_config = {
  "candidate_count": 1,
  "max_output_tokens": 256,
  "temperature": 1.0,
  "top_p": 0.7,
}
safety_settings=[
  {
    "category": "HARM_CATEGORY_DANGEROUS",
    "threshold": "BLOCK_NONE",
  },
  {
    "category": "HARM_CATEGORY_HARASSMENT",
    "threshold": "BLOCK_NONE",
  },
  {
    "category": "HARM_CATEGORY_HATE_SPEECH",
    "threshold": "BLOCK_NONE",
  },
  {
    "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
    "threshold": "BLOCK_NONE",
  },
  {
    "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
    "threshold": "BLOCK_NONE",
  },
]

model = genai.GenerativeModel(
    model_name="gemini-pro",
    generation_config=generation_config,
    safety_settings=safety_settings
)

 

 

https://github.com/google/generative-ai-python/issues/126

 

โ€œ1โ€˜ is blocked by safety reason? seriously ยท Issue #126 ยท google/generative-ai-python

Description of the bug: when i send 1 to the gemini pro, it raise a exception : ValueError: The response.parts quick accessor only works for a single candidate, but none were returned. Check the re...

github.com

 

๋ฐ˜์‘ํ˜•
๋‹คํ–ˆ๋‹ค