Skip to content

Conversation

@yuan-alex
Copy link
Contributor

@yuan-alex yuan-alex commented Mar 3, 2023

Instead of relying on an unofficial method to access ChatGPT, this PR uses the official API to avoid potential issues or errors that might arise from using an unsupported approach.

However, this also introduces a new challenge: setting a system message. This issue was not addressed in the original paper, so I decided to use one of the system prompts that were used in ChatGPT as a baseline.

@yuan-alex
Copy link
Contributor Author

@microsoft-github-policy-service agree

@saihv
Copy link
Contributor

saihv commented Mar 5, 2023

@yuan-alex Thanks a lot for adding this integration! We have also recently started testing the API internally.

I am adding a commit with a suggestion on how the 'system' context can be set - essentially, using the first part of the current prompt as the system message, informing ChatGPT how it should act. Feel free to propose any modifications.

@yuan-alex
Copy link
Contributor Author

@saihv Hey Sai! The multi-line string for the system prompt contains both blanks and newlines. To address this, I suggest adding a new folder specifically for system prompts, which we can read from.

Also, with the new system prompt, ChatGPT responds only with the code and no code-blocks. I've pasted one of the examples below.

# Command the drone to move up 10 units

aw.takeoff() # take off the drone
current_position = aw.get_drone_position() # get current position of the drone
destination = current_position + [0, 0, -10] # add 10 to the Z coordinate
aw.fly_to(destination) # fly the drone to the new position

The new response using your system prompt is cleaner (and saves on token costs!) but it does mean we get less of an explanation from the model. The code block extraction function can be removed but I'm curious on what your take is.

@yuan-alex
Copy link
Contributor Author

Just tested combining the existing system prompt and first user prompt into one big system prompt and it performs very well. It seems like using both the first user prompts and system prompt to set instructions for ChatGPT causes some confusion and degraded performance.

@machinekoder
Copy link

Might be worth taking a look at temperature and other parameters of the official API as well. Temperature 0.0 would be most likely very appropriate for robot tasks that include generating code to make the output more deterministic.

@yuan-alex
Copy link
Contributor Author

Adding a simple response example is enough to remind ChatGPT isn't in a python shell and is supposed to respond with an explanation.

The following is an example of how you would respond:

Me: move 10 units up
You: ```python
aw.fly_to([aw.get_drone_position()[0], aw.get_drone_position()[1], aw.get_drone_position()[2]+10])
```

This code uses the `fly_to()` function to move the drone to a new position that is 10 units up from the current position. It does this by getting the current position of the drone using `get_drone_position()` and then creating a new list with the same X and Y coordinates, but with the Z coordinate increased by 10. The drone will then fly to this new position using `fly_to()`.

@machinekoder
Copy link

@yuan-alex Wouldn't it be better to package the query/response into separate user and assistant type messages with the official API?
e.g.

user: 
move 10 units up
assistant: 
"""python
aw.fly_to([aw.get_drone_position()[0], aw.get_drone_position()[1], aw.get_drone_position()[2]+10])
"""

This code uses the `fly_to()` function to move the drone to a new position that is 10 units up from the current position. It does this by getting the current position of the drone using `get_drone_position()` and then creating a new list with the same X and Y coordinates, but with the Z coordinate increased by 10. The drone will then fly to this new position using `fly_to()`.

@yuan-alex
Copy link
Contributor Author

@machinekoder I haven't encountered any significant performance improvement but I'm adding it anyways since it's been generally recommended.

@yuan-alex
Copy link
Contributor Author

@saihv Can I get a review on this PR? Looks like some folks are having issues with the current codebase because of changes to the revChatGPT proxy. Should fix #8. thanks

@machinekoder
Copy link

@yuan-alex Excellent, makes this more reproducible outside this project as well.

@saihv saihv merged commit 977e9ce into microsoft:main Mar 17, 2023
@saihv
Copy link
Contributor

saihv commented Mar 17, 2023

@yuan-alex Thanks for developing this interface! Merged.

@yuan-alex yuan-alex deleted the yuan-alex/use-official-openai-api branch March 19, 2023 22:43
@yungchentang
Copy link

yungchentang commented Nov 27, 2023

Hi @yuan-alex , thanks for your commit update; however, I still got some connection issues (WARNING:urllib3.connectionpool:Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000271F1C7E2B0>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond')': /v1/chat/completions and openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000271F1C7E670>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))), do you have any idea about this problem? thank you!

jinyoungkim927 added a commit to jinyoungkim927/PromptCraft-Robotics-Hackathon that referenced this pull request Jan 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants