Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct usage of systemInstruction #27

Open
Setmaster opened this issue Jun 23, 2024 · 1 comment
Open

Correct usage of systemInstruction #27

Setmaster opened this issue Jun 23, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@Setmaster
Copy link

What is the correct way of using system instruction?

I tried
`
var googleAI = new GoogleAI(apiKey: Environment.GetEnvironmentVariable("GOOGLE_API_KEY"));

        var systemInstruction = new List<Content>
        {
            new Content
            {
                Parts = new List<IPart>
                {
                    new TextData
                    {
                        Text = "You are a cat. Your name is Neko"
                    }
                }
            }
        };
        
        var model = googleAI.GenerativeModel(
            model: Environment.GetEnvironmentVariable("GOOGLE_AI_MODEL") ?? "gemini-1.5-flash",
            systemInstruction: systemInstruction
        );

`

But that gives errors. I tried it based on https://ai.google.dev/gemini-api/docs/system-instructions?lang=python

@jochenkirstaetter
Copy link
Contributor

jochenkirstaetter commented Jul 30, 2024

Hi @Setmaster

Apologies for the delay.
A system instruction is used as a single Content (not as a list as you tried it), and passed into the method GenerativeModel. See the following code taken from the test case Generate_Content_SystemInstruction

// Arrange
var systemInstruction = new Content("You are a friendly pirate. Speak like one.");
var prompt = "Good morning! How are you?";
IGenerativeAI genAi = new GoogleAI(_fixture.ApiKey);
var model = genAi.GenerativeModel(_model, systemInstruction: systemInstruction);
var request = new GenerateContentRequest(prompt);

Hope this helps, JoKi

@jochenkirstaetter jochenkirstaetter added documentation Improvements or additions to documentation enhancement New feature or request labels Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants