Created
January 11, 2024 15:42
-
-
Save crakdelpol/052fd8e50c1d5bc8bb0e09868209409f to your computer and use it in GitHub Desktop.
translate code from one language to another with chatgpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dir_path = '/home/gigi/project' | |
def translate(): | |
for path, currentDirectory, files in os.walk(dir_path): | |
for file in files: | |
f = os.path.join(path, file) | |
if f.endswith('.php'): | |
# print(f"working on {f}") | |
file = open(f, "r") | |
content = file.read() | |
print(get_completion("translate this code to italian \n" + content)) | |
print("I am done!") | |
def get_completion(prompt, model="gpt-3.5-turbo-16k"): | |
openai.api_key = "your-api-key" | |
messages = [{"role": "user", "content": prompt}] | |
response = openai.ChatCompletion.create(model=model,messages=messages,temperature=0) | |
return response.choices[0].message["content"] | |
if __name__ == '__main__': | |
translate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment