Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Google Gemini API Error: google.api_core.exceptions.InternalServerError: 500 An internal error has o

0

I have a dataset with 148 rows and 12 columns and want to generate text for each cell with the Gemini API. Now the error that occurs is 'google.api_core.exceptions.InternalServerError: 500 An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting' I activated my Account under the Google Cloud. Sometimes it generates the first few columns before the error occurs and sometimes it directly returns the error. Did anyone solve this for good?

def process_industries_and_subniches(): df = pd.read_excel('Niches.xlsx')

# Word-Dokument erstellen
doc = Document()

# Excel-Arbeitsmappe erstellen
wb = Workbook()
ws = wb.active
ws['A1'] = "Industrie"
ws['B1'] = "Sub-Industrie"
ws['C1'] = "Text"
row_counter = 2

last_industry = None

# Durch den DataFrame iterieren
for index, row in df.iterrows():
    industry = row[df.columns[0]]

    for sub_niche in row[1:].dropna():  # Start von Spalte B, leere Zellen überspringen
        content = generate_gemini_output(industry, sub_niche)

        # Wenn es eine neue Industrie ist, dann mehr Platz lassen
        if industry != last_industry: 
            heading = doc.add_heading(f"{industry}: {sub_niche}", level=1)
            heading.bold = True
            heading.style.font.size = Pt(16)

            # Einen leeren Absatz mit extra Platz hinzufügen
            paragraph = doc.add_paragraph("")
            paragraph.style.paragraph_format.space_before = Pt(48)

        # Den generierten Inhalt hinzufügen
        paragraph = doc.add_paragraph(content)
        paragraph.style.paragraph_format.space_before = Pt(24)

        # Letzte verarbeitete Industrie aktualisieren
        last_industry = industry

        # Excel-Formatierung
        if industry != last_industry:
            row_counter += 1
            ws[f'A{row_counter}'] = industry
            ws[f'A{row_counter}'].font = Font(bold=True)
            ws[f'A{row_counter}'].alignment = Alignment(horizontal='center')

        ws[f'B{row_counter}'] = sub_niche
        ws[f'C{row_counter}'] = content

        row_counter += 1

        time.sleep(2)
        print("Aktuell bei: " + industry + " und " + sub_niche)

# Benennungslogik für die Datei
temperature_str = str(generation_config["temperature"]).replace(".", "_")
top_p_str = str(generation_config["top_p"])
filename = f"Formatted_Content_{temperature_str}_{top_p_str}"

wb.save(f'{filename}.xlsx')
doc.save(f'{filename}.docx')
3 1 999
1 REPLY 1

I assume the exception is at the function generate_gemini_output().

Could you share the code for it? When you receive the 500, is it the same input every time that caused it or it's transient?

Are you calling the API to your own Cloud Project or someone else's?