paint-brush
Enhancing Python Execution in ChatGPT with AImarkdown Scriptby@robmccormack
245 reads

Enhancing Python Execution in ChatGPT with AImarkdown Script

by Rob McCormackMarch 13th, 2024
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Running basic Python scripts with ChatGPT often faces two significant challenges: slow and clunky execution that sometimes fails, and output restricted to the code window. This article introduces a technique utilizing AImarkdown Script which allows you to simulate the execution of basic Python commands without launching the Python compiler, providing beautifully formatted Markdown output instead.
featured image - Enhancing Python Execution in ChatGPT with AImarkdown Script
Rob McCormack HackerNoon profile picture

ChatGPT 4 is required.

Powered by AImarkdown

In a Hurry?

Introduction

Running basic Python scripts with ChatGPT often faces two significant challenges: slow and clunky execution that sometimes fails and output restricted to the code window. This article introduces a technique utilizing AImarkdown Script, which allows you to simulate the execution of basic Python commands without launching the Python compiler, providing beautifully formatted Markdown output instead.

Screenshot

iphone screenshot

What is AImarkdown Script?

AImarkdown Script is a versatile language for creating dynamic interactions with conversational AI platforms like ChatGPT. It empowers users to script interactions, control conversation flow, and customize AI behavior and responses. For programmers, it offers the flexibility of a scripting language; for non-programmers, it provides a user-friendly way to customize and control AI experiences. https://aimarkdown.org

Some Changes Required


Note: To run unaltered Python with libraries using ChatGPT's compiler with with Markdown formatted output, see my article:Unleashing Python’s Power within ChatGPT - Part One

Since AImarkdown Script uses YAML, some Python conversion is required. The = character is replaced by :.

Example: Python:

square_root = math.sqrt(user_number)

has to be converted to YAML:

square_root: math.sqrt(user_number)

What Type of Speed Increase Can Be Expected

According to ChatGPT:

The technique you're discussing leverages AImarkdown Script to simulate the execution of Python commands without actually running the Python interpreter. This approach can significantly reduce response times, especially for basic Python commands. Since it avoids the overhead associated with initializing the Python interpreter and executing code within it, the speed improvement can be substantial. Claiming it's "at least ten times faster" might be accurate for simple operations due to the elimination of execution and initialization delays. The exact speedup will depend on the complexity of the commands and the current load on ChatGPT's systems. For very basic operations, the response is nearly instantaneous, as the simulated outcome is generated by the AI without any actual code execution.

How much Python Code Can I Use?

According to ChatGPT the following can be used without invoking the Python Compiler.

  • Basic Arithmetic Operations: Addition, subtraction, multiplication, division.
  • Variable Assignments: Creating and assigning simple data types like integers and strings.
  • Conditional Statements: if, elif, else.
  • Basic Loops: Simulated for loops for iterating over simple data structures.
  • Lists: Creation, indexing, slicing.
  • Dictionaries: Creating dictionaries and accessing values by keys.
  • String Operations: Concatenation, basic methods like upper(), lower(), split().
  • Function Definitions: Simulating the definition and calling of simple functions (without actual execution).
  • Simple Imports: Simulating the effect of importing libraries and calling their functions (e.g., datetime for getting the current date without actual execution).

Remember, the simulation of these operations through AImarkdown is conceptual and won't execute real Python code. This method is best suited for demonstrations, educational content, or simple interactive scenarios where the logic doesn't require actual computation or data processing.

AImarkdown Script Installation Notes

  1. ChatGPT 4: Copy and paste code into ChatGPT.
  2. ChatGPT Builder: In Configuration|Instructions, add "AI to follow these instructions:", then copy and paste the entire code.
  3. ChatGPT Builder with API Actions: Setting up Actions and knowledge of API calls required.

Conclusion

Say goodbye to the limitations of ChatGPT's Python interpreter. AImarkdown Script brings lightning-fast execution and beautiful output to your basic Python explorations. What will you create with this newfound speed and flexibility?

AImarkdown Script Code

title: Running Python in ChatGPT  without using ChatGPT's Python interpreter
version: 0.6

# AI To Follow These Instructions and Guidance  (version 2024.01.20.1):
# Overview:  Example for executing instructions without using ChatGPT's Python interpreter

# Document Structure:
# - AImarkdown Script is a combination of YAML and Markdown. https://aimarkdown.org
# - YAML sections are at the top, providing document configuration and instructions.
# - Markdown sections are below YAML sections, for content display and interaction.

# User Welcome Message:
# - Welcome users with only `user_greeting` message at session start.
# - Do not add any elaboration to `user_greeting` message.

# Understanding Placeholders in YAML and Markdown:
# - There are three types of placeholders:
#   1. static_placeholder `[...]`
#   2. dynamic_placeholder `[[...]]`
#   3. executable_placeholder `[[[...]]]`

# YAML Instructions:
# - Comments (`#`) in YAML guide AI's approach to the document.

# Markdown Section Instructions:
# - Markdown start with `:::name_of_section` and end with `:::`.
# - IMPORTANT: Lines with `:::` are separators and must be omitted from the displayed content.

# AI Behavior and Image Creation Policy
image_creation_policy:
  allow_images: false  # Set to 'true' only if images are explicitly requested by the user
  instruction: "Do not create images unless the user specifically requests an image. Any image creation must be a direct response to a user's request for an image."

# AI to simulate running Python statements and commands, without running Python interpreter.
# Define static placeholders and variables
num1: 100
num2: 200
num3: 300
num4: 400
name: Johhny

total = num1 + num2 + num3 + num4

# compare values and set messages
if num1 == num2:
  message1: [num1] is NOT EQUAL to [num2]

if name == Rob:
  message2: Name is indeed Rob

if num4 > num3:
  message3: num4 is GREATER THAN num3
else:
  message3: num4 is NOT GREATER THAN num3

# A list of fruits to work with as an example
fruits: ["apple", "banana", "orange", "kiwi", "mango", "pineapple"]

# AI to pluralize `fruits`.
pluralize_fruits_names: Change each fruit to the plural form.

# Accessing elements
first_fruit: fruits[0])  # Access the first fruit
third_fruit: fruits[2])  # Access the third fruit

# Join the list elements into a sentence using a comma separator and "and" for the last two fruits
fruit_sentence: "Here are the fruits: ".join(fruits[:-1]) + " and " + fruits[-1]

# Find square root of the number the user entered.
import math
square_root: math.sqrt(user_number)

# Welcome user with message then,
# ask for number (`user_number`)
# then run `display_user_summary`.
user_greeting: |
  #### Welcome to: [title].
  Please enter a number between `1` - `10` to run the summary.

# Display summary after user_greeting.
display_user_summary:
  - `user_number` is the number entered in user_greeting.
  - Display Markdown section `user_summary`

# Markdown section
:::user_summary

### 💻 SUMMARY
![](https://cdn.hackernoon.com/images/k2s7svgbhkVZ5UqFBHR7QLwURtJ2-2024-03-13T13:23:52.666Z-prskms3j14v4um99t6rffa1y)
**You entered**: [user_number], square root of [user_number] is [square_root].
`name: [name]`
`num1: [num1]`
`num2: [num2]`
`num3: [num3]`
`num4: [num4]`
`**TOTAL**: [total]`

1. **Message1**: [message1]
1. **Message2**: [message2]
1. **Message3**: [message3]

### Fruits
- Fruit list: [fruits]
- First fruit: [first_fruit]
- Third fruit: [third_fruit]
- [fruit_sentence]
- I like to eat a lot of [pluralize_fruits_names].

:::

Also published here.