tag:blog.kayhantolga.com,2013:/posts Tolga Kayhan 2024-07-19T12:19:54Z tag:blog.kayhantolga.com,2013:Post/2124473 2024-07-19T12:08:59Z 2024-07-19T12:19:54Z Introducing a New .NET Library for Anthropic's Claude AI Betalgo.Ranul.Anthropic Betalgo.Ranul.Anthropic

Hey there, fellow developers! 👋 I'm excited to share a new tool I've been working on that I think many of you, especially those working with AI in the .NET ecosystem, will find useful.

The Birth of a New Library

As some of you might know, I previously created the Betalgo.OpenAI library for working with OpenAI's API. That experience got me thinking about other AI services, particularly Anthropic's Claude. After mulling over the idea for a while (and getting sidetracked by other projects), I finally decided to dive in and create a .NET library for Anthropic's Claude AI.

What's in a Name?

You might notice that unlike my previous OpenAI library, this one uses a different namespace: Betalgo.Ranul.Anthropic. This is part of a larger project called Ranul-Tinga (more on that in a future post!), which aims to create a universal API for accessing various AI providers.

The Challenges of Building an AI Library

Creating this library came with its share of interesting challenges. Here's a peek into some of the hurdles I encountered and how I approached them:

  1. Documentation Navigation

    Anthropic's documentation is generally good, but like most APIs, it had its nuances. Some information was distributed across different sections, requiring a bit of detective work to piece everything together. It's a common challenge in the fast-moving world of AI development, where keeping documentation perfectly up-to-date is a Herculean task. Who knows, maybe AI will solve this problem for us in the future!

  2. API Differences

    While Anthropic's API shares similarities with OpenAI's, there are notable differences. One major issue I've encountered with some AI APIs is their lack of consideration for strongly typed languages. Anthropic's API fares better in this regard, but there were still some areas that required careful thought to integrate smoothly with .NET's type system.

  3. Future-Proofing

    A significant challenge was figuring out the best way to introduce API fields to developers while keeping the library flexible for potential future changes. It's a delicate balance between providing a robust structure and maintaining adaptability.

  4. Minimalism, Readability, and Runtime Independence

    I set myself the challenge of allowing developers to use the library with minimal lines of code. The goal was to make it easy to read and less daunting to start using. In theory, you can now create a constructor, call the messaging method with a new message request, and print it to the screen in just three lines of code.

    var messageRequest = new MessageRequest {
        Messages = [Message.FromUser("What is the capital of France?")],
        Model = "claude-3-opus-20240229",
        MaxTokens = 100 
    };
    var messageResponse = await anthropicService.Messages.Create(messageRequest);
    if (messageResponse.Successful) Console.WriteLine(messageResponse.ToString());
    

    Moreover, I put a lot of effort into minimizing runtime dependencies. This approach, which will be a key differentiator of the Ranul-Tinga project from other AI frameworks, reduces the reliance on runtime code. It's one of my pet peeves when a project heavily depends on runtime evaluation, so I tried to avoid this as much as possible. The result is a more predictable and easier-to-debug library.

These challenges shaped the development process and ultimately led to some of the unique features of this library. It's been an exciting journey of problem-solving and optimization, always with the end-user - you, the developers - in mind.

The Power of AI in Development

Interestingly, I used my previous project, Mergy, to help create the README file for this library. I'm also planning to use it to generate wiki pages. It's gratifying to see a tool I created becoming useful in my own development process.

What's Next?

Now that the library is ready, the next step is to let developers know it exists. I'm planning to reach out to the Anthropic team – perhaps they'd be interested in including this SDK in their documentation.

Wrapping Up

Creating this library has been an interesting journey, full of challenges but also rewarding insights. I hope it will make working with Anthropic's Claude AI easier for .NET developers.

I'm excited to see what you'll build with this library. Whether you're an AI enthusiast, a seasoned developer, or just getting started with integrating AI into your applications, I hope this tool makes your journey a little smoother.

Give it a try and let me know what you think. Your feedback and real-world use cases will be invaluable as we continue to improve and expand this library.

