Riassumi i contenuti testuali utilizzando l'IA generativa (IA generativa)
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Riassumi i contenuti testuali utilizzando un modello di testo del publisher.
Esempio di codice
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],[],[],[],null,["# Summarize text content using Generative AI (Generative AI)\n\nSummarize text content using a publisher text 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.v1.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.EndpointName.html;\n import com.google.cloud.aiplatform.v1.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PredictResponse.html;\n import com.google.cloud.aiplatform.v1.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PredictionServiceClient.html;\n import com.google.cloud.aiplatform.v1.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PredictionServiceSettings.html;\n import com.google.protobuf.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.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 // Text Summarization with a Large Language Model\n public class PredictTextSummarizationSample {\n\n public static void main(String[] args) throws IOException {\n // TODO(developer): Replace these variables before running the sample.\n // Designing prompts for text summerization with supported large language models:\n // https://cloud.google.com/vertex-ai/docs/generative-ai/text/summarization-prompts\n String instance =\n \"{ \\\"content\\\": \\\"Background: There is evidence that there have been significant changes \\n\"\n + \"in Amazon rainforest vegetation over the last 21,000 years through the Last \\n\"\n + \"Glacial Maximum (LGM) and subsequent deglaciation. Analyses of sediment \\n\"\n + \"deposits from Amazon basin paleo lakes and from the Amazon Fan indicate that \\n\"\n + \"rainfall in the basin during the LGM was lower than for the present, and this \\n\"\n + \"was almost certainly associated with reduced moist tropical vegetation cover \\n\"\n + \"in the basin. There is debate, however, over how extensive this reduction \\n\"\n + \"was. Some scientists argue that the rainforest was reduced to small, isolated \\n\"\n + \"refugia separated by open forest and grassland; other scientists argue that \\n\"\n + \"the rainforest remained largely intact but extended less far to the north, \\n\"\n + \"south, and east than is seen today. This debate has proved difficult to \\n\"\n + \"resolve because the practical limitations of working in the rainforest mean \\n\"\n + \"that data sampling is biased away from the center of the Amazon basin, and \\n\"\n + \"both explanations are reasonably well supported by the available data.\\n\"\n + \"\\n\"\n + \"Q: What does LGM stands for?\\n\"\n + \"A: Last Glacial Maximum.\\n\"\n + \"\\n\"\n + \"Q: What did the analysis from the sediment deposits indicate?\\n\"\n + \"A: Rainfall in the basin during the LGM was lower than for the present.\\n\"\n + \"\\n\"\n + \"Q: What are some of scientists arguments?\\n\"\n + \"A: The rainforest was reduced to small, isolated refugia separated by open forest\"\n + \" and grassland.\\n\"\n + \"\\n\"\n + \"Q: There have been major changes in Amazon rainforest vegetation over the last how\"\n + \" many years?\\n\"\n + \"A: 21,000.\\n\"\n + \"\\n\"\n + \"Q: What caused changes in the Amazon rainforest vegetation?\\n\"\n + \"A: The Last Glacial Maximum (LGM) and subsequent deglaciation\\n\"\n + \"\\n\"\n + \"Q: What has been analyzed to compare Amazon rainfall in the past and present?\\n\"\n + \"A: Sediment deposits.\\n\"\n + \"\\n\"\n + \"Q: What has the lower rainfall in the Amazon during the LGM been attributed to?\\n\"\n + \"A:\\\"}\";\n String parameters =\n \"{\\n\"\n + \" \\\"temperature\\\": 0,\\n\"\n + \" \\\"maxOutputTokens\\\": 32,\\n\"\n + \" \\\"topP\\\": 0,\\n\"\n + \" \\\"topK\\\": 1\\n\"\n + \"}\";\n String project = \"YOUR_PROJECT_ID\";\n String location = \"us-central1\";\n String publisher = \"google\";\n String model = \"text-bison@001\";\n\n predictTextSummarization(instance, parameters, project, location, publisher, model);\n }\n\n // Get summarization from a supported text model\n public static void predictTextSummarization(\n String instance,\n String parameters,\n String project,\n String location,\n String publisher,\n String model)\n throws IOException {\n String endpoint = String.format(\"%s-aiplatform.googleapis.com:443\", location);\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PredictionServiceSettings.html predictionServiceSettings =\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PredictionServiceSettings.html.newBuilder()\n .setEndpoint(endpoint)\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 (https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PredictionServiceClient.html predictionServiceClient =\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PredictionServiceClient.html.create(predictionServiceSettings)) {\n final https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.EndpointName.html endpointName =\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.EndpointName.html.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.EndpointName.html#com_google_cloud_aiplatform_v1_EndpointName_ofProjectLocationPublisherModelName_java_lang_String_java_lang_String_java_lang_String_java_lang_String_(project, location, publisher, model);\n\n // Use Value.Builder to convert instance to a dynamically typed value that can be\n // processed by the service.\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.Value.html.Builder instanceValue = https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.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 // Use Value.Builder to convert parameter to a dynamically typed value that can be\n // processed by the service.\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.Value.html.Builder parameterValueBuilder = https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.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/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.Value.html parameterValue = parameterValueBuilder.build();\n\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PredictResponse.html predictResponse =\n predictionServiceClient.predict(endpointName, instances, parameterValue);\n System.out.println(\"Predict Response\");\n System.out.println(predictResponse);\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)."]]