KeyserDSoze / Rystem.OpenAi

.Net wrapper for OpenAI with Dependency injection integration, factory integration: you may inject more than one endpoint, azure integration: you may swap among openai endpoint and any azure endpoint quickly and easily. You can calculate tokens and cost for each request (before the request) and for each response.
MIT License
91 stars 12 forks source link

Keep getting Null reference exception on a simple request call #71

Open mohammad-shadmehr opened 11 months ago

mohammad-shadmehr commented 11 months ago

Describe the bug

I have already set the openai in the start up via dependency injection. I am just trying to make a simple request but keep getting a null reference exception. I can see the _iOpenAi is not null and have no idea if I am missing something in my code?

To Reproduce

just a simple request call

Code snippets

public class ChatGptManager : IChatGptManager
    {
        private readonly IOpenAi _iOpenAi;

        public ChatGptManager(IOpenAi iOpenAi)
        {
            _iOpenAi = iOpenAi;
        }
        public async Task<string> Generate(List<string> input)
        {

            var result = await _iOpenAi.Chat
                .Request(new ChatMessage { Role = ChatRole.User, Content = "Hi there" })
                .WithModel(ChatModelType.Gpt35Turbo)
                .WithTemperature(1)
                .ExecuteAsync();

            return result.ToString();
        }
    }

OS

Windows

.Net version

.Net 7

Library version

1.0.3

Kuubs commented 11 months ago

I get the same. Even when using the Rystem.OpenAi.WebApp from this repo. My only changes: var apiKey = builder.Configuration["OpenAi:ApiKey"]; builder.Services.AddOpenAi(settings => { settings.ApiKey = apiKey; });

And ofcourse added the ApiKey to appsettings

mohammad-shadmehr commented 11 months ago

here is mine in the Startup.cs: services.AddOpenAi(settings => { settings.ApiKey = _appConfiguration["Chat-Gpt:SecretKey"]; });

bartoandras commented 10 months ago

Getting the same error. When will it be fixed?

williamcajina commented 9 months ago

Also getting this erro

taylorchasewhite commented 9 months ago

This is a duplicate of #70.

taylorchasewhite commented 7 months ago

@KeyserDSoze any idea if this (#70 has the technical details) has been addressed? I see there have been a few releases recently, I can do another upgrade and test out if you are unsure.