C#, AI, Python: which tools for which tasks?

C#, AI, Python: which tools for which tasks?
A developer discovering he needs to learn Python. Be brave, man !

The initial fantasy

Having been developing applications in C# and .NET for some time, it seemed a good idea to keep the same technical stack and use my knowledge to start developing applications involving AI and LLMs.

After all, Microsoft provides libraries to manipulate embedding vectors, and there are numerous functions and structures to facilitate access to LLMs. And then, too, Microsoft has invested money in OpenAI, so that's got to help, right?

... and reality

I believed in it. I've tried it. I spent time rewriting pieces of code to manage my embeddings, to call my local LM Studio instances and parse the results.

At first, I thought: there's no way I'm using Python, come on! .NET is a very solid stack, it's always a pleasure to develop with it, and programming in Python when you're used to very structured languages can become a challenge...

But here's the thing.

What I hadn't taken into account was the incredible ecosystem surrounding AI - almost exclusively in Python.

Why is this? People use this language for its ability to iterate very quickly, to test via Jupyter Notebook, to try things out and then make them operational in a very short time.

The libraries are available in Python. The players, who come from data science and don't necessarily know anything other than Python, are building additional bricks in this ecosystem.

Everything is moving very fast in AI, and Python keeps the same pace.

A fast-moving ecosystem

So, when I started running my LLM-based search system locally via LM Studio (with Microsoft of course pushing the use of Azure, a lot of things had to be coded by hand), I wanted to try to chain processes, as with LangChain...

Which is easier said than done.

And as I couldn't find any LangChain in .NET, I had to fiddle around... Only to realize that I was missing other tools, that matplotlib was pretty damn interesting for quickly generating graphs, that using a Vector base was nice but not obvious in C#...

In short, I came back to the good old common sense: to each task its tool.

So, how do we go about it?

So, back to an old-fashioned but still relevant concept: the separation of responsibilities.

Since Visual Studio is so flexible, I simply created a Python project to host all my AI needs. This project is a REST web service; using FastAPI (https://fastapi.tiangolo.com/), GET and POST methods were quickly set up to authorize processing on the LLM part.

As for my client Web application, it's in a separate C# and Blazor project, and it calls my Python REST service; it lets me develop much faster.

Final point

My 2 cents : use the right tool for the job. There's always a way to make these different technologies communicate in the end, and you'll love the effective separation of responsibilities.

I don't think there's anything better than Python for AI these days; it may require relearning a language, but it's always worth it.

Another bonus: the day you work with a data scientist, he'll be able to be productive straight away, without having to learn a new technology that doesn't necessarily interest him...