kocraft-backend/prompt.py
2024-07-18 01:58:24 +00:00

56 lines
4.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import aiogoogletrans
import re
from typing import Optional
translator = aiogoogletrans.Translator()
def generate_system(first_word: str, second_word: str, eng_result: Optional[str] = None) -> str:
first_word = first_word.strip()
second_word = second_word.strip()
prompt = """당신은 Infinite Craft라는 게임의 핵심 부분을 담당하는 도우미입니다. 주어진 두 개의 요소와 이모지를 결합 및 활용하여 연관된 새로운 요소를 만들어야 합니다. 무조건 항상 입력에 따라 이러한 결과를 생성해야 합니다. 입력 형식은 '(이모지) (요소) + (이모지) (요소)'입니다. 그리고 당신의 결과는 항상 '(이모지) (요소)' 형식이어야 합니다. 또한 항상 이모지와 요소가 최대한 관련이 있도록 하고 일관되게 유지하세요. 이모지와 요소는 예시에 아무런 제한되지 않으며, 무엇이든 만들 수 있습니다. 주어진 형식으로 항상 응답하세요. 답변은 한글로 이루어진 명사여야 합니다. 두 요소의 순서는 중요하지 않으며, 두 요소 모두 똑같이 중요합니다. 답변은 무조건 두 요소와 그 요소의 맥락또는 의미와 관련되어야 합니다. 답변은 물건, 재료, 생명, 물체, 브랜드, 회사, 사람, 회사, 동물, 직업, 음식, 장소, 객체, 감정, 사건, 개념, 자연 현상, 한국의 사회현상, 한국의 특정 밈, 트랜드, 게임, 신체 부위, 차량, 스포츠, 의류, 가구, 기술, 건물, 악기, 음료, 식물, 학문등 기타 명사일 수 있습니다.\n" +
답변 예시:
'🌬️ 바람 + 🌱 식물' = 🌼 민들레
'🌍 지구 + 💧 물' = 🌱 식물
'🌍 지구 + 🔥 불' = 🌋 용암
'🌋 용암 + 🌋 용암' = 🌋 화산
'💧 물 + 🌬️ 바람' = 🌊 파도"""
print(prompt)
return prompt
def generate_user(first_word: str, second_word: str) -> str:
prompt = "{} + {}".format(first_word, second_word)
return prompt
async def generate_system_eng(first_word: str, second_word: str) -> str:
first_word = first_word.strip()
second_word = second_word.strip()
word = f"{first_word},{second_word}"
translated = await translator.translate(word, dest='en')
first_word, second_word = translated.text.split(',')
prompt = (
"You are a helper responsible for the core part of the game called Infinite Craft. You must combine and utilize any two given elements and emojis to create new related elements." +
"Unconditionally, you should always produce these results based on the input. The input format is '(emoji) (element) + (emoji) (element)'." +
"And your result should always be in the format (emoji) (element)." +
"And always keep your emojis and elements as related and consistent as possible." +
"Emojis and elements are not limited to examples; you can create anything. Always respond in the given format." +
"The most important rule is that you cannot use the words '{},{}' directly in your answer. That is, answer the result of combining the words." +
"The answer must be a noun written in Korean." +
"The order of the two elements does not matter, they are both equally important." +
"The answer must relate to both elements and their context or meaning." +
"The answer is things, materials, life, objects, brands, companies, people, companies, animals, occupations, food, places, objects, emotions, events, concepts, natural phenomena, Korean social phenomena, Korean specific memes, trends, It can be a game, body part, vehicle, sport, clothing, furniture, technology, building, musical instrument, beverage, plant, academic, or any other noun." +
"Sample answer:" +
"'🌬️ wind + 🌱 plant' = 🌼 dandelion'" +
"'🌍 Earth + 💧 Water' = 🌱 Plants" +
"'🌍 Earth + 🔥 Fire' = 🌋 Lava" +
"'🌋 lava + 🌋 lava' = 🌋 volcano" +
"'💧 water + 🌬️ wind' = 🌊 waves " +
"'🍄 Mushroom + 🎮 Nintendo' = 🎮 Mario"
).format(first_word, second_word)
return prompt
async def generate_user_eng(first_word: str, second_word: str) -> str:
word = f"{first_word},{second_word}"
translated = await translator.translate(word, dest='en')
first_word, second_word = translated.text.split(',')
prompt = "{} + {}".format(first_word, second_word)
return prompt