C
C#5mo ago
weasy

In my code, it says I have a null parameter, this is my first bit of code, Where am I going wrong?

My first code ever. using Azure; using Azure.AI.OpenAI; using System; using static System.Environment; internal class Program { public static string SetEnvironmentVariables { get; private set; } private static void Main(string[] args) { string endpoint = "https://api.openai.com/v1"; string key = GetEnvironmentVariable("sk-key"); OpenAIClient client = new OpenAIClient(new Uri(endpoint), new AzureKeyCredential(key)); CompletionsOptions completionsOptions = new() { DeploymentName = "gpt-35-turbo-instruct", Prompts = { "When was Microsoft founded?" }, }; Response<Completions> completionsResponse = client.GetCompletions(completionsOptions); string completion = completionsResponse.Value.Choices[0].Text; Console.WriteLine($"Chatbot: {completion}"); } }
7 Replies
Angius
Angius5mo ago
What is null there?
Denis
Denis5mo ago
Could share the complete error message?
weasy
weasy5mo ago
System.ArgumentNullException: 'Value cannot be null. (Parameter 'uriString')'
Angius
Angius5mo ago
Which line?
weasy
weasy5mo ago
says 17 , but when I look at 15 where it tries to call endpoint and key it says null
Angius
Angius5mo ago
Are you sure GetEnvironmentVariable() doesn't return null? Use the debugger to check, ideally $debug
MODiX
MODiX5mo ago
Tutorial: Debug C# code and inspect data - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
Want results from more Discord servers?
Add your server
More Posts