-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage_proficiency.py
50 lines (42 loc) · 1.6 KB
/
language_proficiency.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import openai
def understand_language_syntax(code_snippet, language):
"""
Uses an AI model to explain the syntax of a code snippet in the specified programming language.
Args:
code_snippet (str):import openai
def understand_language_syntax(code_snippet, language):
"""
Uses an AI model to explain the syntax of a code snippet in the specified programming language.
Args:
code_snippet (str): The code snippet to be explained.
language (str): The programming language of the code snippet.
Returns:
str: Explanation of the syntax of the code snippet.
"""
response = openai.Completion.create(
engine="davinci-codex",
prompt=f"Explain the syntax of the following {language} code snippet:\\n{code_snippet}",
max_tokens=150
)
return response.choices[0].text.strip()
# Example usage
code_snippet = "print('codephreak is ...')"
language = "Python"
syntax_explanation = understand_language_syntax(code_snippet, language)
print(syntax_explanation)
The code snippet to be explained.
language (str): The programming language of the code snippet.
Returns:
str: Explanation of the syntax of the code snippet.
"""
response = openai.Completion.create(
engine="davinci-codex",
prompt=f"Explain the syntax of the following {language} code snippet:\\n{code_snippet}",
max_tokens=150
)
return response.choices[0].text.strip()
# Example usage
code_snippet = "print('Hello, World!')"
language = "Python"
syntax_explanation = understand_language_syntax(code_snippet, language)
print(syntax_explanation)