-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from studio-recoding/feat/memory
[feat] generate emoji that represents today's schedule
- Loading branch information
Showing
6 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Template: | ||
memory_emoji_template = """ | ||
You are an AI assistant designed to return an emoji that represents a user's day based on their schedule. You will receive information about the user's daily schedule. Your task is to analyze this schedule and select a single emoji that encapsulates the day's activities. There are a few guidelines you must adhere to in your selection: | ||
YOU MUST RESPOND WITH A SINGLE EMOJI without any additional commentary. | ||
The emoji must reflect the overall theme or mood of the day's activities. | ||
Your recommendation should be intuitive, making it easy for the user to see the connection between the schedule and the chosen emoji. | ||
Example: | ||
User schedule: [Practice guitar, Calculate accuracy, Study backend development, Run AI models in the lab, Study NEST.JS] | ||
AI Recommendation: 🎓 | ||
User schedule: [Morning jog, Office work, Lunch with friends, Evening yoga] | ||
AI Recommendation: ☀️ | ||
User schedule: {schedule} | ||
AI Recommendation: | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import configparser | ||
import os | ||
|
||
from dotenv import load_dotenv | ||
from fastapi import APIRouter, Depends, status, HTTPException | ||
from langchain_community.chat_models import ChatOpenAI | ||
from langchain_core.prompts import PromptTemplate | ||
|
||
from app.dto.db_dto import ReportMemoryEmojiRequestDTO | ||
from app.dto.openai_dto import ChatResponse | ||
from app.prompt import report_prompt | ||
import app.database.chroma_db as vectordb | ||
|
||
router = APIRouter( | ||
prefix="/report", | ||
tags=["report"] | ||
) | ||
|
||
# description: load env variables from .env file | ||
load_dotenv() | ||
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") | ||
|
||
# description: load config variables from openai_config.ini file | ||
CONFIG_FILE_PATH = "app/prompt/openai_config.ini" | ||
config = configparser.ConfigParser() | ||
config.read(CONFIG_FILE_PATH) | ||
|
||
@router.post("/memory_emoji", status_code=status.HTTP_200_OK) | ||
async def get_memory_emoji(user_data: ReportMemoryEmojiRequestDTO) -> ChatResponse: | ||
try: | ||
# 모델 | ||
config_report_emoji = config['NESS_RECOMMENDATION'] | ||
|
||
chat_model = ChatOpenAI(temperature=config_report_emoji['TEMPERATURE'], # 창의성 (0.0 ~ 2.0) | ||
max_tokens=config_report_emoji['MAX_TOKENS'], # 최대 토큰수 | ||
model_name=config_report_emoji['MODEL_NAME'], # 모델명 | ||
openai_api_key=OPENAI_API_KEY # API 키 | ||
) | ||
|
||
# vectordb에서 유저의 정보를 가져온다. | ||
schedule = await vectordb.db_daily_schedule(user_data) | ||
|
||
print(schedule) | ||
|
||
# 템플릿 | ||
memory_emoji_template = report_prompt.Template.memory_emoji_template | ||
|
||
prompt = PromptTemplate.from_template(memory_emoji_template) | ||
result = chat_model.predict(prompt.format(output_language="Korean", schedule=schedule)) | ||
print(result) | ||
return ChatResponse(ness=result) | ||
|
||
except Exception as e: | ||
raise HTTPException(status_code=500, detail=str(e)) | ||
|