From af7866565cdd6b447584da33d86af057f2555b6d Mon Sep 17 00:00:00 2001 From: Simone Vellei Date: Tue, 22 Aug 2023 08:38:52 +0200 Subject: [PATCH] chore: add localai example (#111) --- examples/llm/openai/localai/main.go | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 examples/llm/openai/localai/main.go diff --git a/examples/llm/openai/localai/main.go b/examples/llm/openai/localai/main.go new file mode 100644 index 00000000..322c0ae5 --- /dev/null +++ b/examples/llm/openai/localai/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "context" + "fmt" + + goopenai "github.com/sashabaranov/go-openai" + + "github.com/henomis/lingoose/chat" + "github.com/henomis/lingoose/llm/openai" + "github.com/henomis/lingoose/prompt" +) + +func main() { + + chat := chat.New( + chat.PromptMessage{ + Type: chat.MessageTypeUser, + Prompt: prompt.New("How are you?"), + }, + ) + + customConfig := goopenai.DefaultConfig("") + customConfig.BaseURL = "http://localhost:8080" + customClient := goopenai.NewClientWithConfig(customConfig) + + llm := openai.NewChat().WithClient(customClient).WithModel("ggml-gpt4all-j") + + err := llm.ChatStream(context.Background(), func(output string) { + fmt.Printf("%s", output) + }, chat) + if err != nil { + panic(err) + } + + fmt.Println() + +}