steveagi commited on
Commit
f3bdb49
·
1 Parent(s): 5434ea5

connect to hf

Browse files
games/angrybirds/angrybirds.py CHANGED
@@ -4,7 +4,7 @@ from collections import Counter
4
 
5
  import openai
6
  from games.game import game
7
- from games.game_openai import api_key
8
  from games.angrybirds.config import config
9
 
10
  debug = 2
@@ -14,7 +14,7 @@ class angrybird (game):
14
  data_version = ai_version
15
 
16
  def __init__(self):
17
- openai.api_key = api_key
18
  self.ROOT = Path(__file__).parent.parent.parent
19
  self.PATH = self.__class__.__name__
20
  self.embeddings = {}
 
4
 
5
  import openai
6
  from games.game import game
7
+ # from games.game_openai import api_key
8
  from games.angrybirds.config import config
9
 
10
  debug = 2
 
14
  data_version = ai_version
15
 
16
  def __init__(self):
17
+ # openai.api_key = api_key
18
  self.ROOT = Path(__file__).parent.parent.parent
19
  self.PATH = self.__class__.__name__
20
  self.embeddings = {}
games/game_openai.py DELETED
@@ -1,2 +0,0 @@
1
-
2
- api_key = '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'
 
 
 
games/game_snake.py CHANGED
@@ -6,13 +6,16 @@ from games.snake.snake import snake
6
 
7
  game = snake()
8
 
9
- def process(command: str):
10
- url = 'http://127.0.0.1:8080/nlp'
 
11
  myobj = {
12
- 'game': 'snake',
13
  'command': command,
14
  }
15
- x = requests.post(url, json=myobj)
 
 
 
16
  print(x.text)
17
 
18
  # res1, _ = game.query_entry_point(command)
 
6
 
7
  game = snake()
8
 
9
+ def process(token: str, command: str):
10
+ url = 'https://steveagi-pgtrain.hf.space/games/snake'
11
+ # url = 'http://127.0.0.1:8080/nlp'
12
  myobj = {
 
13
  'command': command,
14
  }
15
+ auth_token = token
16
+ headers = {'Authorization': f'Bearer {auth_token}'}
17
+
18
+ x = requests.post(url, json=myobj, headers=headers)
19
  print(x.text)
20
 
21
  # res1, _ = game.query_entry_point(command)
games/game_util.py CHANGED
@@ -8,9 +8,9 @@ GAME_ANGRY_BIRD = 'angrybird'
8
  GAME_SNAKE = 'snake'
9
 
10
 
11
- def nlp(game: str, command: str):
12
  if game == GAME_ANGRY_BIRD:
13
- return game_angrybird.process(command)
14
  if game == GAME_SNAKE:
15
- return game_snake.process(command)
16
  raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
 
8
  GAME_SNAKE = 'snake'
9
 
10
 
11
+ def nlp(game: str, token: str, command: str):
12
  if game == GAME_ANGRY_BIRD:
13
+ return game_angrybird.process(token, command)
14
  if game == GAME_SNAKE:
15
+ return game_snake.process(token, command)
16
  raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
games/snake/snake.py CHANGED
@@ -3,7 +3,7 @@ from pathlib import Path
3
 
4
  import openai
5
  from games.game import game
6
- from games.game_openai import api_key
7
 
8
  debug = 2
9
 
@@ -12,7 +12,7 @@ class snake (game):
12
  data_version = ai_version
13
 
14
  def __init__(self):
15
- openai.api_key = api_key
16
  self.ROOT = Path(__file__).parent.parent.parent
17
  self.PATH = self.__class__.__name__
18
  self.embeddings = {}
 
3
 
4
  import openai
5
  from games.game import game
6
+ # from games.game_openai import api_key
7
 
8
  debug = 2
9
 
 
12
  data_version = ai_version
13
 
14
  def __init__(self):
15
+ # openai.api_key = api_key
16
  self.ROOT = Path(__file__).parent.parent.parent
17
  self.PATH = self.__class__.__name__
18
  self.embeddings = {}
main.py CHANGED
@@ -10,5 +10,5 @@ async def root():
10
  return {"message": "PGAI API"}
11
 
12
  @app.post("/nlp")
13
- def test(game: str=Body(), command: str=Body()):
14
- return game_util.nlp(game, command)
 
10
  return {"message": "PGAI API"}
11
 
12
  @app.post("/nlp")
13
+ def test(game: str=Body(), token: str=Body(), command: str=Body()):
14
+ return game_util.nlp(game, token, command)