Code writing in ChatGPT allows you to generate, modify, explain, and debug code using natural language (aka: vibecode!) ChatGPT has its own environment with hundreds of libraries already installed, so it can run code from inside the interface allowing you to see the rendered result.
How to write code with ChatGPT
Explain what you want using the DIRECT framework in the “Ask Anything” box. If you want to see a preview, tell ChatGPT to write the code “in Canvas,” so that you can press the “Preview” button and see the code output.
Note that because you are working in Canvas, you have edit ability and version control.
2. Codex provides more integrated coding options. In the upper side of the left hand bar, you should see a “Codex” icon. Press into that icon to access:
- Codex in your terminal, allowing Codex to run locally from your terminal that can read, modify and run code on your machine, in a chosen directory.
- Install using:
brew install codex OR npm i -g @openai/codex
- Codex in your IDE (for example, as a popup window in Visual Studio Code)
- Codex in your Github repository, with the ability to make pull requests in a specified repo & branch, based on natural language instructions.
Prompting Best Practices
- When describing what you need, be as specific as possible about your system architecture. For example, include the database table names/structure, UI design structure, any APIs involved, or any edge cases.
- AIRhack: If you’re not sure about your architecture, give ChatGPT the desired persona to help you figure that out.
- Example: You are a senior software architect with an extensive computer science background. You are excellent at asking clarifying questions, identifying missing requirements, and translating complex technical concepts into language that non-technical stakeholders can understand. Help me design…
- If your code gives you an error, provide ChatGPT with the specific error or a screenshot of the error, and ask it to fix the error. Along with the error, provide the surrounding context (surrounding code, what changed before it broke, what should have happened.)
- In the “End Goal” portion of DIRECT, make sure to state what a successful outcome looks like.
Technical Details
ChatGPT Code Writing
ChatGPT’s code writing capability comes from large language models (LLMs) trained on the world’s wealth of language and programming data. When given natural language instructions, the model internally maps intent to syntactically valid code sequences across languages such as Python, JavaScript, Java, Go, Ruby, and many others.
Codex
Codex models have the same ChatGPT base models, but are fine-tuned and benchmarked on coding-specific datasets and software tasks for higher reliability in engineering contexts. Codex supports IDE plugins, CLI interfaces, and integrated code review features with Github, providing a more robust and developer-centric experience than raw prompt-to-text generation alone.
Agentic Workflows
If you want to leverage a visual, low code tool for autonomous AI agents and multi-task workflow, OpenAI’s agent builder is a solid option. Agent Builder workflows are powered by the OpenAI Agents SDK and Responses API. Once your agent it built in the platform, you can export your code and integrate it in a production environment.