Как мне управлять подсказками с помощью GCP Vertex AI?Python

Программы на Python
Anonymous
 Как мне управлять подсказками с помощью GCP Vertex AI?

Сообщение Anonymous »

В AWS Bedrock мы можем использовать AWS BEDROCK PROMPT MANAGEMENT для управления жизненным циклом подсказок. Как мне это сделать в GCP VertexAI или студии Google AI
Я пытался использовать код, указанный в ссылке ниже, но код выглядит неработающим, а пакет Vertex AI кажется старым
https://docs.cloud.google.com/vertex-ai ... s#overview
Я попробовал следующее код
import vertexai
from vertexai import types
from google.genai import types

prompt = types.Prompt(
prompt_data=types.PromptData(
contents=[genai_types.Content(parts=[genai_types.Part(text="Hello, {name}! How are you?")])],
variables=[
{"name": genai_types.Part(text="Alice")},
{"name": genai_types.Part(text="Bob")},
],
model="your-model",
),
)

Обновление приведенного выше кода:
Я продолжал пробовать разные варианты и смог заставить приведенный выше код работать так же, как показано ниже. Мне пришлось импортировать типы из защищенного члена в vertexai, что, на мой взгляд, не очень хорошо. Мне действительно нужны советы и помощь в этом вопросе.
import vertexai
from google.genai import types as genai_types
from vertexai._genai import types

# Instantiate GenAI client from Vertex SDK
# Replace with your project ID and location
client = vertexai.Client(project='xxxx', location='us-central1')

prompt = types.Prompt(
prompt_data=types.PromptData(
contents=[genai_types.Content(parts=[genai_types.Part(text="Hello, {name}! How are you?")])],
system_instruction=genai_types.Content(parts=[genai_types.Part(text="Please answer in a short sentence.")]),
variables=[
{"name": genai_types.Part(text="Alice")},
],
model="gemini-2.5-flash",
),
)

prompt_resource = client.prompts.create(
prompt=prompt,
)

print(prompt_resource)


Подробнее здесь: https://stackoverflow.com/questions/798 ... management

Вернуться в «Python»