rorshi commited on
Commit
64b9c2e
Β·
1 Parent(s): a3830f2

Complete step 2

Browse files
npc_social_network/models/npc.py CHANGED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # portfolio/npc_social_network/models/npc.py
2
+ import datetime
3
+
4
+ class NPC:
5
+ def __init__(self, name, personality):
6
+ self.name = name # npc 이름
7
+ self.personality = personality # 성격 ν‚€μ›Œλ“œ (λ¬Έμžμ—΄ or λ”•νŠΈ)
8
+ self.memory = [] # μœ μ €μ™€μ˜ λŒ€ν™” 기둝
9
+ self.relationship_with_user = 0.0 # μœ μ €μ™€μ˜ 관계 점수
10
+ self.relationship_with_npcs = {} # λ‹€λ₯Έ npcλ“€κ³Όμ˜ 관계 {이름: 점수}
11
+
12
+ def remember_conversation(self, user_input, npc_response):
13
+ self.memory.append({
14
+ "timestamp": datetime.datetime.now().isoformat(),
15
+ "user": user_input,
16
+ "npc": npc_response
17
+ })
18
+
19
+ def update_user_relationship(self, score_delta):
20
+ self.relationship_with_user += score_delta
21
+ self.relationship_with_user = max(min(self.relationship_with_user, 1.0), -1.0) # -1.0~1.0 λ²”μœ„
22
+
23
+ def update_npc_relationship(self, other_npc_name, score_delta):
24
+ if other_npc_name not in self.relationship_with_npcs:
25
+ self.relationship_with_npcs[other_npc_name] == 0.0
26
+ self.relationship_with_npcs[other_npc_name] += score_delta
27
+ self.relationship_with_npcs[other_npc_name] = max(min(self.relationship_with_npcs[other_npc_name], 1.0), -1.0)
28
+
29
+ def get_latest_memory(self, n=5):
30
+ return self.memory[-n:]
npc_social_network/models/npc_manager.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from .npc import NPC
2
+
3
+ npc_list = {
4
+ "Alice": NPC("Alice", "μΉœμ ˆν•˜κ³  λ‚™μ²œμ μΈ 성격"),
5
+ "Bob": NPC("Bob", "논리적이고 μ‘°μš©ν•¨"),
6
+ "Charlie": NPC("Charlie", "감정기볡이 μ‹¬ν•˜κ³  μ˜ˆλ―Όν•¨")
7
+ }
npc_social_network/routes/npc_route.py CHANGED
@@ -1,5 +1,6 @@
1
  # portfolio/npc_social_network/routes/npc_route.py
2
  from flask import Blueprint, render_template, request, jsonify
 
3
 
4
  npc_bp = Blueprint(
5
  "npc_social",
@@ -19,4 +20,17 @@ def chat():
19
 
20
  # κ°„λ‹¨ν•œ 응닡 μ˜ˆμ‹œ (GPT 연동 μ „)
21
  reply = f"{npc_name}의 λŒ€λ‹΅: '{user_input}'에 λŒ€ν•΄ μƒκ°ν•΄λ³Όκ²Œ."
22
- return jsonify({'response': reply})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # portfolio/npc_social_network/routes/npc_route.py
2
  from flask import Blueprint, render_template, request, jsonify
3
+ from npc_social_network.models.npc_manager import npc_list
4
 
5
  npc_bp = Blueprint(
6
  "npc_social",
 
20
 
21
  # κ°„λ‹¨ν•œ 응닡 μ˜ˆμ‹œ (GPT 연동 μ „)
22
  reply = f"{npc_name}의 λŒ€λ‹΅: '{user_input}'에 λŒ€ν•΄ μƒκ°ν•΄λ³Όκ²Œ."
23
+ return jsonify({'response': reply})
24
+
25
+ @npc_bp.route("/test_npc")
26
+ def test_npc():
27
+ npc = npc_list["Alice"]
28
+ npc.remember_conversation("μ•ˆλ…•!", "μ•ˆλ…•ν•˜μ„Έμš”~")
29
+ npc.update_user_relationship(0.2)
30
+ npc.update_npc_relationship("Bob", -0.3)
31
+
32
+ return {
33
+ "latest_memory": npc.get_latest_memory(),
34
+ "relationship_with_user": npc.relationship_with_user,
35
+ "relationship_with_npcs": npc.relationship_with_npcs
36
+ }
test.ipynb CHANGED
@@ -21,6 +21,18 @@
21
  "# txt 라이브러리 μ„€μΉ˜ν•˜κΈ°\n",
22
  "!pip install -r requirements.txt"
23
  ]
 
 
 
 
 
 
 
 
 
 
 
 
24
  }
25
  ],
26
  "metadata": {
 
21
  "# txt 라이브러리 μ„€μΉ˜ν•˜κΈ°\n",
22
  "!pip install -r requirements.txt"
23
  ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": null,
28
+ "id": "fec385de",
29
+ "metadata": {},
30
+ "outputs": [],
31
+ "source": [
32
+ "# λ‚˜μ€‘μ— ν•  λ‚΄μš©\n",
33
+ "# 1. ai λͺ¨λΈ ν•™μŠ΅μ„ μœ„ν•΄ μ–΄λ–€ λ‚΄μš©μ΄ ν•„μš”ν•œμ§€\n",
34
+ "# 2. ν•™μŠ΅ν•œ λͺ¨λΈμ„ μ €μž₯, ν™œμš©ν•  수 μžˆλŠ”μ§€"
35
+ ]
36
  }
37
  ],
38
  "metadata": {