⚠️ Please note that gosk is currently in a very early stage of development. As such, there may be bugs or incomplete features. Your understanding and patience are much appreciated. I warmly welcome any contributions, suggestions, or bug reports to help improve the module.
Go Semantic Kernel (gosk) is a Go module inspired by the Microsoft Semantic Kernel, originally designed to facilitate the integration of OpenAI's API and large language models in C# and Python applications. gosk
extends this functionality to the Go programming language, thereby empowering Go developers to define and utilize AI skills and functions with ease, bringing the power of OpenAI's advanced language models to a broader programming community.
Using prompt engineering, gosk enables developers to define AI skills and functions, which can then be easily utilized within their applications.
See also: https://github.com/microsoft/semantic-kernel
To install the gosk
module, use the following command:
go get github.com/mfmayer/gosk
gosk
defines Generators, Skills and Skill-Functions. Each Skill can have multiple Functions that can use Generators and Prompt Templates to make use of large language models (LLM) like OpenAI's GPT models.
gosk
comes with a few exemplary skills and generators, which can be easily supplemented with your own.
gosk
includes the exemplary fun
skill with the joke
function, which defines two input properties:
- The default input property as joke subject
- An optional
style
input property
The fun function can be used the following way (see also cmd/joke/main.go):
package main
import (
"fmt"
"github.com/mfmayer/gosk"
"github.com/mfmayer/gosk/pkg/gpt"
"github.com/mfmayer/gosk/pkg/llm"
"github.com/mfmayer/gosk/pkg/skills/fun"
)
func main() {
kernel := gosk.NewKernel()
kernel.RegisterGenerators(gpt.Register)
kernel.RegisterSkills(fun.Register)
functions, err := kernel.FindFunctions("fun.joke")
if err != nil {
panic(err)
}
input := llm.NewContent("dinosaur").With("style", "One-Liner, no question")
response, err := kernel.Call(input, functions...)
if err != nil {
panic(err)
}
fmt.Println(response.String())
}
Explanation:
- A new kernel is created and the
gpt
generator andfun
skill are registered with it. - The
fun
skill'sjoke
function is found and returned (with a path annotation<skill>.<function>
). - The function input is created with:
- subject as default input property:
dinosaur
- "style" input property:
One-Liner, no question
- subject as default input property:
- Function is called and response printed.
The resulting joke is printed to the console. E.g.:
"I told my boss I couldn't come to work because a dinosaur was blocking my driveway, but he didn't believe me, guess he thinks it's a Bronto-lie-rus."
classDiagram
class Skill {
%%<<interface>>
+Name string
+Description string
+Plannable bool
+Functions map[string]*Function
}
class Function {
+Name string
+Description string
+Plannable bool
+InputProperties map[string]*Parameter
+Call func(input llm.Content) (output llm.Content, err error)
}
Skill "1" -- "*" Function
%%%%
%% note "From Duck till Zebra"!
%% Animal <|-- Duck
%% note for Duck "can fly\ncan swim\ncan dive\ncan help in debugging"
%% Animal <|-- Fish
%% Animal <|-- Zebra
%% Animal : +int age
%% Animal : +String gender
%% Animal: +isMammal()
%% Animal: +mate()
%% class Duck{
%% +String beakColor
%% +swim()
%% +quack()
%% }
%% class Fish{
%% -int sizeInFeet
%% -canEat()
%% }
%% class Zebra{
%% +bool is_wild
%% +run()
%% }
Contributions to the gosk project are welcome! If you have a bug to report, a feature to suggest, or a patch to submit, please feel free to use the GitHub issue tracker or submit a pull request.
The gosk module is open source software released under the MIT License (like semantic kernel from microsoft). For more details, see the LICENSE file in the repository.