fix next no titles handler
This commit is contained in:
parent
71de282ec4
commit
bf9f6f3cd1
|
@ -208,6 +208,34 @@ func (e *EMDB) GetNextUnratedReview() (moviestore.Review, error) {
|
||||||
return review, nil
|
return review, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *EMDB) GetNextNoTitlesReview() (moviestore.Review, error) {
|
||||||
|
url := fmt.Sprintf("%s/review/no-titles/next", e.baseURL)
|
||||||
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return moviestore.Review{}, err
|
||||||
|
}
|
||||||
|
req.Header.Add("Authorization", e.apiKey)
|
||||||
|
|
||||||
|
resp, err := e.c.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return moviestore.Review{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return moviestore.Review{}, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
var review moviestore.Review
|
||||||
|
if err := json.Unmarshal(body, &review); err != nil {
|
||||||
|
return moviestore.Review{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return review, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (e *EMDB) UpdateReview(review moviestore.Review) error {
|
func (e *EMDB) UpdateReview(review moviestore.Review) error {
|
||||||
body, err := json.Marshal(review)
|
body, err := json.Marshal(review)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -36,7 +36,7 @@ func (reviewAPI *ReviewAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
case r.Method == http.MethodGet && subPath == "no-titles" && subSubPath == "":
|
case r.Method == http.MethodGet && subPath == "no-titles" && subSubPath == "":
|
||||||
reviewAPI.ListNoTitles(w, r)
|
reviewAPI.ListNoTitles(w, r)
|
||||||
case r.Method == http.MethodGet && subPath != "no-titles" && subSubPath == "next":
|
case r.Method == http.MethodGet && subPath != "no-titles" && subSubPath == "next":
|
||||||
reviewAPI.NextUnrated(w, r)
|
reviewAPI.NextNoTitles(w, r)
|
||||||
case r.Method == http.MethodGet && subPath != "":
|
case r.Method == http.MethodGet && subPath != "":
|
||||||
reviewAPI.Get(w, r, subPath)
|
reviewAPI.Get(w, r, subPath)
|
||||||
case r.Method == http.MethodPut && subPath != "":
|
case r.Method == http.MethodPut && subPath != "":
|
||||||
|
|
|
@ -34,20 +34,20 @@ Just answer with the JSON and nothing else. When in doubt about whether a title
|
||||||
func main() {
|
func main() {
|
||||||
//movieID := "c313ffa9-1cec-4d37-be6e-a4e18c247a0f" // night train
|
//movieID := "c313ffa9-1cec-4d37-be6e-a4e18c247a0f" // night train
|
||||||
//movieID := "07fb2a59-24ec-442e-aa9e-eb7e4fb002db" // battle royale
|
//movieID := "07fb2a59-24ec-442e-aa9e-eb7e4fb002db" // battle royale
|
||||||
movieID := "2fce2f8f-a048-4e39-8ffe-82df09a29d32" // shadows in paradise
|
//movieID := "2fce2f8f-a048-4e39-8ffe-82df09a29d32" // shadows in paradise
|
||||||
|
|
||||||
emdb := client.NewEMDB(os.Getenv("EMDB_BASE_URL"), os.Getenv("EMDB_API_KEY"))
|
emdb := client.NewEMDB(os.Getenv("EMDB_BASE_URL"), os.Getenv("EMDB_API_KEY"))
|
||||||
movie, err := emdb.GetMovie(movieID)
|
review, err := emdb.GetNextNoTitlesReview()
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
reviews, err := emdb.GetReviews(movieID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
movie, err := emdb.GetMovie(review.MovieID)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
llm, err := ollama.New(ollama.WithModel("mistral"))
|
llm, err := ollama.New(ollama.WithModel("mistral"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -63,7 +63,6 @@ func main() {
|
||||||
llmChain := chains.NewLLMChain(llm, prompt)
|
llmChain := chains.NewLLMChain(llm, prompt)
|
||||||
|
|
||||||
fmt.Printf("Processing review for movie: %s\n", movie.Title)
|
fmt.Printf("Processing review for movie: %s\n", movie.Title)
|
||||||
for _, review := range reviews {
|
|
||||||
fmt.Printf("Review: %s\n", review.Review)
|
fmt.Printf("Review: %s\n", review.Review)
|
||||||
outputValues, err := chains.Call(ctx, llmChain, map[string]any{
|
outputValues, err := chains.Call(ctx, llmChain, map[string]any{
|
||||||
"title": movie.Title,
|
"title": movie.Title,
|
||||||
|
@ -88,17 +87,13 @@ func main() {
|
||||||
|
|
||||||
if err := json.Unmarshal([]byte(out), &resp); err != nil {
|
if err := json.Unmarshal([]byte(out), &resp); err != nil {
|
||||||
fmt.Printf("could not unmarshal llm response, skipping this one: %s", err)
|
fmt.Printf("could not unmarshal llm response, skipping this one: %s", err)
|
||||||
continue
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Movies: %v\n", resp.Movies)
|
|
||||||
|
|
||||||
review.Titles = resp
|
review.Titles = resp
|
||||||
|
|
||||||
if err := emdb.UpdateReview(review); err != nil {
|
if err := emdb.UpdateReview(review); err != nil {
|
||||||
fmt.Printf("could not update review: %s\n", err)
|
fmt.Printf("could not update review: %s\n", err)
|
||||||
continue
|
os.Exit(1)
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue