Skip to content

Upstage

Nuget package dotnet License: MIT Discord

Features 🔥

  • Fully generated C# SDK based on official Upstage OpenAPI specification using AutoSDK
  • Same day update to support new features
  • Updated and supported automatically if there are no breaking changes
  • All modern .NET features - nullability, trimming, NativeAOT, etc.
  • Support .Net Framework/.Net Standard 2.0

Usage

1
2
3
using Upstage;

using var client = new UpstageClient(apiKey);

Chat Completion

Shows how to use the Upstage Solar LLM for chat completions.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Create an authenticated client using your Upstage API key.
using var client = new UpstageClient(apiKey);

// Send a simple chat message to the Solar Mini model.
// The `CreateChatCompletionAsync` method accepts a model name and a list of messages.
var response = await client.Chat.CreateChatCompletionAsync(
    model: "solar-mini",
    messages: [
        new ChatMessage
        {
            Role = ChatMessageRole.System,
            Content = "You are a helpful assistant.",
        },
        new ChatMessage
        {
            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
 9
10
11
12
13
14
// Create an authenticated client using your Upstage API key.
using var client = new UpstageClient(apiKey);

// Generate an embedding for a text input using the Solar Embedding model.
// The `input` parameter accepts a string or an array of strings.
var response = await client.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
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Create an authenticated client using your Upstage API key.
using var client = new UpstageClient(apiKey);

// Define the context (source material) and an answer to verify.
// The groundedness check determines whether the answer is supported by the context.
var context = "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.";
var answer = "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").
var response = await client.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
 9
10
11
12
13
14
15
16
17
18
// Create an authenticated client using your Upstage API key.
using var client = new UpstageClient(apiKey);

// Translate English text to Korean using the Solar translation model.
// The `TranslateAsync` method requires the model name, text, source language,
// and target language.
var response = await client.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}");

Support

Priority place for bugs: https://github.com/tryAGI/Upstage/issues
Priority place for ideas and general questions: https://github.com/tryAGI/Upstage/discussions
Discord: https://discord.gg/Ca2xhfBf3v

Acknowledgments

JetBrains logo

This project is supported by JetBrains through the Open Source Support Program.