1024programmer Asp.Net The .net platform uses SDK to quickly connect to major language models

The .net platform uses SDK to quickly connect to major language models

The .net platform uses SDK to quickly connect to major language models

.net platform uses SDK to quickly connect to major language models

1. Project Introduction

Recently, when working on the GPT project, I found that the interface specifications and parameters of each platform are different. It is necessary to write multiple interfaces according to different platforms and models, which is quite troublesome. I don’t want to have a rich and convenient AI environment like Python. If c# has one It would be great if the SDK can easily call various platform models. This is the origin of the budding AllInAI.Sharp.API.

So I developed this SDK, package name: [AllInAI.Sharp.API](https://github.com/raokun/AllInAI.Sharp.API.Sample).

AllInAI.Sharp.API is an SDK that calls language models of major platforms, helping users quickly connect to major models. It has integrated OpenAI, chatGLM, Wenxin Qianfan, Tongyi Qianwen, stable-diffusion, etc. It supports setting up reverse proxy and supports streaming interface. AllInAI SDK integrates unified input parameters and output parameters in chat and picture interfaces. Easy to call.

The SDK has been open sourced on nuget, you are welcome to use it.

Currently the SDK uses .net7. If you need support for other versions, please submit an issue in the project.

2. Completed model

  • OpenAI
  • chatGLM
  • Wen Xin Qianfan
  • Tongyi Qianwen
  • stable-diffusion

3.Interface Category

Currently divided into two categories

  • ChatService chat service
  • ImgService image service

4.Usage Example

For usage examples, please refer to the sample project: AllInAI.Sharp.API](https://github.com/raokun/AllInAI.Sharp.API.Sample

1. Set basic configuration:

key — the model’s secret key
BaseUrl — proxy address
AIType — model type, corresponding to the enumeration Enums.AITypeEnum

2. Call interface

1.chat

AuthOption authOption = new AuthOption() { Key = "sk-***", BaseUrl = "https://api.openai.com", AIType = Enums.AITypeEnum  .OpenAi };

 ChatService chatService = new ChatService(authOption);
 CompletionReq completionReq = new CompletionReq();
 List messages = new List();
 messages.Add(new MessageDto() { Role = "user", Content = "Hello!" });
 completionReq.Model = "gpt-3.5-turbo";
 completionReq.Messages = messages;
 CompletionRes completionRes = await chatService.Completion(completionReq);

 

2.image

AuthOption authOption = new AuthOption() {BaseUrl = "http://43.134.164.127:77", AIType = Enums.AITypeEnum.SD };
 ImgService imgService = new ImgService(authOption);
 Txt2ImgReq imgReq = new Txt2ImgReq();
 imgReq.Steps = 20;
 imgReq.Size = "1024x1024";
 imgReq.N = 1;
 imgReq.Prompt = "kitty";
 imgReq.ResponseFormat = "b64_json";
 ImgRes imgRes = await imgService.Txt2Img(imgReq);
 

5.Applications in the project

AllInAI.Sharp.API is used extensively in TerraMours_Gpt. The TerraMours_Gpt project is a multi-model AI application and management system that supports multi-language model chat, multi-model image generation based on chatgpt and SD, and other functions. The management end implements data dashboard, chat record management, role management, picture record management, user management, system configuration, etc.

Currently supported models for configuring APIs: OpenAI, chatGLM, Wenxin Qianfan, Tongyi Qianwen, stable-diffusion.

The project supports rapid deployment and construction based on docker. To build an AI application and management system individually, you only need a docker-compose command.

docker-compose command

image-20231205102937675

If you encounter style problems while reading, please go to your personal blog: https://www.raokun.top

Embrace ChatGPT: https://first.terramours.site

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/811109

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索