Skip to content

Commit

Permalink
call gpt-4v, remove call_gpt
Browse files Browse the repository at this point in the history
  • Loading branch information
bioerrorlog committed Dec 24, 2023
1 parent 3be7c3d commit d4bcbf2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pip install -r requirements-dev.txt
# Run camera tests (require a connected camera)
pytest -m 'camera'

# Run ChatGPT API tests (Warning: The ChatGPT API will be actually called. The API Key is required.)
pytest -s -m 'chatgpt'
# Run GPT API tests (Warning: The GPT API will be actually called. The API Key is required.)
pytest -s -m 'gpt'

# Run servo moter tests (require connected servo motors)
pytest -m 'servo'
Expand Down
16 changes: 1 addition & 15 deletions robot_gpt/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,6 @@ def call_gpt4v(self) -> str:

return content

def call_gpt(self) -> str:
logger.info("Start OpenAI API call.")
logger.info(f"Prompts: {self.prompts}")
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=self.prompts
)
content = response.choices[0].message.content
logger.info(f"Response content: {content}")

self.append_prompt(Role.ASSISTANT, content)

return content

def call_and_recognize(self):
response = self.call_gpt4()
json_response = json.loads(response)
Expand All @@ -131,4 +117,4 @@ def talk(self, message: str) -> str:
self.append_prompt(Role.USER, message)
self.append_prompt(Role.SYSTEM, "You can answer in free format only once.")

return self.call_gpt()
return self.call_gpt4v()
7 changes: 3 additions & 4 deletions tests/test_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ def test_recognize(mocker):
assert last_prompt["role"] == Role.USER.value


@ pytest.mark.chatgpt
@ pytest.mark.gpt
def test_call_gpt(mocker):
"""Warning: The ChatGPT API will be actually called. The API Key is required."""
"""Warning: The GPT API will be actually called. The API Key is required."""
with RobotGPT() as robot:
mocker.patch("robot_gpt.hardware.Camera.capture_image", return_value="./outputs/captured_image.jpg")
mocker.patch("robot_gpt.hardware.recognize_objects", return_value=["skeaker", "pcmonitor", "keyboard"])
robot.recognize()

response = robot.call_gpt()
response = robot.call_gpt4v()

# Response can be parsed in JSON
json_response = json.loads(response)
Expand Down

0 comments on commit d4bcbf2

Please sign in to comment.