Shows how to verify whether an answer is grounded in a given context
using the Upstage Groundedness Check API.
This example assumes using Upstage; is in scope and apiKey contains your Upstage API key.
1 2 3 4 5 6 7 8 910111213141516171819202122
// Create an authenticated client using your Upstage API key.usingvarclient=newUpstageClient(apiKey);// Define the context (source material) and an answer to verify.// The groundedness check determines whether the answer is supported by the context.varcontext="Upstage is a leading AI company based in South Korea. "+"They develop Solar LLM, a large language model optimized for "+"various natural language processing tasks.";varanswer="Upstage is a South Korean AI company that created Solar LLM.";// Call the `GroundednessCheckAsync` method with the context and answer.// You can optionally specify a model (default is "groundedness-check").varresponse=awaitclient.GroundednessCheck.GroundednessCheckAsync(context:context,answer:answer);// The response includes a boolean `Grounded` field, a confidence `Score`// between 0 and 1, and a `Reason` explaining the determination.Console.WriteLine($"Grounded: {response.Grounded}");Console.WriteLine($"Score: {response.Score}");Console.WriteLine($"Reason: {response.Reason}");