Giter Site home page Giter Site logo

lofcz / openaing Goto Github PK

View Code? Open in Web Editor NEW
22.0 5.0 8.0 530 KB

A simple C# / .NET library to use with OpenAI's API, including GPT-4 Turbo, Assistants, DALL·E 3, etc. Supports commercial and self hosted API providers such as OpenAI, Azure OpenAI, KoboldCpp, LocalAI and others.

License: MIT License

C# 100.00%
csharp-library koboldcpp llamacpp openai openai-api ai api-proxy assistants chatgpt gpt-35-turbo

openaing's Introduction

OpenAI

.NET SDK for accessing the OpenAI Compatible APIs such as GPT-4 (Vision), Assistants and DALL-E 3

OpenAiNextGeneration is a simple .NET library to use with various OpenAI compatible providers, such as OpenAI, Azure OpenAI, and KoboldCpp ( v1.45.2+). Supports features such as function calling in conjunction with streaming, caches its own HttpClients.

Supported features compared to OpenAI-API-dotnet:

  • Assistants, threads, and messages support.
  • Includes new models.
  • Parallel function calling.
  • Improved memory usage, and function calling in conjunction with streaming.
  • Manages its pool of HttpClients.
  • Improved credentials passing.
  • Supports OpenAI-compatible API providers, such as KoboldCpp.
  • Improved Azure OpenAI integration.
  • Nullability annotations.
  • Calls are guaranteed not to throw, full response is included in the call result. (Fully supported in 3.0+)
  • Actively maintained, backed by a company I work for.

Features scheduled for open-sourcing:

  • High-level plugin API.
  • Approximate token counting for streaming & function calling.

⚡Getting Started

Install the library via NuGet:

Install-Package OpenAiNg

🔮 Quick Inference

var api = new OpenAiNg.OpenAiApi("YOUR_API_KEY");
var result = await api.Completions.GetCompletion("One Two Three One Two");
Console.WriteLine(result);
// should print something starting with "Three"

📖 Readme

Requirements

Unlike the original library, OpenAiNg supports only .NET Core >= 6.0, if you need .NET Standard 2.0 /.NET Framework support, please use OpenAI-API-DotNet.

Getting started

Install from NuGet

Install package OpenAiNg from Nuget. Here's how via the command line:

Install-Package OpenAiNg

Authentication

Pass keys directly to ApiAuthentication(string key) constructor.

You use the APIAuthentication when you initialize the API as shown:

// for example
var api = new OpenAiApi("YOUR_API_KEY"); // shorthand
// or
var api = new OpenAiApi(new APIAuthentication("YOUR_API_KEY")); // create object manually

You may optionally include an OpenAi Organization if multiple Organizations are under one account.

// for example
var api = new OpenAiApi(new ApiAuthentication("YOUR_API_KEY", "org-yourOrgHere"));

Documentation

Every single class, method, and property has extensive XML documentation, so it should show up automatically in IntelliSense. That combined with the official OpenAI documentation should be enough to get started. Feel free to open an issue here if you have any questions.

License

This library is licensed under MIT license.

openaing's People

Contributors

anetakahle avatar efimovnikita avatar lofcz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

openaing's Issues

Cannot use a base64 image string when talking with GPT4 Vision

Hey,

I have a base64 encoded image string I want to pass to ChatGPT which I understand is valid, but this library only allows a URL. In my use case this isn't a possibility as the images are not publically accessible.

Can the ChatImage type be extended to allow base64 images?

Thanks!

Have you considered using HTTP/2 for the EndpointClient?

I see that the endpoint client sets MaxConnectionsPerServer and PooledConnectionLifetime to help control connection management, but my understanding is that leveraging HTTP/2 (or higher) can also help with this problem by multiplexing connections:

HttpClient EndpointClient = new(new SocketsHttpHandler
{
	MaxConnectionsPerServer = 10000,
	PooledConnectionLifetime = TimeSpan.FromMinutes(2)
})
{
	Timeout = TimeSpan.FromSeconds(600),
	DefaultRequestVersion = new(2, 0) // default to higher version
};

I'm curious whether you've found a reason to be using 1.1 instead?

Should functionCallHandler in GetResponseFromChatbotAsyncWithFunctions return a `List<FunctionResult>`?

Right now the handler is defined as Func<List<FunctionCall>, Task<FunctionResult?>>. This implies that a single FunctionResult can capture the results of multiple functions. However, I can't see how to do that via the API. I would have expected something like this:

Func<List<FunctionCall>, Task<List<FunctionResult>>>

That way if there are N calls I can return N results. Am I misunderstanding the intended usage pattern?

ResponseFormat type

I'm surprised that ChatRequest.ResponseFormat is type ChatRequestResponseFormats instead of ChatRequestResponseFormatTypes. Can you explain what I'm missing or a cleaner way to do it?

e.g.:

wanting to do:

    ResponseFormat = ChatRequestResponseFormatTypes.Text,

instead of:

var textType = new ChatRequestResponseFormats();
textType.Type = ChatRequestResponseFormatTypes.Text;
...
    ResponseFormat = textType,

(actually I am swapping between text and json but that's not relevant for this example)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.