google / generative-ai-docs

Documentation for Google's Gen AI site - including the Gemini API and Gemma
https://ai.google.dev
Apache License 2.0
1.7k stars 612 forks source link

Google example API call fails with "RECITATION" #518

Closed johann-petrak closed 1 month ago

johann-petrak commented 2 months ago

Description of the bug:

This page gives the code for testing a newly established API key quickly: https://aistudio.google.com/app/apikey

curl \
  -H 'Content-Type: application/json' \
  -d '{"contents":[{"parts":[{"text":"Explain how AI works"}]}]}' \
  -X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=YOUR_API_KEY'

One would expect this to return a generated answer. Instead it returns:

{
  "candidates": [
    {
      "finishReason": "RECITATION",
      "index": 0
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 4,
    "totalTokenCount": 4
  }
}

Actual vs expected behavior:

See above

Any other information you'd like to share?

It is pretty werid and embarrassing that the very example given to test if invoking gemini works fails.

gmKeshari commented 2 months ago

Hi @johann-petrak. Sometimes, We see finish Reason as RECITATION because model will be generating copyright text from the training data. So, I would suggest to run the code again or modify the prompt a bit.

vishal-dharm commented 1 month ago

Hey @johann-petrak - are you still able to reproduce this? I've been trying to no avail on my end (ran the prompt 20ish times).

curl \
  -H 'Content-Type: application/json' \
  -d '{"contents":[{"parts":[{"text":"Explain how AI works"}]}]}' \
  -X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=<REDACTED>'
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "## How AI Works: A Simplified Explanation\n\nAI, or Artificial Intelligence, is a broad field that aims to create machines that can \"think\" and \"learn\" like humans. But how does it actually work? Here's a simplified explanation:\n\n**1. Data is the Fuel:** AI systems learn from vast amounts of data, like images, text, audio, and more. This data acts as a \"training set\" to teach the AI about the world.\n\n**2. Algorithms are the Tools:**  AI systems use complex algorithms, which are sets of instructions, to analyze and understand this data. There are different types of algorithms, but some common ones are:\n\n    * **Machine Learning:**  Algorithms that enable computers to learn from data without explicit programming. They identify patterns and make predictions based on that data.\n    * **Deep Learning:** A subset of machine learning that utilizes artificial neural networks, inspired by the structure of the human brain, to process information and make predictions.\n\n**3. Models are the Result:** By training on data using algorithms, AI systems build models that represent the relationships and patterns found in that data. These models are then used to perform tasks like:\n\n    * **Image recognition:** Identifying objects in images.\n    * **Natural language processing:** Understanding and generating human language.\n    * **Predictive analytics:** Forecasting future outcomes based on past data.\n\n**4. Continuous Learning:** AI systems are constantly being improved through ongoing training and refinement. As they encounter new data and feedback, their models become more accurate and sophisticated over time.\n\n**Example:** Imagine you want to teach an AI to recognize cats. You feed it thousands of images of cats and dogs. The algorithm analyzes these images and identifies patterns specific to cats (whiskers, pointy ears, etc.). It then builds a model that can distinguish between cats and dogs based on these patterns. \n\n**Key Points to Remember:**\n\n* **AI is not magic:** It relies on data, algorithms, and computational power.\n* **AI is constantly evolving:** New algorithms and techniques are being developed all the time.\n* **AI has the potential to be incredibly powerful:** It can automate tasks, solve complex problems, and improve our lives in many ways.\n\n**This is a very basic explanation, but hopefully it gives you a starting point to understand how AI works.** There are many different approaches and techniques used within AI, and it's a constantly developing field. \n"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0,
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE"
        }
      ]
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 4,
    "candidatesTokenCount": 504,
    "totalTokenCount": 508
  }
}
johann-petrak commented 1 month ago

I just retried and it works now.