문서의 Python

docstring을 사용하여 Python 함수 생성

모델을 직접 쿼리하고 Cloud 콘솔에서 다른 매개변수 값을 사용하거나 Vertex AI API를 직접 호출하여 반환된 결과를 테스트할 수 있습니다.

자유 형식 프롬프트



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"""

docstring에 따라 영역 함수의 본문을 작성합니다.

응답


    # Unpack the triangle's points
    a, b, c = triangle


# Calculate the semi-perimeter of the triangle
s = perimeter(triangle) / 2

# Return the area of the triangle using Heron's formula
return sqrt(s * (s - distance(a, b)) * (s - distance(b, c)) * (s - distance(c, a)))

모델: gemini-1.5-pro-preview-0409
강도: 1
최대 출력 토큰: 8192
최상위 K: 40
최상위 P: 0.95