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/

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more