filmov
tv
Python code, uses chat gpt and API documentation and turns it into a python file and executes it.

Показать описание
from dotenv import load_dotenv
import openai
import subprocess
import os
from api_documentation import api_documentation
def generate_code(prompt: str):
model='text-davinci-003',
prompt=prompt,
temperature=0.7,
max_tokens=300,
top_p=1,
frequency_penalty=0,
presence_penalty=0.6,
stop=['human:', 'AI:']
)
return response['choices'][0]['text']
def create_and_execute_file(code: str, filename: str):
with open(filename, 'w') as f:
load_dotenv()
conversation1 = "Knowing the following api documentation " + api_documentation + "What programs can you write"
conversation2 = "Knowing the following api documentation " + api_documentation + "generate a python file that does " \
"the following "
while True:
possible_programs = generate_code(conversation1)
print(possible_programs)
ask = input('What do you want your python file to do:')
conversation2 += ask
code = generate_code(conversation2)
print('Proposed code: ' + code)
confirm = input('Do you accept the code? (yes/no)')
filename = input("Enter the file name: ")
create_and_execute_file(code, filename)
break
continue
###############################################
###############################################
###############################################
###############################################
###############################################
api_documentation = """1. Public APIs
Get a list of any or all public APIs currently cataloged in the project.
Sample API URL:
2. Cat Facts
Get random cat facts via text message every day.
Sample API URL:
3. CoinDesk
View the Bitcoin Price Index (BPI) in real-time.
Sample API URL:
4. Bored
Bored is a free API to find something to do by getting suggestions for random activities.
Sample API URL:
Predict the age of a person based on their name.
Sample API URL:
Predict the gender of a person based on their name.
Sample API URL:
Predict the nationality of a person based on their name.
Sample API URL:
8. Data USA
Get US public data (e.g., population data, etc.).
Sample API URL:
9. Dogs
Cheer yourself up with random dog images.
Sample API URL:
10. IPify
IPify is a free API that allows you to get your current IP address.
Sample API URL:
11. IPinfo
Get information about a specified IP address, such as geological info, company, and carrier name.
Sample API URL:
12. Jokes
Get random jokes. You can also get jokes according to type (e.g., programming jokes only).
Sample API URL:
13. RandomUser
Get information about a random fake user, including gender, name, email, address, etc.
Sample API URL:
14. Universities List
Get a list of universities in a specified country.
Sample API URL:
15. Zippopotam
Get information about a specified ZIP code.
Sample API URL: