help chatgpt

Title

chatgpt -- Provides an interface that allows users to interact with GPT(Generative Pre-trained Transformer) within Stata software and receive responses about Stata.

Syntax

chatgpt [ subcommand ] [, options ]

where the subcommands can be:

subcommand Description

talk talk with GPT and receive responses.
read submit text files or data to GPT in order to gain a better understanding.
session create or modify the configuration information of a session.
test test if the commands can run, no options

Early Access

This command is currently undergoing continuous development, and the features presented in this sthlp file will be further updated as the command program is refined. We welcome you to try out this command in advance and provide valuable suggestions for the next phase of command development.

Description

chatgpt uses the API Key provided by OpenAI to create sessions, enabling users to communicate with GPT within the Stata software. To be more specific, chatgpt not only enables GPT to read technical documents related to Stata (such as ado/do/sthlp file), but it also allows users to directly chat with GPT in the Stata, with GPT's responses displayed on the Stata screen.

Addition, chatgpt also supports in-context learning, just like when users use ChatGPT on the official website(https://chat.openai.com/chat). This makes it easier to have a continuous and in-depth discussion about a Stata technical issue.

Requirements

1. Before using this command, a API key is needed.
You can get a secret key from Open AI platform(https://platform.openai.com/account/api-keys).

2. chatgpt requires Stata version 14 or higher.

3. Windows Users need to install cURL first(https://curl.se/download.html), a command-line tool and a library used for transferring data over various protocols, and set the path of cURL as an environment variable.

4. Python is required for both Windows and MacOS users.

Options for chatgpt

chatgpt base options

These options can be used in various sub-commands to configure basic settings.

option Description

stata this session is dedicated to discussing Stata topics.
openai_api_key(string) provides the credentials of the Open AI's platform to be used.
engine(string) specifies the language engine used for the session.
systemprompt(string) specifies the system prompt for the session. Appropriate system prompts help GPT better understand and answer questions.

chatgpt session options

The options of chatgpt session are used to create a session.
We recommend that you specifically use chatgpt session with base options to configure session information when you want to have multi-turn conversations with GPT, to prevent the confusion that may arise from the misuse of options.

set_session(string) creates a new session, with the parameter being the session id.

replace clears all records of the current session and creates a new session.

chatgpt talk options

command(string) specifies the prompt for GPT, and GPT will response based on the prompt.

session(string) specifies the session id to which the command belongs. If this id has not been created by chatgpt session, the command will result in an error.
When this option is used, the openai_api_key(str) option does not need to be added, as it is already bound to the session id.

proxy(string) specifies the proxy port used by the command when submitting data through the API.
This option is used when users need to access the services provided by OpenAI through a proxy server.
The option should be formatted as proxy("127.0.0.1:7890").

chatgpt read options

do(string) specifies the command to be executed by Stata and submits the execution result to GPT.
This option is only useful when using chatgpt read data.

file(string) specifies the file path to be submitted to GPT for reading.
It can be an absolute path or a relative path based on the current working path of Stata.
This option is only useful when using chatgpt read other.

command(string) is same as mentioned above.

session(string) is same as mentioned above.

proxy(string) is same as mentioned above.

Example

1. Quick Talk

`"clear"'

`"global OPENAI_API_KEY "YOUR OPENAN API KEY""'

`"chatgpt talk, openai_api_key($OPENAI_API_KEY) command("how to clearing the dataset?") stata"'

2. Session Talk

`"clear"'

`"global OPENAI_API_KEY "YOUR OPENAN API KEY""'

`"chatgpt session, openai_api_key($OPENAI_API_KEY) set_session("session_talk") stata systemprompt("Please add 'Best,\nGPT' at the end of each response") replace"'

`"chatgpt talk, command("how to clearing the dataset?") session("session_talk")"'

`"chatgpt talk, command("how to new a variable?") session("session_talk")"'

`"chatgpt talk, command("Summarizing the first two commands.") session("session_talk")"'

3. Read Ado File

`"clear"'

`"global OPENAI_API_KEY "YOUR OPENAN API KEY""'

`"ssc install psemail,replace"'

`"chatgpt read psemail.ado, openai_api_key($OPENAI_API_KEY) stata"'

4. Read Sthlp File

`"clear"'

`"global OPENAI_API_KEY "YOUR OPENAN API KEY""'

`"ssc install cntraveltime"'

`"chatgpt read cntraveltime.sthlp, openai_api_key($OPENAI_API_KEY) command("Can this command calculate the travel distance of an ocean freighter?") stata"'

5. Read Do File

`"clear"'

`"global OPENAI_API_KEY "YOUR OPENAN API KEY""'

`"chatgpt read "path/to/the/test.do", openai_api_key($OPENAI_API_KEY) stata command("Enter the question you would like to ask")"'

6. Read Other Text File

`"clear"'

`"global OPENAI_API_KEY "YOUR OPENAN API KEY""'

`"chatgpt read other, openai_api_key($OPENAI_API_KEY) stata file("path/to/the/other/textfile.txt")"'

7. Read Dataset in Stata, no do() option

`"clear"'

`"global OPENAI_API_KEY "YOUR OPENAN API KEY""'

`"sysuse auto"'

`"chatgpt read data, openai_api_key($OPENAI_API_KEY)"'

8. Read Dataset in Stata, with do() option

`"clear"'

`"global OPENAI_API_KEY "YOUR OPENAN API KEY""'

`"sysuse auto"'

`"chatgpt read data, openai_api_key($OPENAI_API_KEY) do("sum mpg,detail")"'

9. A Complete Session Conversation

`"clear"'

`"global OPENAI_API_KEY "YOUR OPENAN API KEY""'

`"sysuse auto"'

`"chatgpt session, openai_api_key($OPENAI_API_KEY) set_session("smile01") stata systemprompt("Please add 'Best,\nGPT' at the end of each response") replace"'

`"chatgpt read data, session("smile01") do("sum *,detail")"'

`"chatgpt talk, command("Which variable in the dataset best fits a normal distribution?") session("smile01")"'

`"chatgpt talk, command("How can I plot its distribution graph?") session("smile01")"'

Author

Chuntao LI

China Stata Club(爬虫俱乐部)

Wuhan, China

chtl@henu.edu.cn

Xueren Zhang

China Stata Club(爬虫俱乐部)

Wuhan, China

snowmanzhang@whu.edu.cn

Cong Nie

HongKong, China

congnie@ln.hk