LangSharp 1.0.18

dotnet add package LangSharp --version 1.0.18
                    
NuGet\Install-Package LangSharp -Version 1.0.18
                    
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="LangSharp" Version="1.0.18" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LangSharp" Version="1.0.18" />
                    
Directory.Packages.props
<PackageReference Include="LangSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LangSharp --version 1.0.18
                    
#r "nuget: LangSharp, 1.0.18"
                    
#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.
#addin nuget:?package=LangSharp&version=1.0.18
                    
Install LangSharp as a Cake Addin
#tool nuget:?package=LangSharp&version=1.0.18
                    
Install LangSharp as a Cake Tool

LangSharp SDK

LangSharp SDK is a .NET 8 library that leverages Python.NET to communicate with AI providers, utilizing powerful Python resources such as LangChain. This SDK provides a robust framework for executing Python commands and scripts within a .NET environment, enabling seamless integration with various AI services.

Table of Contents

Introduction

LangSharp SDK is designed to bridge the gap between .NET applications and Python's extensive ecosystem of AI tools. By using Python.NET, this SDK allows .NET developers to harness the power of Python libraries such as LangChain, enabling advanced AI functionalities within their .NET applications.

Features

  • AI Provider Support: Communicate with AI providers like OpenAI using Python scripts.
  • Chain Requests: Create chains through Python to make requests to AI providers.

Getting Started

Installation

  1. Install the LangSharp SDK:
   dotnet add package LangSharp.SDK

Configuration

Configure the LangSharp SDK using the builder pattern in your Program.cs:

using LangSharp.Core.Configuration;
using LangSharp.Core.Enums;
using LangSharp.MicrosoftExtensionsDI;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);

// Building the SDK configuration using the LangSharpConfigurationBuilder
var sdkConfiguration = new LangSharpConfigurationBuilder()
    .SetAIProvider(AIProviderType.OpenAI)
    .SetModel("gpt-4o-mini")
    .SetApiKey("your-openai-api-key")
    .SetDatabaseUri("your-database-uri") // Optional
    .Build();

// Adding the services and the SDK configuration
builder.Services.AddLangSharp(sdkConfiguration);

var app = builder.Build();

app.Run();

Usage

Executing Queries

To execute a database query using the LangSharp SDK, you can ask a question about the table:

using LangSharp.Core.Interfaces.Services;

var service = app.Services.GetService<ILangSharpService>();
string queryResult = await service.ExecuteDatabaseQueryAsync("What are the names of all users in the users table?");
Console.WriteLine(queryResult);

Calling AI Cloud

To call an AI cloud service using the LangSharp SDK:

using LangSharp.Core.Interfaces.Services;

var service = app.Services.GetService<ILangSharpService>();
string aiResponse = await service.CallAIChatAsync("What is the weather like today?");
Console.WriteLine(aiResponse);

Running in Docker Containers

To run the LangSharp SDK in a Docker container, ensure Python and required dependencies are properly configured. Below are examples for Linux and Windows containers.

Linux

Install Python 3.11.7 and development headers:

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER root
WORKDIR /app

# Install Python 3.11 and dependencies
RUN apt update && \
    apt install -y \
    python3.11 \
    python3.11-dev \
    python3-pip \
    libpython3.11-dev \
    && rm -rf /var/lib/apt/lists/*

Windows

Copy the Python package from the global NuGet cache into the publish folder:

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./LangSharp.Examples.AspNetCore.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
RUN mkdir -p /app/publish/root/.nuget/packages && \
    cp -r /root/.nuget/packages/python /app/publish/root/.nuget/packages/

?? Note: This is required because the default NuGet global packages path (/root/.nuget/packages) is not available at runtime. Copying it ensures that Python.NET can locate the Python package during execution.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Product Compatible and additional computed target framework versions.
.NET 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on LangSharp:

Package Downloads
LangSharp.Examples.AspNetCore

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.18 0 5/13/2025
1.0.17 0 5/13/2025
1.0.16 0 5/12/2025
1.0.15 109 5/8/2025
1.0.14 125 5/2/2025
1.0.13 123 5/2/2025
1.0.12 130 5/2/2025
1.0.11 132 5/2/2025
1.0.10 134 5/1/2025
1.0.9 124 5/1/2025
1.0.8 129 5/1/2025
1.0.7 124 5/1/2025
1.0.6 132 5/1/2025
1.0.4 129 5/1/2025
1.0.3 129 5/1/2025
1.0.2 125 5/1/2025
1.0.1 131 5/1/2025
1.0.0 127 5/1/2025