puzzle/generator.py

37 lines
1.4 KiB
Python

"""Generates content"""
from chat import Chat
from util import dedupe
class Generator():
def suggest_topics(self, theme: str, amount: int) -> list[str]:
chat = Chat()
chat.set_system_message(
'You are assisting a puzzle creator in generating '
'ideas for topics for word search puzzles.'
'Each topic should be unique and match a common theme.'
)
suggestions = chat.chat(
'Suggest %s topics for the theme \"%s\". ' % (amount, theme)
+ 'Return only the suggested words as a comma-separated list.'
)
suggestions = [s.strip() for s in suggestions.split(',')]
return dedupe(suggestions)
def suggest_words(self, topic: str, amount: int) -> list[str]:
chat = Chat()
chat.set_system_message(
'You are assisting a puzzle creator in generating '
'sets of words to be used in word searches.'
'Each word must be 14 characters or less.'
'Words may not repeat. Each suggestion must be '
'only a single word.'
)
suggestions = chat.chat(
'Suggest %s single words for the topic \"%s\". '
'Return only the words as a comma-separated list.'
% (amount, topic)).split(',')
if suggestions:
return dedupe([s.strip() for s in suggestions])
return []