Member-only story
Building an AI Chatbot with Go
Create an AI assistant using Gemini and Websockets.
Chat GPT changed the world when it was released. It spawned new niches, driving the development of innovative courses, platforms, and businesses all centered around the capabilities of generative AI.
I like to use Chat GPT for text analysis, proofreading and code generation. When it comes to generating code, I usually know the code I need ahead of time and prompt Chat GPT until I have the desired output.
In this post, I’ll be building a Go-based web server that enables access to a large language model (LLM) via websocket connection. I’ll name this project “Terminal GPT,” and it will be powered by Gemini AI.
GPT Interface
To start, I’ll need an interface that can manage the lifecycle of a chat session and — most importantly — send user messages to Gemini’s API.
To communicate with the API, I’ll use the following Go package:
github.com/google/generative-ai-go/genai
With the requirements outlined above, here is the code of the interface:
import "github.com/gorilla/websocket"
// GPT interface
type GPT interface {
// Register a client session by ID. Store websocket connection
// so that LLM…