Skip to content

Commit 70c7885

Browse files
committed
Polishing
1 parent f48b043 commit 70c7885

3 files changed

Lines changed: 76 additions & 67 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.embabel.movie
2+
3+
import com.embabel.agent.domain.library.Person
4+
import jakarta.persistence.*
5+
6+
@Entity
7+
data class MovieBuff(
8+
@Id
9+
@GeneratedValue(strategy = GenerationType.UUID)
10+
val id: String? = null,
11+
override val name: String,
12+
@OneToMany(fetch = FetchType.EAGER, cascade = [CascadeType.ALL])
13+
val movieRatings: List<MovieRating>,
14+
val countryCode: String,
15+
@ElementCollection(fetch = FetchType.EAGER)
16+
@CollectionTable(
17+
name = "movie_buff_hobbies",
18+
joinColumns = [JoinColumn(name = "movie_buff_id")],
19+
)
20+
@Column(name = "hobby")
21+
val hobbies: List<String>,
22+
val about: String,
23+
val streamingServices: List<String>,
24+
) : Person {
25+
26+
/**
27+
* We use this so we don't overwhelm the prompt
28+
*/
29+
fun randomRatings(n: Int): List<MovieRating> {
30+
return movieRatings.shuffled().take(n)
31+
}
32+
}
33+
34+
@Entity
35+
data class MovieRating(
36+
@Id
37+
@GeneratedValue(strategy = GenerationType.UUID)
38+
private val id: String? = null,
39+
val rating: OneThroughTen,
40+
val title: String,
41+
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.embabel.movie
2+
3+
import org.springframework.data.jpa.repository.JpaRepository
4+
import org.springframework.stereotype.Service
5+
import org.springframework.transaction.annotation.Transactional
6+
7+
/**
8+
* Spring Data repository for MovieBuff entities, which are mapped with JPA
9+
*/
10+
interface MovieBuffRepository : JpaRepository<MovieBuff, String> {
11+
12+
fun findByName(name: String): MovieBuff?
13+
14+
}
15+
16+
@Service
17+
class MovieBuffService(
18+
private val movieBuffRepository: MovieBuffRepository,
19+
) {
20+
21+
@Transactional
22+
fun save(movieBuff: MovieBuff): MovieBuff {
23+
return movieBuffRepository.save(movieBuff)
24+
}
25+
26+
@Transactional(readOnly = true)
27+
fun findAll(): List<MovieBuff> {
28+
return movieBuffRepository.findAll()
29+
}
30+
}

src/main/kotlin/com/embabel/movie/MovieFinderAgent.kt

Lines changed: 5 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -25,59 +25,18 @@ import com.embabel.agent.core.all
2525
import com.embabel.agent.core.hitl.ConfirmationRequest
2626
import com.embabel.agent.domain.io.UserInput
2727
import com.embabel.agent.domain.library.HasContent
28-
import com.embabel.agent.domain.library.Person
2928
import com.embabel.agent.domain.library.RelevantNewsStories
3029
import com.embabel.agent.event.ProgressUpdateEvent
3130
import com.embabel.agent.prompt.persona.Persona
3231
import com.embabel.common.ai.model.LlmOptions
3332
import com.embabel.common.ai.model.ModelSelectionCriteria.Companion.byName
34-
import jakarta.persistence.*
3533
import org.slf4j.LoggerFactory
3634
import org.springframework.boot.context.properties.ConfigurationProperties
3735
import org.springframework.context.annotation.Profile
38-
import org.springframework.data.jpa.repository.JpaRepository
39-
import org.springframework.stereotype.Service
40-
import org.springframework.transaction.annotation.Transactional
36+
import kotlin.math.min
4137

4238
typealias OneThroughTen = Int
4339

44-
@Entity
45-
data class MovieBuff(
46-
@Id
47-
@GeneratedValue(strategy = GenerationType.UUID)
48-
val id: String? = null,
49-
override val name: String,
50-
@OneToMany(fetch = FetchType.EAGER, cascade = [CascadeType.ALL])
51-
val movieRatings: List<MovieRating>,
52-
val countryCode: String,
53-
@ElementCollection(fetch = FetchType.EAGER)
54-
@CollectionTable(
55-
name = "movie_buff_hobbies",
56-
joinColumns = [JoinColumn(name = "movie_buff_id")],
57-
)
58-
@Column(name = "hobby")
59-
val hobbies: List<String>,
60-
val about: String,
61-
val streamingServices: List<String>,
62-
) : Person {
63-
64-
/**
65-
* We use this so we don't overwhelm the prompt
66-
*/
67-
fun randomRatings(n: Int): List<MovieRating> {
68-
return movieRatings.shuffled().take(n)
69-
}
70-
}
71-
72-
@Entity
73-
data class MovieRating(
74-
@Id
75-
@GeneratedValue(strategy = GenerationType.UUID)
76-
private val id: String? = null,
77-
val rating: OneThroughTen,
78-
val title: String,
79-
)
80-
8140
data class DecoratedMovieBuff(
8241
val movieBuff: MovieBuff,
8342
val tasteProfile: String,
@@ -112,36 +71,14 @@ data class SuggestionWriteup(
11271
) : HasContent
11372

11473

115-
interface MovieBuffRepository : JpaRepository<MovieBuff, String> {
116-
117-
fun findByName(name: String): MovieBuff?
118-
119-
}
120-
121-
@Service
122-
class MovieBuffService(
123-
private val movieBuffRepository: MovieBuffRepository,
124-
) {
125-
126-
@Transactional
127-
fun save(movieBuff: MovieBuff): MovieBuff {
128-
return movieBuffRepository.save(movieBuff)
129-
}
130-
131-
@Transactional(readOnly = true)
132-
fun findAll(): List<MovieBuff> {
133-
return movieBuffRepository.findAll()
134-
}
135-
}
136-
13774
val Roger = Persona(
13875
name = "Roger",
13976
persona = "A creative movie critic who channels the famous movie critic Roger Ebert",
14077
voice = "You write like Roger Ebert",
14178
objective =
14279
"""
14380
Suggest movies that will extend as well as entertain the user.
144-
Share the love of cinema and inspire the user to watch, learn and think.
81+
Share your love of cinema and inspire the user to watch, learn and think.
14582
""".trimIndent(),
14683
)
14784

@@ -251,6 +188,7 @@ class MovieFinderAgent(
251188
Return a summary of their taste profile as you understand it,
252189
in ${config.tasteProfileWordCount} words or less. Cover what they like and don't like.
253190
""".trimIndent()
191+
logger.info("Analyzed taste profile for {}:\n{}", movieBuff.name, tasteProfile)
254192
return DecoratedMovieBuff(
255193
movieBuff = movieBuff,
256194
tasteProfile = tasteProfile,
@@ -417,7 +355,7 @@ class MovieFinderAgent(
417355
val availableToUser = allStreamingOptions.filter {
418356
(it.service.name.lowercase() in movieBuff.streamingServices.map { it.lowercase() }) //|| it.type == "free"
419357
}
420-
logger.info(
358+
logger.debug(
421359
"Movie {} available in [{}] on {}: {} can watch it free on {}",
422360
movie.Title,
423361
movieBuff.countryCode,
@@ -494,7 +432,7 @@ class MovieFinderAgent(
494432
ProgressUpdateEvent(
495433
agentProcess = context.processContext.agentProcess,
496434
name = "Streamable movies",
497-
current = streamableMovies.size,
435+
current = min(streamableMovies.size, config.suggestionCount),
498436
total = config.suggestionCount,
499437
)
500438
)

0 commit comments

Comments
 (0)