Shows how to use the Upstage Solar LLM for chat completions.
1 2 3 4 5 6 7 8 9101112131415161718192021222324
// Create an authenticated client using your Upstage API key.usingvarclient=newUpstageClient(apiKey);// Send a simple chat message to the Solar Mini model.// The `CreateChatCompletionAsync` method accepts a model name and a list of messages.varresponse=awaitclient.Chat.CreateChatCompletionAsync(model:"solar-mini",messages:[newChatMessage{Role=ChatMessageRole.System,Content="You are a helpful assistant.",},newChatMessage{Role=ChatMessageRole.User,Content="Hello! What is Upstage?",},]);// The response contains a unique ID, the model used, and a list of choices.// Each choice has a message with the assistant's reply.Console.WriteLine($"Response: {response.Choices[0].Message!.Content}");
Embeddings
Shows how to generate text embeddings using Upstage Solar Embedding models.
1 2 3 4 5 6 7 8 91011121314
// Create an authenticated client using your Upstage API key.usingvarclient=newUpstageClient(apiKey);// Generate an embedding for a text input using the Solar Embedding model.// The `input` parameter accepts a string or an array of strings.varresponse=awaitclient.Embeddings.CreateEmbeddingAsync(model:"solar-embedding-1-large",input:"Upstage is a leading AI company.");// The response contains a list of embedding data objects,// each with a vector of floating-point numbers.Console.WriteLine($"Model: {response.Model}");Console.WriteLine($"Embedding dimensions: {response.Data[0].Embedding!.Count}");
Groundedness Check
Shows how to verify whether an answer is grounded in a given context
using the Upstage Groundedness Check API.
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}");
Translation
Shows how to translate text between languages using Upstage Solar Translation models.
1 2 3 4 5 6 7 8 9101112131415161718
// Create an authenticated client using your Upstage API key.usingvarclient=newUpstageClient(apiKey);// Translate English text to Korean using the Solar translation model.// The `TranslateAsync` method requires the model name, text, source language,// and target language.varresponse=awaitclient.Translation.TranslateAsync(model:"solar-1-mini-translate-enko",text:"Hello, how are you?",sourceLang:"en",targetLang:"ko");// The response contains the translated text along with the detected// source language and the target language.Console.WriteLine($"Translated text: {response.Output.Text}");Console.WriteLine($"Source language: {response.Output.SourceLang}");Console.WriteLine($"Target language: {response.Output.TargetLang}");