-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Open
Description
I tried to follow the steps from this link with a little tweak: https://tmc.github.io/langchaingo/docs/tutorials/basic-chat-app#step-6-add-a-conversation-chain
But it didn't seems to remember from the memory.
package main
import (
"bufio"
"context"
"fmt"
"log"
"os"
"strings"
"github.com/tmc/langchaingo/chains"
"github.com/tmc/langchaingo/llms/openai"
"github.com/tmc/langchaingo/memory"
)
func main() {
// Initialize LLM
llm, err := openai.New(
openai.WithBaseURL("http://localhost:11434/v1"), // ollama's OpenAI-compatible API
openai.WithToken("token"),
openai.WithModel("gemma3:1b-it-qat"),
)
if err != nil {
log.Fatal(err)
}
// Create conversation memory
chatMemory := memory.NewConversationBuffer()
// Create conversation chain
// The built-in conversation chain includes a default prompt template
// and handles memory automatically
conversationChain := chains.NewConversation(llm, chatMemory)
ctx := context.Background()
reader := bufio.NewReader(os.Stdin)
fmt.Println("Advanced Chat Application (type 'quit' to exit)")
fmt.Println("----------------------------------------")
for {
fmt.Print("You: ")
input, _ := reader.ReadString('\n')
input = strings.TrimSpace(input)
if input == "quit" {
break
}
// Run the chain with the input
result, err := chains.Run(ctx, conversationChain, input)
if err != nil {
fmt.Printf("Error: %v\n", err)
continue
}
fmt.Printf("AI: %s\n\n", result)
}
fmt.Println("Goodbye!")
}Demo result (shows it doesn't have any idea what's my name after I told it):
Advanced Chat Application (type 'quit' to exit)
----------------------------------------
You: hello, my name is yasa
AI: Hello yasa! It’s nice to meet you. I’m glad you’re here. 😊
You: what is my name?
AI: I’m sorry, I don’t have access to that information. I’m still under development and learning to access personal details. 😊
Metadata
Metadata
Assignees
Labels
No labels