Skip to content

abhirockzz/cosmosdb-chat-history-langchaingo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Azure Cosmos DB Chat History implementation for langchaingo

This package provides an Azure Cosmos DB NoSQL API based implementation for chat history in langchaingo using Go SDK for Azure Cosmos DB.

Below is an example of using Azure Cosmos DB chat history with a LLMChain:

// Create a chat history instance
cosmosChatHistory, err := cosmosdb.NewCosmosDBChatMessageHistory(cosmosClient, databaseName, containerName, req.SessionID, req.UserID)
if err != nil {
	log.Printf("Error creating chat history: %v", err)
	sendErrorResponse(w, "Failed to create chat session", http.StatusInternalServerError)
	return
}

// Create a memory with the chat history
chatMemory := memory.NewConversationBuffer(
	memory.WithMemoryKey("chat_history"),
	memory.WithChatHistory(cosmosChatHistory),
)

// Create an LLM chain
chain := chains.LLMChain{
	Prompt:       promptsTemplate,
	LLM:          llm,
	Memory:       chatMemory,
	OutputParser: outputparser.NewSimple(),
	OutputKey:    "text",
}

Check out the blog post Implementing Chat History for AI Applications Using Azure Cosmos DB Go SDK and the sample chatbot application that demonstrates how to use this package.

App

Run test cases

This repository includes simple test cases for the chat history component. It demonstrates an example of how to use the Azure Cosmos DB Linux-based emulator (in preview at the time of writing) for integration tests with Testcontainers for Go.

To run the tests for the Azure Cosmos DB chat history component, use the following command:

go test -v github.com/abhirockzz/cosmosdb-chat-history-langchaingo/cosmosdb

About

Chat history implementation for Azure Cosmos DB NoSQL API using langchaingo and the Go SDK for Azure Cosmos DB.

Topics

Resources

Stars

Watchers

Forks

Languages