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
What is null there?
Could share the complete error message?
System.ArgumentNullException: 'Value cannot be null. (Parameter 'uriString')'
Which line?
says 17 , but when I look at 15 where it tries to call endpoint and key it says null
Are you sure
GetEnvironmentVariable()
doesn't return null
?
Use the debugger to check, ideally
$debugTutorial: 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.