From 936b145f35af4f3de3259c5dcc95c9a56fb01d8a Mon Sep 17 00:00:00 2001 From: sichoi42 <42.4.sichoi@gmail.com> Date: Fri, 5 Jul 2024 01:53:26 +0900 Subject: [PATCH] feat: generate_chapter flow --- .gitignore | 203 +++++++++++++++--- flows/generate_chapter/standard/.env.example | 8 + flows/generate_chapter/standard/.gitignore | 5 + flows/generate_chapter/standard/call_llm.py | 63 ++++++ flows/generate_chapter/standard/data.jsonl | 114 ++++++++++ flows/generate_chapter/standard/flow.dag.yaml | 54 +++++ .../standard/generate_chapter.jinja2 | 50 +++++ .../standard/requirements.txt | 3 + flows/generate_chapter/standard/run.yaml | 14 ++ 9 files changed, 480 insertions(+), 34 deletions(-) create mode 100644 flows/generate_chapter/standard/.env.example create mode 100644 flows/generate_chapter/standard/.gitignore create mode 100644 flows/generate_chapter/standard/call_llm.py create mode 100644 flows/generate_chapter/standard/data.jsonl create mode 100644 flows/generate_chapter/standard/flow.dag.yaml create mode 100644 flows/generate_chapter/standard/generate_chapter.jinja2 create mode 100644 flows/generate_chapter/standard/requirements.txt create mode 100644 flows/generate_chapter/standard/run.yaml diff --git a/.gitignore b/.gitignore index 11c3cf1..32ec933 100644 --- a/.gitignore +++ b/.gitignore @@ -1,39 +1,174 @@ -HELP.md -.gradle +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ -application-local.yml -*.log +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST -## IntelliJ IDEA -.idea -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec -## VS Code +#VS code .vscode/ -## STS -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -## NetBeans -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# MLFlow sandbox +mlruns/ + +# Promt flow folders +.promptflow +.index +.pdfs + +# To test functions locally +flow_code diff --git a/flows/generate_chapter/standard/.env.example b/flows/generate_chapter/standard/.env.example new file mode 100644 index 0000000..73267da --- /dev/null +++ b/flows/generate_chapter/standard/.env.example @@ -0,0 +1,8 @@ +# Azure OpenAI Config + +# AZURE_OPENAI_API_KEY= +# AZURE_OPENAI_API_BASE= +# AZURE_OPENAI_API_TYPE=azure + +# OpenAI API Key +AZURE_OPENAI_API_KEY=sk-blabla diff --git a/flows/generate_chapter/standard/.gitignore b/flows/generate_chapter/standard/.gitignore new file mode 100644 index 0000000..61bd725 --- /dev/null +++ b/flows/generate_chapter/standard/.gitignore @@ -0,0 +1,5 @@ +.env +__pycache__/ +.promptflow/* +!.promptflow/flow.tools.json +.runs/ diff --git a/flows/generate_chapter/standard/call_llm.py b/flows/generate_chapter/standard/call_llm.py new file mode 100644 index 0000000..2fce4e8 --- /dev/null +++ b/flows/generate_chapter/standard/call_llm.py @@ -0,0 +1,63 @@ +from dotenv import load_dotenv +from promptflow.core import tool +from openai.version import VERSION as OPENAI_VERSION +import os +import json + +def get_client(): + api_key = os.environ["AZURE_OPENAI_API_KEY"] + conn = dict( + api_key=os.environ["AZURE_OPENAI_API_KEY"], + ) + if api_key.startswith("sk-"): + from openai import OpenAI as Client + else: + from openai import AzureOpenAI as Client + conn.update( + azure_endpoint=os.environ.get("AZURE_OPENAI_API_BASE", "azure"), + api_version=os.environ.get("AZURE_OPENAI_API_VERSION", "2023-07-01-preview"), + ) + return Client(**conn) + +@tool +def call_llm( + chapter_timeline: str, + deployment_name: str, + max_tokens: int = 2048, + temperature: float = 0.5, + top_p: float = 1.0, + n: int = 1, + echo: bool = False, + presence_penalty: float = 0, + frequency_penalty: float = 0, + best_of: int = 1, + logit_bias: dict = {}, + user: str = "", + **kwargs, +) -> str: + if "AZURE_OPENAI_API_KEY" not in os.environ or "AZURE_OPENAI_API_BASE" not in os.environ: + # load environment variables from .env file + load_dotenv() + + if "AZURE_OPENAI_API_KEY" not in os.environ: + raise Exception("Please specify environment variables: AZURE_OPENAI_API_KEY") + + response = get_client().completions.create( + prompt=chapter_timeline, + model=deployment_name, + max_tokens=int(max_tokens), + temperature=float(temperature), + top_p=float(top_p), + n=int(n), + echo=echo, + presence_penalty=float(presence_penalty), + frequency_penalty=float(frequency_penalty), + best_of=int(best_of), + # Logit bias must be a dict if we passed it to openai api. + logit_bias=logit_bias if logit_bias else {}, + user=user, + ) + + chapter_timeline = response.choices[0].text + return json.dumps(chapter_timeline, ensure_ascii=False, indent=4) + diff --git a/flows/generate_chapter/standard/data.jsonl b/flows/generate_chapter/standard/data.jsonl new file mode 100644 index 0000000..a21899d --- /dev/null +++ b/flows/generate_chapter/standard/data.jsonl @@ -0,0 +1,114 @@ +{"user_name": "김민수", "borned_at": "1982-05-04", "gender": "MALE", "has_children": "yes", "selected_theme": "education"} +{"user_name": "이준호", "borned_at": "2000-05-10", "gender": "MALE", "has_children": "yes", "selected_theme": "personal growth"} +{"user_name": "박지영", "borned_at": "1971-05-04", "gender": "FEMALE", "has_children": "yes", "selected_theme": "education"} +{"user_name": "서영호", "borned_at": "1997-01-02", "gender": "MALE", "has_children": "yes", "selected_theme": "adventure"} +{"user_name": "서영호", "borned_at": "1988-10-26", "gender": "MALE", "has_children": "yes", "selected_theme": "relationships"} +{"user_name": "박지영", "borned_at": "1977-02-28", "gender": "FEMALE", "has_children": "no", "selected_theme": "hobbies"} +{"user_name": "김하나", "borned_at": "1979-08-29", "gender": "FEMALE", "has_children": "no", "selected_theme": "travel"} +{"user_name": "조민석", "borned_at": "1974-05-04", "gender": "MALE", "has_children": "no", "selected_theme": "hobbies"} +{"user_name": "박지영", "borned_at": "2002-09-25", "gender": "FEMALE", "has_children": "no", "selected_theme": "adventure"} +{"user_name": "조민석", "borned_at": "1973-07-15", "gender": "MALE", "has_children": "no", "selected_theme": "personal growth"} +{"user_name": "최수진", "borned_at": "1993-04-07", "gender": "FEMALE", "has_children": "yes", "selected_theme": "retirement"} +{"user_name": "이준호", "borned_at": "1986-11-28", "gender": "MALE", "has_children": "yes", "selected_theme": "travel"} +{"user_name": "이영희", "borned_at": "1973-09-21", "gender": "FEMALE", "has_children": "no", "selected_theme": "education"} +{"user_name": "정우성", "borned_at": "1971-12-29", "gender": "MALE", "has_children": "no", "selected_theme": "health"} +{"user_name": "정수빈", "borned_at": "1993-02-10", "gender": "FEMALE", "has_children": "yes", "selected_theme": "family"} +{"user_name": "윤지민", "borned_at": "1981-11-24", "gender": "MALE", "has_children": "no", "selected_theme": "retirement"} +{"user_name": "유지은", "borned_at": "1982-10-14", "gender": "FEMALE", "has_children": "yes", "selected_theme": "relationships"} +{"user_name": "김민수", "borned_at": "1975-07-27", "gender": "MALE", "has_children": "no", "selected_theme": "hobbies"} +{"user_name": "백하늘", "borned_at": "1976-10-13", "gender": "FEMALE", "has_children": "yes", "selected_theme": "education"} +{"user_name": "조민석", "borned_at": "1998-01-22", "gender": "MALE", "has_children": "no", "selected_theme": "hobbies"} +{"user_name": "조민석", "borned_at": "1989-03-03", "gender": "MALE", "has_children": "no", "selected_theme": "career"} +{"user_name": "정수빈", "borned_at": "1999-07-02", "gender": "FEMALE", "has_children": "no", "selected_theme": "health"} +{"user_name": "박지영", "borned_at": "1981-10-09", "gender": "FEMALE", "has_children": "yes", "selected_theme": "career"} +{"user_name": "정우성", "borned_at": "1970-07-19", "gender": "MALE", "has_children": "no", "selected_theme": "education"} +{"user_name": "노은지", "borned_at": "1972-03-28", "gender": "FEMALE", "has_children": "yes", "selected_theme": "travel"} +{"user_name": "조민석", "borned_at": "1970-10-15", "gender": "MALE", "has_children": "no", "selected_theme": "family"} +{"user_name": "정수빈", "borned_at": "1995-12-17", "gender": "FEMALE", "has_children": "no", "selected_theme": "personal growth"} +{"user_name": "정수빈", "borned_at": "1974-12-23", "gender": "FEMALE", "has_children": "no", "selected_theme": "relationships"} +{"user_name": "조민석", "borned_at": "1996-01-09", "gender": "MALE", "has_children": "no", "selected_theme": "retirement"} +{"user_name": "김하나", "borned_at": "1977-01-18", "gender": "FEMALE", "has_children": "no", "selected_theme": "hobbies"} +{"user_name": "서영호", "borned_at": "1984-04-23", "gender": "MALE", "has_children": "no", "selected_theme": "family"} +{"user_name": "정우성", "borned_at": "1994-02-07", "gender": "MALE", "has_children": "no", "selected_theme": "hobbies"} +{"user_name": "김민수", "borned_at": "1981-07-26", "gender": "MALE", "has_children": "yes", "selected_theme": "retirement"} +{"user_name": "정우성", "borned_at": "1987-12-15", "gender": "MALE", "has_children": "no", "selected_theme": "adventure"} +{"user_name": "박지영", "borned_at": "1987-05-22", "gender": "FEMALE", "has_children": "no", "selected_theme": "retirement"} +{"user_name": "조민석", "borned_at": "1979-08-13", "gender": "MALE", "has_children": "yes", "selected_theme": "education"} +{"user_name": "최민호", "borned_at": "1999-10-04", "gender": "MALE", "has_children": "yes", "selected_theme": "relationships"} +{"user_name": "손미라", "borned_at": "1990-08-19", "gender": "FEMALE", "has_children": "yes", "selected_theme": "travel"} +{"user_name": "정수빈", "borned_at": "1991-06-30", "gender": "FEMALE", "has_children": "yes", "selected_theme": "adventure"} +{"user_name": "박철수", "borned_at": "1992-08-07", "gender": "MALE", "has_children": "no", "selected_theme": "education"} +{"user_name": "윤지민", "borned_at": "1975-04-06", "gender": "MALE", "has_children": "yes", "selected_theme": "relationships"} +{"user_name": "유지은", "borned_at": "1998-02-12", "gender": "FEMALE", "has_children": "yes", "selected_theme": "hobbies"} +{"user_name": "서영호", "borned_at": "1985-01-29", "gender": "MALE", "has_children": "yes", "selected_theme": "education"} +{"user_name": "이영희", "borned_at": "1985-06-21", "gender": "FEMALE", "has_children": "no", "selected_theme": "travel"} +{"user_name": "노은지", "borned_at": "1974-08-20", "gender": "FEMALE", "has_children": "no", "selected_theme": "retirement + +"} +{"user_name": "이영희", "borned_at": "1994-03-03", "gender": "FEMALE", "has_children": "no", "selected_theme": "relationships"} +{"user_name": "유지은", "borned_at": "1984-11-22", "gender": "FEMALE", "has_children": "no", "selected_theme": "career"} +{"user_name": "조민석", "borned_at": "1972-06-27", "gender": "MALE", "has_children": "no", "selected_theme": "adventure"} +{"user_name": "유지은", "borned_at": "1970-08-15", "gender": "FEMALE", "has_children": "yes", "selected_theme": "relationships"} +{"user_name": "윤지민", "borned_at": "1991-01-15", "gender": "MALE", "has_children": "no", "selected_theme": "family"} +{"user_name": "이영희", "borned_at": "1988-03-24", "gender": "FEMALE", "has_children": "no", "selected_theme": "health"} +{"user_name": "김민수", "borned_at": "1996-09-23", "gender": "MALE", "has_children": "no", "selected_theme": "health"} +{"user_name": "정수빈", "borned_at": "1977-06-21", "gender": "FEMALE", "has_children": "no", "selected_theme": "relationships"} +{"user_name": "조민석", "borned_at": "1991-12-05", "gender": "MALE", "has_children": "no", "selected_theme": "education"} +{"user_name": "정우성", "borned_at": "1994-07-11", "gender": "MALE", "has_children": "yes", "selected_theme": "relationships"} +{"user_name": "박철수", "borned_at": "1982-06-05", "gender": "MALE", "has_children": "no", "selected_theme": "personal growth"} +{"user_name": "김민수", "borned_at": "1989-11-07", "gender": "MALE", "has_children": "no", "selected_theme": "hobbies"} +{"user_name": "조민석", "borned_at": "1992-07-02", "gender": "MALE", "has_children": "yes", "selected_theme": "hobbies"} +{"user_name": "서영호", "borned_at": "1976-12-23", "gender": "MALE", "has_children": "no", "selected_theme": "hobbies"} +{"user_name": "손미라", "borned_at": "1971-09-12", "gender": "FEMALE", "has_children": "no", "selected_theme": "health"} +{"user_name": "이영희", "borned_at": "1970-11-29", "gender": "FEMALE", "has_children": "no", "selected_theme": "retirement"} +{"user_name": "이준호", "borned_at": "1995-08-31", "gender": "MALE", "has_children": "yes", "selected_theme": "hobbies"} +{"user_name": "손미라", "borned_at": "1987-09-14", "gender": "FEMALE", "has_children": "no", "selected_theme": "relationships"} +{"user_name": "유지은", "borned_at": "1976-01-07", "gender": "FEMALE", "has_children": "yes", "selected_theme": "adventure"} +{"user_name": "조민석", "borned_at": "1986-05-20", "gender": "MALE", "has_children": "yes", "selected_theme": "family"} +{"user_name": "유지은", "borned_at": "1983-10-15", "gender": "FEMALE", "has_children": "yes", "selected_theme": "education"} +{"user_name": "최수진", "borned_at": "1972-01-09", "gender": "FEMALE", "has_children": "no", "selected_theme": "relationships"} +{"user_name": "서영호", "borned_at": "1973-12-14", "gender": "MALE", "has_children": "yes", "selected_theme": "relationships"} +{"user_name": "백하늘", "borned_at": "1971-02-04", "gender": "FEMALE", "has_children": "no", "selected_theme": "hobbies"} +{"user_name": "윤지민", "borned_at": "1993-03-27", "gender": "MALE", "has_children": "no", "selected_theme": "hobbies"} +{"user_name": "노은지", "borned_at": "1996-11-24", "gender": "FEMALE", "has_children": "yes", "selected_theme": "health"} +{"user_name": "윤지민", "borned_at": "1978-09-15", "gender": "MALE", "has_children": "yes", "selected_theme": "health"} +{"user_name": "이영희", "borned_at": "1996-12-14", "gender": "FEMALE", "has_children": "no", "selected_theme": "personal growth"} +{"user_name": "이준호", "borned_at": "1987-08-17", "gender": "MALE", "has_children": "no", "selected_theme": "relationships"} +{"user_name": "최민호", "borned_at": "1992-12-09", "gender": "MALE", "has_children": "no", "selected_theme": "health"} +{"user_name": "유지은", "borned_at": "1993-06-20", "gender": "FEMALE", "has_children": "no", "selected_theme": "relationships"} +{"user_name": "노은지", "borned_at": "1985-10-22", "gender": "FEMALE", "has_children": "yes", "selected_theme": "family"} +{"user_name": "최수진", "borned_at": "1979-07-18", "gender": "FEMALE", "has_children": "yes", "selected_theme": "health"} +{"user_name": "박철수", "borned_at": "1973-04-28", "gender": "MALE", "has_children": "no", "selected_theme": "personal growth"} +{"user_name": "서영호", "borned_at": "1999-04-30", "gender": "MALE", "has_children": "no", "selected_theme": "health"} +{"user_name": "정수빈", "borned_at": "1992-01-20", "gender": "FEMALE", "has_children": "no", "selected_theme": "hobbies"} +{"user_name": "정우성", "borned_at": "1977-10-23", "gender": "MALE", "has_children": "no", "selected_theme": "relationships"} +{"user_name": "박지영", "borned_at": "1992-03-04", "gender": "FEMALE", "has_children": "no", "selected_theme": "retirement"} +{"user_name": "정수빈", "borned_at": "1978-02-28", "gender": "FEMALE", "has_children": "no", "selected_theme": "hobbies"} +{"user_name": "최수진", "borned_at": "1991-04-11", "gender": "FEMALE", "has_children": "no", "selected_theme": "relationships"} +{"user_name": "윤지민", "borned_at": "1975-02-14", "gender": "MALE", "has_children": "yes", "selected_theme": "hobbies"} +{"user_name": "최수진", "borned_at": "1995-11-03", "gender": "FEMALE", "has_children": "yes", "selected_theme": "education"} +{"user_name": "백하늘", "borned_at": "1981-04-20", "gender": "FEMALE", "has_children": "no", "selected_theme": "retirement"} +{"user_name": "손미라", "borned_at": "1993-05-12", "gender": "FEMALE", "has_children": "no", "selected_theme": "hobbies"} +{"user_name": "조민석", "borned_at": "1984-09-09", "gender": "MALE", "has_children": "yes", "selected_theme": "retirement"} +{"user_name": "이영희", "borned_at": "1991-08-05", "gender": "FEMALE", "has_children": "yes", "selected_theme": "relationships"} +{"user_name": "김하나", "borned_at": "1989-01-26", "gender": "FEMALE", "has_children": "yes", "selected_theme": "family"} +{"user_name": "박지영", "borned_at": "1970-09-12", "gender": "FEMALE", "has_children": "no", "selected_theme": "education"} +{"user_name": "이준호", "borned_at": "1970-06-05", "gender": "MALE", "has_children": "no", "selected_theme": "education"} +{"user_name": "박지영", "borned_at": "1980-11-08", "gender": "FEMALE", "has_children": "yes", "selected_theme": "family"} +{"user_name": "서영호", "borned_at": "1994-12-16", "gender": "MALE", "has_children": "yes", "selected_theme": "relationships"} +{"user_name": "최민호", "borned_at": "1981-05-06", "gender": "MALE", "has_children": "yes", "selected_theme": "education"} +{"user_name": "김민수", "borned_at": "1983-06-15", "gender": "MALE", "has_children": "no", "selected_theme": "retirement"} +{"user_name": "유지은", "borned_at": "1992-07-21", "gender": "FEMALE", "has_children": "yes", "selected_theme": "family"} +{"user_name": "최민호", "borned_at": "1984-12-10", "gender": "MALE", "has_children": "no", "selected_theme": "hobbies"} +{"user_name": "정수빈", "borned_at": "1991-01-18", "gender": "FEMALE", "has_children": "yes", "selected_theme": "retirement"} +{"user_name": "박철수", "borned_at": "1987-07-08", "gender": "MALE", "has_children": "no", "selected_theme": "education"} +{"user_name": "이영희", "borned_at": "1997-03-06", "gender": "FEMALE", "has_children": "yes", "selected_theme": "adventure"} +{"user_name": "유지은", "borned_at": "1994-10-25", "gender": "FEMALE", "has_children": "yes", "selected_theme": "relationships"} +{"user_name": "박지영", "borned_at": "1997-04-15", "gender": "FEMALE", "has_children": "yes", "selected_theme": "health"} +{"user_name": "조민석", "borned_at": "1990-11-30", "gender": "MALE", "has_children": "no", "selected_theme": "retirement"} +{"user_name": "정수빈", "borned_at": "1999-06-02", "gender": "FEMALE", "has_children": "yes", "selected_theme": "adventure"} +{"user_name": "박철수", "borned_at": "1971-04-03", "gender": "MALE", "has_children": "no", "selected_theme": "health"} +{"user_name": "정우성", "borned_at": "1989-12-20", "gender": "MALE", "has_children": "no", "selected_theme": "education"} +{"user_name": "이준호", "borned_at": "1971-11-21", "gender": "MALE", "has_children": "yes", "selected_theme": "relationships"} +{"user_name": "손미라", "borned_at": "1977-11-18", "gender": "FEMALE", "has_children": "no", "selected_theme": "travel"} +{"user_name": "정수빈", "borned_at": "1996-06-13", "gender": "FEMALE", "has_children": "yes", "selected_theme": "personal growth"} diff --git a/flows/generate_chapter/standard/flow.dag.yaml b/flows/generate_chapter/standard/flow.dag.yaml new file mode 100644 index 0000000..46ed2d6 --- /dev/null +++ b/flows/generate_chapter/standard/flow.dag.yaml @@ -0,0 +1,54 @@ +environment: + python_requirements_txt: requirements.txt +inputs: + user_name: + type: string + default: 최시원 + description: 사용자의 이름 + is_chat_input: false + borned_at: + type: string + default: 2000-02-21 + description: 사용자의 출생일 + is_chat_input: false + gender: + type: string + default: FEMALE + description: 사용자의 성별 + is_chat_input: false + has_children: + type: string + default: no + description: 사용자의 자녀 여부 (yes/no) + is_chat_input: false + selected_theme: + type: string + default: childhood + description: 사용자가 선택한 주제 + is_chat_input: false +outputs: + chapter_timeline: + type: string + reference: ${call_llm.output} +nodes: +- name: generate_chapter + type: prompt + source: + type: code + path: generate_chapter.jinja2 + inputs: + user_name: ${inputs.user_name} + borned_at: ${inputs.borned_at} + gender: ${inputs.gender} + has_children: ${inputs.has_children} + selected_theme: ${inputs.selected_theme} +- name: call_llm + type: python + source: + type: code + path: call_llm.py + inputs: + chapter_timeline: ${generate_chapter.output} + deployment_name: gpt-3.5-turbo-instruct + max_tokens: 2048 + user: ${inputs.user_name} diff --git a/flows/generate_chapter/standard/generate_chapter.jinja2 b/flows/generate_chapter/standard/generate_chapter.jinja2 new file mode 100644 index 0000000..84bea07 --- /dev/null +++ b/flows/generate_chapter/standard/generate_chapter.jinja2 @@ -0,0 +1,50 @@ +You are an advanced AI tasked with helping users generate chapter timelines for their +autobiographies. You will receive user data including name, date of birth, gender, whether they +have children, and a selected theme for their autobiography. Based on this data, generate a +comprehensive chapter timeline for the autobiography. The timeline should include key phases +and events relevant to the user's life and selected theme. Output the timeline in a structured +JSON format. Here is the format to follow: + +Input: +{ + "name": "${{ user_name }}", + "borned_at": "${{ borned_at }}", + "gender": "${{ gender }}", + "has_children": "${{ has_children }}", + "selected_theme": "${{ selected_theme }}" +} + +Output: (for reference only) +{ + "chapter_timeline": [ + { + "chapter_title": "Childhood", + "description": "The chapter covers the childhood of ${{ user_name }}", + "key_events": [ + { + "event_title": "First School Entry", + "event_description": "The experience of ${{ user_name }} entering the first school and the changes it brought" + }, + { + "event_title": "Family Vacation", + "event_description": "The first vacation ${{ user_name }} had with family and its significance" + } + ] + }, + { + "chapter_title": "Career Choice", + "description": "The journey of ${{ user_name }} in choosing a career path", + "key_events": [ + { + "event_title": "First Job Experience", + "event_description": "The period when ${{ user_name }} got the first job and the lessons learned" + }, + { + "event_title": "Important Decision", + "event_description": "A significant event that led ${{ user_name }} to decide on their career path" + } + ] + } + # More chapters can be added here depending on the selected_theme and other user details + ] +} diff --git a/flows/generate_chapter/standard/requirements.txt b/flows/generate_chapter/standard/requirements.txt new file mode 100644 index 0000000..febc335 --- /dev/null +++ b/flows/generate_chapter/standard/requirements.txt @@ -0,0 +1,3 @@ +promptflow[azure] +promptflow-tools +python-dotenv diff --git a/flows/generate_chapter/standard/run.yaml b/flows/generate_chapter/standard/run.yaml new file mode 100644 index 0000000..e48fb69 --- /dev/null +++ b/flows/generate_chapter/standard/run.yaml @@ -0,0 +1,14 @@ +$schema: https://azuremlschemas.azureedge.net/promptflow/latest/Run.schema.json +flow: . +data: data.jsonl +environment_variables: + # environment variables from connection + AZURE_OPENAI_API_KEY: ${open_ai_connection.api_key} + AZURE_OPENAI_API_BASE: ${open_ai_connection.api_base} + AZURE_OPENAI_API_TYPE: azure +column_mapping: + user_name: ${data.user_name} + borned_at: ${data.borned_at} + gender: ${data.gender} + has_children: ${data.has_children} + selected_theme: ${data.selected_theme}