0xacx / chatGPT-shell-cli

Simple shell script to use OpenAI's ChatGPT and DALL-E from the terminal. No Python or JS required.
https://gptshell.cc
MIT License
1.05k stars 150 forks source link

some escaping issue? #29

Closed dmd closed 1 year ago

dmd commented 1 year ago

Observe the return pi line, where it seems a * was expanded into the contents of my home directory.

chatgpt Sure! Here's an implementation of the Leibniz formula for calculating pi in Python:

```python
def calculate_pi():
 pi = 0
 sign = 1
 denominator = 1
 precision = 1e-10 # 10 decimal places

 while True:
 term = sign / denominator
 if abs(term) < precision:
 break
 pi += term
 sign = -sign
 denominator += 2

 return pi Applications Desktop Documents Downloads   Dropbox (Work) Dropbox (Personal) Library Movies Music Pictures Public PycharmProjects X-Plane 11 bin dotfiles go myapi sendKindle venvs 4

print(calculate_pi())

This algorithm uses an infinite series to calculate pi, adding and subtracting terms alternately to converge on the value. The precision variable determines how close the result needs to be to the true value of pi, and the loop continues until the absolute value of the next term is smaller than that precision. The result is then multiplied by 4 since the series actually calculates pi/4.

Enter a prompt:

0xacx commented 1 year ago

Fixed in #34