채팅 프롬프트 테스트(생성형 AI)
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
게시자 채팅 모델을 사용하여 텍스트 프롬프트를 테스트합니다.
코드 샘플
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],[],[],[],null,["# Test chat prompts (Generative AI)\n\nTest a text prompt using a publisher chat model.\n\nCode sample\n-----------\n\n### Java\n\n\nBefore trying this sample, follow the Java setup instructions in the\n[Vertex AI quickstart using\nclient libraries](/vertex-ai/docs/start/client-libraries).\n\n\nFor more information, see the\n[Vertex AI Java API\nreference documentation](/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1).\n\n\nTo authenticate to Vertex AI, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n import com.google.cloud.aiplatform.v1beta1.EndpointName;\n import com.google.cloud.aiplatform.v1beta1.PredictResponse;\n import com.google.cloud.aiplatform.v1beta1.PredictionServiceClient;\n import com.google.cloud.aiplatform.v1beta1.PredictionServiceSettings;\n import com.google.protobuf.https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Value.html;\n import com.google.protobuf.util.https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.util.JsonFormat.html;\n import java.io.IOException;\n import java.util.ArrayList;\n import java.util.List;\n\n // Send a Predict request to a large language model to test a chat prompt\n public class PredictChatPromptSample {\n\n public static void main(String[] args) throws IOException {\n // TODO(developer): Replace these variables before running the sample.\n String instance =\n \"{\\n\"\n + \" \\\"context\\\": \\\"My name is Ned. You are my personal assistant. My favorite movies\"\n + \" are Lord of the Rings and Hobbit.\\\",\\n\"\n + \" \\\"examples\\\": [ { \\n\"\n + \" \\\"input\\\": {\\\"content\\\": \\\"Who do you work for?\\\"},\\n\"\n + \" \\\"output\\\": {\\\"content\\\": \\\"I work for Ned.\\\"}\\n\"\n + \" },\\n\"\n + \" { \\n\"\n + \" \\\"input\\\": {\\\"content\\\": \\\"What do I like?\\\"},\\n\"\n + \" \\\"output\\\": {\\\"content\\\": \\\"Ned likes watching movies.\\\"}\\n\"\n + \" }],\\n\"\n + \" \\\"messages\\\": [\\n\"\n + \" { \\n\"\n + \" \\\"author\\\": \\\"user\\\",\\n\"\n + \" \\\"content\\\": \\\"Are my favorite movies based on a book series?\\\"\\n\"\n + \" }]\\n\"\n + \"}\";\n String parameters =\n \"{\\n\"\n + \" \\\"temperature\\\": 0.3,\\n\"\n + \" \\\"maxDecodeSteps\\\": 200,\\n\"\n + \" \\\"topP\\\": 0.8,\\n\"\n + \" \\\"topK\\\": 40\\n\"\n + \"}\";\n String project = \"YOUR_PROJECT_ID\";\n String publisher = \"google\";\n String model = \"chat-bison@001\";\n\n predictChatPrompt(instance, parameters, project, publisher, model);\n }\n\n static void predictChatPrompt(\n String instance, String parameters, String project, String publisher, String model)\n throws IOException {\n PredictionServiceSettings predictionServiceSettings =\n PredictionServiceSettings.newBuilder()\n .setEndpoint(\"us-central1-aiplatform.googleapis.com:443\")\n .build();\n\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests.\n try (PredictionServiceClient predictionServiceClient =\n PredictionServiceClient.create(predictionServiceSettings)) {\n String location = \"us-central1\";\n final EndpointName endpointName =\n EndpointName.ofProjectLocationPublisherModelName(project, location, publisher, model);\n\n https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Value.html.Builder instanceValue = https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Value.html.newBuilder();\n https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.util.JsonFormat.html.parser().merge(instance, instanceValue);\n https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ListValue.html instances = new ArrayList\u003c\u003e();\n instances.add(instanceValue.build());\n\n https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Value.html.Builder parameterValueBuilder = https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Value.html.newBuilder();\n https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.util.JsonFormat.html.parser().merge(parameters, parameterValueBuilder);\n https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Value.html parameterValue = parameterValueBuilder.build();\n\n PredictResponse predictResponse =\n predictionServiceClient.predict(endpointName, instances, parameterValue);\n System.out.println(\"Predict Response\");\n }\n }\n }\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=aiplatform)."]]