Python aus der Dokumentation

Python-Funktion anhand ihres docstring generieren

Sie können ein Modell direkt abfragen und die zurückgegebenen Ergebnisse testen, wenn Sie verschiedene Parameterwerte mit der Cloud Console oder durch direkten Aufruf der Vertex AI API verwenden.

Freiform-Prompt


from collections import namedtuple
from math import sqrt


# A point has an x and a y coordinate
Point = namedtuple('Point', 'x y')
# A triangle is defined by three points
Triangle = namedtuple('Triangle', 'a b c')


def distance(p, q):
"""Returns the distance between the provided pair of points"""
return sqrt((p.x - q.x)**2 + (p.y - q.y)**2)


def perimeter(triangle):
"""Returns the perimeter of the provided triangle"""
return distance(triangle.a, triangle.b) + distance(triangle.b, triangle.c) + distance(triangle.c, triangle.a)


def area(triangle):
"""Returns the area of the provided triangle using Heron's formula"""

Schreiben Sie den Text der Bereichsfunktion anhand ihrem docstring.

Antwort


from collections import namedtuple
from math import sqrt


# A point has an x and a y coordinate
Point = namedtuple('Point', 'x y')
# A triangle is defined by three points
Triangle = namedtuple('Triangle', 'a b c')


def distance(p, q):
"""Returns the distance between the provided pair of points"""
return sqrt((p.x - q.x)**2 + (p.y - q.y)**2)


def perimeter(triangle):
"""Returns the perimeter of the provided triangle"""
return distance(triangle.a, triangle.b) + distance(triangle.b, triangle.c) + distance(triangle.c, triangle.a)


def area(triangle):
"""Returns the area of the provided triangle using Heron's formula"""
s = perimeter(triangle) / 2
return sqrt(s * (s - distance(triangle.a, triangle.b)) * (s - distance(triangle.b, triangle.c)) * (s - distance(triangle.c, triangle.a)))
Modell: gemini-1.5-flash-001
Temperatur: 1
Max. Ausgabetokens: 8.192
TopK: 40
TopP: 0,95