IcedMango.DifyAi
1.1.5
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package IcedMango.DifyAi --version 1.1.5
NuGet\Install-Package IcedMango.DifyAi -Version 1.1.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IcedMango.DifyAi" Version="1.1.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IcedMango.DifyAi --version 1.1.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: IcedMango.DifyAi, 1.1.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install IcedMango.DifyAi as a Cake Addin #addin nuget:?package=IcedMango.DifyAi&version=1.1.5 // Install IcedMango.DifyAi as a Cake Tool #tool nuget:?package=IcedMango.DifyAi&version=1.1.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Dify C# SDK
Introduction
A Dify C# SDK for interacting with Dify's APIs.
Supports Chat/Knowledge Base APIs.
If you encounter any issues, feel free to raise an Issue or PR.
Quick Start
Installation
Install-Package IcedMango.DifyAi
Service Registration:
Startup.cs
// Startup.cs
using DifyAi.ServiceExtension;
public void ConfigureServices(IServiceCollection services)
{
...other code
// Register services
services.AddDifyAiServices();
}
Configuration File (appsettings.json)
The following configurations must be filled in
Here is a sample configuration that you need to modify according to your actual situation.
Note:
- BaseUrl: [Required] The URL of the Dify API instance. Must end with a
/
. - BotApiKey: [Required] Your bot API key.
- DatasetApiKey: Your knowledge base API key.
- Proxy: Proxy settings, supports http, https, socks5. If not needed, leave it blank.
{
"DifyAi": {
"BaseUrl": "https://example.com/v1/",
"BotApiKey": "app-your-bot-key",
"DatasetApiKey": "dataset-your-dataset-key",
"Proxy": "socks5://127.0.0.1:8889"
}
}
Usage
using DifyAi.Dto.ParamDto;
using DifyAi.Services;
namespace TestDifyAi;
public class TestClass
{
// Chat bot public API
private readonly IDifyAiChatServices _difyAiChatServices;
// Knowledge base public API
private readonly IDifyAiDatasetServices _difyAiDatasetServices;
public TestClass(IDifyAiChatServices difyAiChatServices, IDifyAiDatasetServices difyAiDatasetServices)
{
_difyAiChatServices = difyAiChatServices;
_difyAiDatasetServices = difyAiDatasetServices;
}
// Chat bot
public async Task<string> TestCompletion()
{
var res = await _difyAiChatServices.CreateChatCompletionBlockModeAsync(new Dify_CreateChatCompletionParamDto()
{
Query = "Who are you?",
User = "IcedMango",
ConversationId = string.Empty
});
if (res.Success)
{
return res.Data.Answer;
}
return "Error";
}
// Add knowledge base document
public async Task<bool> AddDatasetDocAsync()
{
var difyAiDto = new Dify_CreateDocumentByTextParamDto()
{
DatasetId = "your-dataset-id",
Text = "who are you? Why are you here? I am a bot.",
Name = "About me",
IsAutomaticProcess = true,
EnableHighQualityIndex = true
};
var res = await _difyAiDatasetServices.CreateDocumentByTextAsync(difyAiDto);
if (res.Success)
{
var docInfo = res.Data.Document;
return true;
}
return false;
}
}
API Documentation
TODO
- Unit Tests
- Message Completion Streaming Mode
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributor License Agreement (CLA)
By submitting a PR, you agree to license your contributions to the project owner under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Mapster (>= 7.4.0)
- Mapster.Core (>= 1.2.1)
- Microsoft.Extensions.Configuration (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection (>= 6.0.0)
- Microsoft.Extensions.Http (>= 6.0.0)
- MimeMapping (>= 3.0.1)
- Newtonsoft.Json (>= 13.0.3)
-
net7.0
- Mapster (>= 7.4.0)
- Mapster.Core (>= 1.2.1)
- Microsoft.Extensions.Configuration (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- Microsoft.Extensions.Http (>= 7.0.0)
- MimeMapping (>= 3.0.1)
- Newtonsoft.Json (>= 13.0.3)
-
net8.0
- Mapster (>= 7.4.0)
- Mapster.Core (>= 1.2.1)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- MimeMapping (>= 3.0.1)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.