Veröffentlicht am
Judge Agent

Code-Workflow mit Mistral AI Agents

Post image In diesem Beitrag dokumentiere ich ein Beispiel für einen Workflow zur Python-Code-Generierung mit Mistral AI Agents.

Überblick über Mistral AI Agents

Inspiriert vom Python Agent Workflow, der in den offiziellen Ressourcen von Mistral dokumentiert ist, habe ich einen benutzerdefinierten Workflow namens gen_code_workflow entwickelt. Das Ziel dieses Workflows ist es, die Generierung von Python-Skripten basierend auf benutzerdefinierten Anweisungen zu automatisieren. Eine Schleife ist in den Workflow integriert, um die Skriptausführung und Wiederholung im Falle von Fehlern zu handhaben.

Der Workflow nutzt drei Mistral AI Agents:

  • Python Code Generator Agent: Generiert Python-Skripte basierend auf Benutzereingaben.
  • Python Code Fixer Agent: Versucht, Ausführungsfehler im generierten Code zu beheben.
  • Judge Agent: Bewertet das Python-Skript anhand der Benutzeranweisungen und vergibt eine Punktzahl zwischen 0 und 10.

Workflow-Argumente

Der gen_code_workflow akzeptiert die folgenden Argumente:

  • Benutzeranweisungen (str)
  • Optional: Dateipfad zum Speichern des resultierenden Python-Skripts (str)
  • Optional: Debugging-Modus (bool)

Workflow-Diagramm

Workflow chart

Diagramm erstellt mit Excalidraw Integration mit Mermaid.

Beispielausführung

gen_code_workflow("""
   Generate a method to search Wikipedia for a specific topic.
   You will receive the search topic as an argument. If no argument is passed, set a default.
   The method should return information found on Wikipedia.
   Use a publicly available Python library to access Wikipedia.
   Do not limit the number of sentences.
   Handle errors in case the topic is not found.
   Document the method with its arguments and return values.
""","test.py", False)
Score: 8.5

Resultierendes Python-Skript

import wikipedia
import subprocess
import sys

# Install the wikipedia library if it's not already installed
try:
    import wikipedia
except ImportError:
    subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'wikipedia'])

def search_wikipedia(topic='Python programming language'):
    """
    Search Wikipedia for a given topic and return the information found.

    Args:
        topic (str): The topic to search on Wikipedia. Defaults to 'Python programming language'.

    Returns:
        str: The information found on Wikipedia for the specified topic.
              If the topic is not found, returns a user-friendly error message.
    """
    try:
        # Search Wikipedia for the provided topic
        page = wikipedia.page(topic)
        return page.content
    except wikipedia.exceptions.PageError:
        # Handle the case where the topic is not found
        return f"The topic '{topic}' was not found on Wikipedia."
    except wikipedia.exceptions.DisambiguationError as e:
        # Handle disambiguation errors by returning a message with possible options
        return f"The topic '{topic}' is ambiguous. Possible options are: {e.options}"

if __name__ == "__main__":
    print(search_wikipedia('Artificial Intelligence'))

Hat Ihnen dieser Beitrag gefallen? Fanden Sie ihn hilfreich? Hinterlassen Sie gerne einen Kommentar unten, um Ihre Gedanken mitzuteilen oder Fragen zu stellen. Ein GitHub-Konto ist erforderlich, um an der Diskussion teilzunehmen.

Weiterlesen

Ähnliche Beiträge