Eric Botti commited on
Commit
778c3d7
·
1 Parent(s): 3ea5035

added llm calls to ai

Browse files
Files changed (2) hide show
  1. src/game_utils.py +8 -3
  2. src/player.py +27 -5
src/game_utils.py CHANGED
@@ -38,14 +38,20 @@ WIN CONDITION:
38
  '''
39
 
40
  herd_animal = """\
41
- You are a {animal}. In 10 words or less give a description of yourself starting with "I". The description should not give away too much information about the {animal} as you do not want the Chameleon to be able to guess what animal you are. Do not repeat responses from other players.
 
 
42
  Previously Mentioned Descriptions:
43
  {player_responses}
44
  Your Response:
45
  """
46
 
47
  chameleon_animal = """\
48
- You are the Chameleon. Initially, you don't know what animal the other players are, your goal is to deduce . Using the context that they have provided, In 10 words or less give a description of yourself starting with "I". If no one else has said anything try to say something generic that could be true of any animals.
 
 
 
 
49
  Previously Mentioned Descriptions:
50
  {player_responses}
51
  Your Response:
@@ -65,7 +71,6 @@ chameleon_prompt = """\
65
  You are the Chameleon, vote for someone else to remove suspicion from yourself.
66
  """
67
 
68
-
69
  prompts = {
70
  "herd_animal": game_rules + herd_animal,
71
  "chameleon_animal": game_rules + chameleon_animal,
 
38
  '''
39
 
40
  herd_animal = """\
41
+ You are a {animal}, keep this a secret at all costs.
42
+ In 10 words or less give a description of yourself starting with "I". The description should not give away too much information about the {animal} as you do not want the Chameleon to be able to guess what animal you are. Do not repeat responses from other players.
43
+ If the Chameleon can guess what animal you really are you will LOSE.
44
  Previously Mentioned Descriptions:
45
  {player_responses}
46
  Your Response:
47
  """
48
 
49
  chameleon_animal = """\
50
+ You are the Chameleon, keep this a secret at all costs.
51
+ You don't know what animal the other players are, your goal is to deduce it using the context they provide.
52
+ Starting with "I" describe yourself in 10 words or less as if you are the same animal as the other players.
53
+ If no one else has said anything try to say something generic that could be true of any animals.
54
+ If the other players realize you are the Chameleon you will LOSE.
55
  Previously Mentioned Descriptions:
56
  {player_responses}
57
  Your Response:
 
71
  You are the Chameleon, vote for someone else to remove suspicion from yourself.
72
  """
73
 
 
74
  prompts = {
75
  "herd_animal": game_rules + herd_animal,
76
  "chameleon_animal": game_rules + chameleon_animal,
src/player.py CHANGED
@@ -1,4 +1,19 @@
1
- from game_utils import fetch_prompt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  class Player:
4
  def __init__(self, name: str, controller: str, role: str):
@@ -9,9 +24,9 @@ class Player:
9
 
10
  def collect_input(self, prompt: str) -> str:
11
  """Store the input and output in the messages list. Return the output."""
12
- self.messages.append(prompt)
13
  output = self.respond(prompt)
14
- self.messages.append(output)
15
  return output
16
 
17
  def respond(self, prompt: str) -> str:
@@ -20,11 +35,18 @@ class Player:
20
  return input()
21
 
22
  elif self.controller == "ai":
23
- return "I am an AI and I am responding to the prompt."
 
 
 
 
 
 
 
24
 
25
  def add_message(self, message: str):
26
  """Add a message to the messages list. No response required."""
27
- self.messages.append(message)
28
 
29
 
30
 
 
1
+ import os
2
+ import openai
3
+
4
+ # Using TGI Inference Endpoints from Hugging Face
5
+ # api_type = "tgi"
6
+ api_type = "openai"
7
+
8
+ if api_type == "tgi":
9
+ model_name = "tgi"
10
+ client = openai.Client(
11
+ base_url=os.environ['HF_ENDPOINT_URL'] + "/v1/",
12
+ api_key=os.environ['HF_API_TOKEN']
13
+ )
14
+ else:
15
+ model_name = "gpt-3.5-turbo"
16
+ client = openai.Client()
17
 
18
  class Player:
19
  def __init__(self, name: str, controller: str, role: str):
 
24
 
25
  def collect_input(self, prompt: str) -> str:
26
  """Store the input and output in the messages list. Return the output."""
27
+ self.messages.append({"role": "user", "content": prompt})
28
  output = self.respond(prompt)
29
+ self.messages.append({"role": "assistant", "content": output})
30
  return output
31
 
32
  def respond(self, prompt: str) -> str:
 
35
  return input()
36
 
37
  elif self.controller == "ai":
38
+ chat_completion = client.chat.completions.create(
39
+ model=model_name,
40
+ messages=self.messages,
41
+ stream=False,
42
+ )
43
+
44
+ return chat_completion.choices[0].message.content
45
+
46
 
47
  def add_message(self, message: str):
48
  """Add a message to the messages list. No response required."""
49
+ self.messages.append({"role": "user", "content": message})
50
 
51
 
52