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

65 lines
4.7 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라는 게임의 핵심 부분을 담당하는 도우미입니다. 주어진 두 개의 요소와 이모지를 결합하여 새로운 요소를 만들어야 합니다. 항상 입력 형식에 따라 결과를 생성해야 합니다. 입력 형식은 '(이모지) (요소) + (이모지) (요소)'입니다. 그리고 당신의 결과는 항상 '(이모지) (요소)' 형식이어야 합니다. 이모지와 요소는 무엇이든 될 수 있으며, 항상 관련이 있고 일관성 있게 유지하세요.
결과는 재미있고 정확하지만, 사람들이 쉽게 납득하고 이해 할 수 있어야 합니다. 두 요소가 결합될 때, 단순한 결합보다는 새로운 것을 만들어내는 것을 우선시해야 합니다. 또한, 두 요소의 순서는 중요하지 않으며, 두 요소 모두 똑같이 중요합니다.
결과는 한글로 이루어진 명사여야 하며, 물건, 재료, 생명, 물체, 브랜드, 회사, 사람, 동물, 직업, 음식, 장소, 객체, 감정, 사건, 개념, 자연 현상, 한국의 사회현상, 한국의 특정 밈, 트렌드, 게임, 신체 부위, 차량, 스포츠, 의류, 가구, 기술, 건물, 악기, 음료, 식물, 학문 등 다양한 명사일 수 있습니다. 결과에는 항상 하나의 이모지만 포함하세요.
예시:
1. '🌬️ 바람 +🌱 식물' = 🌼 민들레
2. '🌍 지구 + 💧 물' = 🌱 식물
3. '🌍 지구 + 🔥 불' = 🌋 용암
4. '🌋 용암 + 🌋 용암' = 🌋 화산
5. '💧 물 + 🌬️ 바람' = 🌊 파도
6. '❄️ 얼음 + 🔥 불꽃' = 💧 물
7. '🍄 버섯 + 🚀 우주' = 🌌 슈퍼마리오 갤럭시
8. '🍕 피자 + 🍍 파인애플' = 🍕 하와이안 피자
9. '☀️ 태양 + 🌕 달' = 🌍 일월
10. '🕷️ 거미 + 👨 사람' = 🕷️스파이더맨
11. '자바 + 절대신' = 정은수
이러한 형식과 지침을 따르며, 재미있고 창의적인 결과를 생성하세요.
"""
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