using Google.Cloud.AIPlatform.V1;
using System;
using System.Collections.Generic;
using System.Linq;
using Value = Google.Protobuf.WellKnownTypes.Value;
// Text Summarization with a Large Language Model
public class PredictTextSummarizationSample
{
public string PredictTextSummarization(
string projectId = "your-project-id",
string locationId = "us-central1",
string publisher = "google",
string model = "text-bison@001")
{
// Initialize client that will be used to send requests.
// This client only needs to be created once,
// and can be reused for multiple requests.
var client = new PredictionServiceClientBuilder
{
Endpoint = $"{locationId}-aiplatform.googleapis.com"
}.Build();
// Configure the parent resource.
var endpoint = EndpointName.FromProjectLocationPublisherModel(projectId, locationId, publisher, model);
// Initialize request argument(s).
var content = @"
Provide a summary with about two sentences for the following article:
The efficient-market hypothesis (EMH) is a hypothesis in financial
economics that states that asset prices reflect all available
information. A direct implication is that it is impossible to
""beat the market"" consistently on a risk-adjusted basis since market
prices should only react to new information. Because the EMH is
formulated in terms of risk adjustment, it only makes testable
predictions when coupled with a particular model of risk. As a
result, research in financial economics since at least the 1990s has
focused on market anomalies, that is, deviations from specific
models of risk. The idea that financial market returns are difficult
to predict goes back to Bachelier, Mandelbrot, and Samuelson, but
is closely associated with Eugene Fama, in part due to his
influential 1970 review of the theoretical and empirical research.
The EMH provides the basic logic for modern risk-based theories of
asset prices, and frameworks such as consumption-based asset pricing
and intermediary asset pricing can be thought of as the combination
of a model of risk with the EMH. Many decades of empirical research
on return predictability has found mixed evidence. Research in the
1950s and 1960s often found a lack of predictability (e.g. Ball and
Brown 1968; Fama, Fisher, Jensen, and Roll 1969), yet the
1980s-2000s saw an explosion of discovered return predictors (e.g.
Rosenberg, Reid, and Lanstein 1985; Campbell and Shiller 1988;
Jegadeesh and Titman 1993). Since the 2010s, studies have often
found that return predictability has become more elusive, as
predictability fails to work out-of-sample (Goyal and Welch 2008),
or has been weakened by advances in trading technology and investor
learning (Chordia, Subrahmanyam, and Tong 2014; McLean and Pontiff
2016; Martineau 2021).
Summary:";
var instances = new List<Value>
{
Value.ForStruct(new()
{
Fields =
{
["content"] = Value.ForString(content),
}
})
};
var parameters = Value.ForStruct(new()
{
Fields =
{
{ "temperature", new Value { NumberValue = 0.2 } },
{ "maxOutputTokens", new Value { NumberValue = 256 } },
{ "topP", new Value { NumberValue = 0.95 } },
{ "topK", new Value { NumberValue = 40 } }
}
});
// Make the request.
var response = client.Predict(endpoint, instances, parameters);
// Parse and return the content
var responseContent = response.Predictions.First().StructValue.Fields["content"].StringValue;
Console.WriteLine($"Content: {responseContent}");
return responseContent;
}
}