Eric Botti
commited on
Commit
·
ea658a2
1
Parent(s):
cebc517
added player logging
Browse files- src/player.py +10 -7
src/player.py
CHANGED
@@ -4,6 +4,7 @@ import asyncio
|
|
4 |
|
5 |
import openai
|
6 |
from agents import LogMessagesKani
|
|
|
7 |
from kani.engines.openai import OpenAIEngine
|
8 |
|
9 |
from game_utils import log
|
@@ -36,6 +37,8 @@ class Player:
|
|
36 |
self.role = role
|
37 |
self.messages = []
|
38 |
|
|
|
|
|
39 |
if log_filepath:
|
40 |
player_info = {
|
41 |
"id": self.id,
|
@@ -47,15 +50,14 @@ class Player:
|
|
47 |
|
48 |
async def respond_to(self, prompt: str) -> str:
|
49 |
"""Makes the player respond to a prompt. Returns the response."""
|
50 |
-
# Generate a response from the controller
|
51 |
-
output = await self.__generate(prompt)
|
52 |
-
|
53 |
-
return output
|
54 |
-
|
55 |
-
async def __generate(self, prompt: str) -> str:
|
56 |
if self.controller == "human":
|
|
|
|
|
57 |
print(prompt)
|
58 |
-
|
|
|
|
|
|
|
59 |
|
60 |
elif self.controller == "ai":
|
61 |
output = await self.kani.chat_round_str(prompt)
|
@@ -64,3 +66,4 @@ class Player:
|
|
64 |
|
65 |
|
66 |
|
|
|
|
4 |
|
5 |
import openai
|
6 |
from agents import LogMessagesKani
|
7 |
+
from kani import ChatMessage
|
8 |
from kani.engines.openai import OpenAIEngine
|
9 |
|
10 |
from game_utils import log
|
|
|
37 |
self.role = role
|
38 |
self.messages = []
|
39 |
|
40 |
+
self.log_filepath = log_filepath
|
41 |
+
|
42 |
if log_filepath:
|
43 |
player_info = {
|
44 |
"id": self.id,
|
|
|
50 |
|
51 |
async def respond_to(self, prompt: str) -> str:
|
52 |
"""Makes the player respond to a prompt. Returns the response."""
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
if self.controller == "human":
|
54 |
+
# We're pretending the human is an ai for logging purposes... I don't love this but it's fine for now
|
55 |
+
log(ChatMessage.user(prompt), self.log_filepath)
|
56 |
print(prompt)
|
57 |
+
output = input()
|
58 |
+
log(ChatMessage.ai(output), self.log_filepath)
|
59 |
+
|
60 |
+
return output
|
61 |
|
62 |
elif self.controller == "ai":
|
63 |
output = await self.kani.chat_round_str(prompt)
|
|
|
66 |
|
67 |
|
68 |
|
69 |
+
|