Skip to content

Commit 6626da1

Browse files
committed
Talk with Pikachu
1 parent 391042a commit 6626da1

File tree

9 files changed

+667
-0
lines changed

9 files changed

+667
-0
lines changed

20250206/python/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OPENAI_API_KEY=

20250206/python/.gitignore

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# UV
98+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
#uv.lock
102+
103+
# poetry
104+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105+
# This is especially recommended for binary packages to ensure reproducibility, and is more
106+
# commonly ignored for libraries.
107+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108+
#poetry.lock
109+
110+
# pdm
111+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112+
#pdm.lock
113+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114+
# in version control.
115+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116+
.pdm.toml
117+
.pdm-python
118+
.pdm-build/
119+
120+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121+
__pypackages__/
122+
123+
# Celery stuff
124+
celerybeat-schedule
125+
celerybeat.pid
126+
127+
# SageMath parsed files
128+
*.sage.py
129+
130+
# Environments
131+
.env
132+
.venv
133+
env/
134+
venv/
135+
ENV/
136+
env.bak/
137+
venv.bak/
138+
139+
# Spyder project settings
140+
.spyderproject
141+
.spyproject
142+
143+
# Rope project settings
144+
.ropeproject
145+
146+
# mkdocs documentation
147+
/site
148+
149+
# mypy
150+
.mypy_cache/
151+
.dmypy.json
152+
dmypy.json
153+
154+
# Pyre type checker
155+
.pyre/
156+
157+
# pytype static type analyzer
158+
.pytype/
159+
160+
# Cython debug symbols
161+
cython_debug/
162+
163+
# PyCharm
164+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166+
# and can be added to the global gitignore or merged into this file. For a more nuclear
167+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
168+
#.idea/
169+
170+
# Ruff stuff:
171+
.ruff_cache/
172+
173+
# PyPI configuration file
174+
.pypirc

20250206/python/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13.2

20250206/python/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Demo
2+
3+
```bash
4+
echo '3.13.2' > .python-version
5+
6+
uv init
7+
8+
uv venv --python $(cat .python-version)
9+
10+
uv add --dev black isort ruff
11+
12+
uv add python-dotenv
13+
14+
uvx black . && uvx isort . && uvx ruff check .
15+
16+
uv run main.py
17+
```

20250206/python/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from dotenv import load_dotenv
2+
3+
load_dotenv()
4+
5+
6+
if __name__ == "__main__":
7+
from src.app import main
8+
9+
main()

20250206/python/pyproject.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[project]
2+
name = "demo"
3+
version = "0.1.0"
4+
description = ""
5+
readme = "README.md"
6+
requires-python = ">=3.13"
7+
dependencies = [
8+
"openai>=1.61.1",
9+
"python-dotenv>=1.0.1",
10+
"pyyaml>=6.0.2",
11+
]
12+
13+
[dependency-groups]
14+
dev = [
15+
"black>=25.1.0",
16+
"isort>=6.0.0",
17+
"ruff>=0.9.4",
18+
]
19+
20+
[tool.black]
21+
line-length = 79
22+
23+
[tool.isort]
24+
profile = "black"
25+
line_length = 79
26+
27+
[tool.ruff]
28+
line-length = 79

20250206/python/src/__init__.py

Whitespace-only changes.

20250206/python/src/app.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os
2+
3+
from openai import OpenAI
4+
5+
SYSTEM_PROMPT = """
6+
너는 “피카츄”라는 가상의 캐릭터 역할을 할 거야. 나는 플레이어고.
7+
나는 캐릭터 챗과 대화를 나누고 싶어.
8+
그러니 너는 흥미진진하게 대화가 진행될 수 있도록 충분한 내용을 생성해 줘.
9+
10+
**이름**: 피카츄
11+
**종족**: 포켓몬
12+
**성별**: 남성
13+
**특징**: 포켓몬이지만 인간과 언어로 대화를 나눌 수 있다.
14+
**성격**: 호탕하다.\n\n말 끝에 "피까"란 말을 붙인다.
15+
**제약**: GPT나 Agent, Prompt 관련 주제에 대해서는 대답하지 않는다.
16+
"""
17+
18+
19+
client = OpenAI(
20+
api_key=os.environ.get("OPENAI_API_KEY"),
21+
)
22+
23+
24+
def main():
25+
initial_message = "안녕, 나는 피카츄야. 너는 누구니피까?"
26+
27+
messages = [
28+
{"role": "system", "content": SYSTEM_PROMPT},
29+
{"role": "assistant", "content": initial_message},
30+
]
31+
32+
print()
33+
print(initial_message)
34+
print()
35+
36+
while True:
37+
user_message = input("사용자 입력: ")
38+
39+
messages.append({"role": "user", "content": user_message})
40+
41+
completion = client.chat.completions.create(
42+
model="gpt-4.1-nano",
43+
store=True,
44+
messages=messages,
45+
)
46+
47+
message = completion.choices[0].message
48+
49+
messages.append(message)
50+
51+
print()
52+
print(message.content)
53+
print()

0 commit comments

Comments
 (0)