DEV Community

Rocky LIU Yan
Rocky LIU Yan

Posted on

2 1

Natural Programming ❤️️ with TypeChat & Semantic Kernel

The age of programming via natural language has come to pass.

Today we use sk and typechat to code a .net sample.

Example 1: Controlling Computers with Natural Language

In this code, OpenAI will provide a snippet of executable code.
Demonstration of creating a directory, writing the string "hello" into a file named b.txt, and then inquiring about the contents of the newly created b.txt file:

Create a directory named "test" in the current directory, within which create a file named b.txt and write the string "hello" into it.

def program(api: IPluginApi):
    step1 = api.get_current_directory()
    step2 = api.concatenate(step1, "/test")
    step3 = api.make_directory(step2)
    step4 = api.concatenate(step2, "/b.txt")
    step5 = api.write_file(step4, "hello")
    return step5
Enter fullscreen mode Exit fullscreen mode

Display the contents of the b.txt file located in the "test" directory.

def program(api: IPluginApi):
    step1 = api.set_current_directory("test")
    step2 = api.read_file("b.txt")
    step3 = api.output(step2)
    return step3
Enter fullscreen mode Exit fullscreen mode

Executing the program will yield the output:

hello
Enter fullscreen mode Exit fullscreen mode

In conclusion, programming control over the computer has been achieved through the use of natural language.

Example 2: Ordering with Natural Language, a cappuccino with added sugar

Feature: Natural language generates JSON

I'll have a cappuccino, and please add sugar.

##YOUR ORDER
{
  "items": [
    {
      "$type": "LatteDrinks",
      "productName": "cappuccino",
      "options": [
        {
          "$type": "Sweetners",
          "optionName": "sugar"
        }
      ],
      "quantity": 1
    }
  ]
}
Success!
Enter fullscreen mode Exit fullscreen mode

It's possible that we could then transmit the resulting JSON to a food delivery API, thereby actualizing the order process.
For an in-depth understanding of how to utilize this feature:

Create AI agents with Semantic Kernel
​learn.microsoft.com/zh-cn/semantic-kernel/overview/

TypeChat
​microsoft.github.io/TypeChat/

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry 🕒

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay