package main
import (
"fmt"
"log"
"github.com/DappierAI/dappier-go"
)
func main() {
// Initialize Dappier client
client, err := dappier.NewDappierApp("your-api-key")
if err != nil {
log.Fatalf("Failed to initialize Dappier client: %v", err)
}
// Example usage of DappierRagAPI
// Parameters:
// - query (string): A natural language query or a URL. If a URL is passed,
// the AI analyzes the page and performs a semantic search query.
// - similarityTopK (int): Number of articles to return (default is 9).
// - ref (string): The domain of the site to fetch recommendations from (e.g., techcrunch.com). optional
// - numArticlesRef (int): Number of guaranteed articles from the specified domain (if ref is provided). optional
// - datamodelID (string): The Data Model ID for the API request.
recommendations, err := client.AIRecommendations("latest tech news", "dm_02hr75e8ate6adr15hjrf3ikol")
if err != nil {
log.Fatalf("Failed to get AI recommendations: %v", err)
}
// Print the results
for _, result := range recommendations.Results {
fmt.Printf("Title: %s\nAuthor: %s\nSite: %s\nURL: %s\n\n", result.Title, result.Author, result.Site, result.URL)
}
// With optional params
recommendations, err = client.AIRecommendations(
"latest tech news",
"dm_02hr75e8ate6adr15hjrf3ikol",
dappier.WithSimilarityTopK(5), // Set custom similarity_top_k
dappier.WithRef("techcrunch.com"), // Set custom ref
dappier.WithNumArticlesRef(5),
)
if err != nil {
log.Fatalf("Failed to get AI recommendations: %v", err)
}
// Print the results
for _, result := range recommendations.Results {
fmt.Printf("Title: %s\nAuthor: %s\nSite: %s\nURL: %s\n\n", result.Title, result.Author, result.Site, result.URL)
}
}