emdb/cmd/worker/main.go

51 lines
1.2 KiB
Go
Raw Normal View History

2023-12-29 19:10:31 +01:00
package main
import (
2023-12-30 13:09:23 +01:00
"context"
2023-12-29 19:10:31 +01:00
"fmt"
"os"
"ewintr.nl/emdb/client"
2023-12-30 13:09:23 +01:00
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/ollama"
2023-12-29 19:10:31 +01:00
)
func main() {
2023-12-30 13:09:23 +01:00
//movieID := "c313ffa9-1cec-4d37-be6e-a4e18c247a0f" // night train
movieID := "07fb2a59-24ec-442e-aa9e-eb7e4fb002db" // battle royale
2023-12-29 19:10:31 +01:00
2023-12-30 13:09:23 +01:00
emdb := client.NewEMDB(os.Getenv("EMDB_BASE_URL"), os.Getenv("EMDB_API_KEY"))
reviews, err := emdb.GetReviews(movieID)
2023-12-29 19:10:31 +01:00
if err != nil {
fmt.Println(err)
os.Exit(1)
}
2023-12-30 13:09:23 +01:00
llm, err := ollama.New(ollama.WithModel("dolphin-mixtral"))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
ctx := context.Background()
for _, review := range reviews {
fmt.Printf("\nReview: %s\nAnswer:\n", review.Review)
prompt := fmt.Sprintf(`Human: The following is a comment about the movie "Battle Royale":
---%s
---What other movies are referenced in this comment? If you're not sure, just say so. Don't make any other comment. Just give a list of movies if there are any.
Assistant:`, review.Review)
_, err := llm.Call(ctx, prompt,
llms.WithTemperature(0.8),
llms.WithStreamingFunc(func(ctx context.Context, chunk []byte) error {
fmt.Print(string(chunk))
return nil
}),
)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
2023-12-29 19:10:31 +01:00
}