Happy coding! 🚀
Tolga.

GitHub Repository: Link to the .NET Library for Anthropic Claude repository

]]>
tag:blog.kayhantolga.com,2013:Post/2122336 2024-07-10T18:50:55Z 2024-07-10T18:50:56Z Mergy: A Quick Tool for Claude Projects

Mergy: A Quick Tool for Claude Projects

Hey folks! I wanted to share a project I put together for the Build with Claude contest in June 2024. Anthropic challenged developers to create something using their API in just two weeks, with a chance to win $10k in API credits.

What is Mergy?

Mergy is a browser extension that combines and optimizes GitHub repository contents into a single text file. It's designed to work with Claude, an AI assistant. Here's what it does:

  1. When you visit a GitHub repository, Mergy can fetch all the files.
  2. It combines these files into one text document.
  3. The extension optimizes the content to use fewer tokens, which is important for AI processing.
  4. You can then upload this combined file to Claude Projects.

This tool helps developers quickly give Claude context about an entire codebase, making it easier to work with AI on programming tasks.

The Problem

While working on a .NET SDK for Claude, I kept running into a common issue. Whenever you start a new project or use a new library, Claude doesn't know your codebase. Claude Projects lets you upload code for context, but there were a few annoyances:

  1. Some files are unnecessarily large.
  2. Empty spaces waste valuable tokens.
  3. Manually selecting and optimizing files is tedious.

The Solution

I decided to create Mergy to solve this problem. The idea was to scan a folder, collect relevant files, filter them based on rules, and create a single optimized file for Claude Projects. With Claude's help, I put together a basic console application in about half a day.

Making It More Accessible

The console app worked, but it wasn't very user-friendly. Users would need to clone a project and download an app just to use it. So, I decided to turn Mergy into a browser extension instead. This would make it easier for people to use, regardless of their operating system.

Design and Development

For the extension's look, I tried to match Claude AI's style. I used Midjourney to create some simple icons for settings, sync, and download, with a bit of tweaking in Photoshop. They're not professional-grade, but they do the job.

One interesting aspect of this project was how much I built with Claude's assistance. Almost all of the code was written with Claude's help. I only had to code manually when I hit Claude's usage limit. It felt a bit like going back to the "old school" way of programming.

Creating a Client App: Mergy in Action

I decided to take Mergy a step further by creating a client app. This would allow people to use the knowledge via API instead of just through Claude Projects. And this is where things got really interesting.

Here's the cool part: I used Mergy itself to download knowledge about its own source code, as well as the Betalgo Ranul Anthropic .NET SDK. Then, I asked Claude to create a .NET client app for me based on this knowledge. And you know what? It worked surprisingly well!

This was a real-world test for Mergy, and it held up nicely. It was pretty satisfying to see the tool I built being used to create something new. The fact that Claude could understand the codebase well enough to generate a functional client app was a good indication of the potential of this approach.

I think this was a neat demonstration of Mergy's capabilities. It wasn't just a theoretical tool anymore - I actually needed to use the extension in a real-world scenario, and it delivered. This experience helped validate the concept behind Mergy and showed its practical value in AI-assisted development.

What's Next?

Mergy is now available on GitHub, free and open-source. It's a small project, but it might save you some time when preparing code for Claude Projects or, as I've discovered, for other AI-assisted coding tasks.

This project was an interesting way to explore AI-assisted development. It's far from perfect, but it was a good challenge to work on. If nothing else, it shows how AI tools like Claude can help even in the process of building tools for AI integration.

If you're working with Claude Projects or looking to leverage AI in your development process, give Mergy a try. It might make your workflow a bit smoother. And if you see room for improvement, contributions are always welcome!

Who knows? You might end up using it to build something interesting, just like I did with the client app. The possibilities are pretty exciting.

Wrapping Up

After getting the main functionality working, I made a quick demo video and wrote this blog post.



Github Mergy: betalgo/Mergy (github.com)

Github Mergy Client: betalgo/MergyClient: (github.com)

]]>