Add DuckDuckGo support and refactor caching system
Introduced DuckDuckGo as a new search provider alongside Google. Implemented a flexible caching system with in-memory, file-based, and no-op cache options to improve modularity. Updated dependencies and revised the project structure for improved maintainability.
This commit is contained in:
		| @@ -5,13 +5,15 @@ import ( | ||||
| 	"answer/pkg/cache" | ||||
| 	"answer/pkg/search" | ||||
| 	"context" | ||||
| 	gollm "gitea.stevedudenhoeffer.com/steve/go-llm" | ||||
| 	"github.com/joho/godotenv" | ||||
| 	"github.com/urfave/cli" | ||||
| 	"log/slog" | ||||
| 	"os" | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/joho/godotenv" | ||||
| 	"github.com/urfave/cli" | ||||
|  | ||||
| 	gollm "gitea.stevedudenhoeffer.com/steve/go-llm" | ||||
| ) | ||||
|  | ||||
| func getKey(key string, env string) string { | ||||
| @@ -57,13 +59,13 @@ func main() { | ||||
|  | ||||
| 			&cli.StringFlag{ | ||||
| 				Name:  "search-provider", | ||||
| 				Value: "google", | ||||
| 				Value: "duckduckgo", | ||||
| 				Usage: "search provider to use for searching the web", | ||||
| 			}, | ||||
|  | ||||
| 			&cli.StringFlag{ | ||||
| 				Name:  "cache-provider", | ||||
| 				Value: "memory", | ||||
| 				Value: "file", | ||||
| 				Usage: "cache provider to use for caching search results", | ||||
| 			}, | ||||
| 		}, | ||||
| @@ -111,6 +113,13 @@ func main() { | ||||
| 			case "google": | ||||
| 				question.Search = search.Google{Cache: question.Cache} | ||||
|  | ||||
| 			case "duckduckgo": | ||||
| 				var err error | ||||
| 				question.Search, err = search.NewDuckDuckGo(question.Cache) | ||||
| 				if err != nil { | ||||
| 					panic("failed to create duckduckgo search: " + err.Error()) | ||||
| 				} | ||||
|  | ||||
| 			default: | ||||
| 				panic("unknown search provider") | ||||
| 			} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user