一、計畫介紹
最近,在 做GPT計畫時,發現各個平台的介面規範和參數不同,需要根據不同平台和模型寫多種介面,比較麻煩,不想Python那樣有豐富和方便的AI環境, 如果c#有一個SDK可以方便呼叫各種平台模型就好了,這是AllInAI.Sharp.API萌芽的起源。
於是開發了這個SDK,包名:AllInAI.Sharp.API:https://github.com/raokun/AllInAI.Sharp.API.Sample。
AllInAI.Sharp.API一款呼叫各大平台語言模型的SDK,能幫助使用者快速對接各大模型。
已整合OpenAI,chatGLM,文心千帆,同義千問,stable-diffusion 等 支持設定反向代理,支持流式介面 AllInAI SDK 在聊天和圖片介面中整合統一的入參和出參,方便呼叫。
SDK已開源在nuget上,歡迎使用。
目前sdk使用 .NET 7 如需其他版本支持請在計畫中提issue。
二、已完成模型
OpenAI
chatGLM
文心千帆
同義千問
stable-diffusion
三、介面分類
目前分為兩類
ChatService 聊天服務
ImgService 圖片服務
四、使用 範例
使用範例可參考範例計畫:AllInAI.Sharp.API](https://github.com/raokun/AllInAI.Sharp.API.Sample
1、設定基礎配置
key -- 模型的秘鑰key
BaseUrl -- 代理地址
AIType -- 模型型別,對應列舉Enums.AITypeEnum
2、呼叫介面
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<MessageDto> messages = new List<MessageDto>();
messages.Add(new MessageDto() { Role = "user", Content = "Hello!" });
completionReq.Model = "gpt-3.5-turbo";
completionReq.Messages = messages;
CompletionRes completionRes = await chatService.Completion(completionReq);
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);
五、計畫中的套用
AllInAI.Sharp.API 已在 TerraMours_Gpt 中廣泛使用。
TerraMours_Gpt 計畫是一個多模型的AI套用和管理系統,支持多語言模型聊天、基於chatgpt和SD的多模型圖片生成等功能。
管理端實作數據看板、聊天記錄管理,角色管理,圖片記錄管理、使用者管理、系統設定等。
目前已支持配置api的模型:OpenAI,chatGLM,文心千帆,同義千問,stable-diffusion。
計畫支持基於docker的快速部署搭建。個人搭建AI套用和管理系統只需一段docker-compose命令。
docker-compose命令
擁抱ChatGPT:https://first.terramours.site
轉自:raokun
連結:cnblogs.com/raok/p/17876755.html