tharun1507 commited on
Commit
1f50c88
·
verified ·
1 Parent(s): 5a6af41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -11,9 +11,26 @@ def get_completion(code_snippet):
11
  try:
12
  python_code_examples = """
13
  ---------------------
14
- Example 1: x = 10 ... (Your code examples here)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  ---------------------
16
  """
 
17
  prompt = f"""
18
  Your task is to explain the following code snippet step-by-step:
19
  {python_code_examples}
@@ -22,13 +39,14 @@ def get_completion(code_snippet):
22
  ```
23
  """
24
 
25
- # Generate content using the new API method
26
- response = genai.generate_content(
27
  prompt=prompt,
28
  temperature=0,
29
  max_output_tokens=500,
30
  )
31
- return response.text
 
32
 
33
  except Exception as e:
34
  # Return the error message
 
11
  try:
12
  python_code_examples = """
13
  ---------------------
14
+ Example 1: x = 10
15
+ def foo():
16
+ global x
17
+ x = 5
18
+ foo()
19
+ print(x)
20
+ Correct output: 5
21
+ Code Explanation: The global keyword modifies the global variable x to be 5.
22
+ ---------------------
23
+ Example 2: def modify_list(input_list):
24
+ input_list.append(4)
25
+ input_list = [1, 2, 3]
26
+ my_list = [0]
27
+ modify_list(my_list)
28
+ print(my_list)
29
+ Correct output: [0, 4]
30
+ Code Explanation: Appending 4 modifies the input_list but does not affect the original my_list.
31
  ---------------------
32
  """
33
+
34
  prompt = f"""
35
  Your task is to explain the following code snippet step-by-step:
36
  {python_code_examples}
 
39
  ```
40
  """
41
 
42
+ # Use the correct API method to generate text
43
+ response = genai.generate_text(
44
  prompt=prompt,
45
  temperature=0,
46
  max_output_tokens=500,
47
  )
48
+
49
+ return response.result # Access the result of the response
50
 
51
  except Exception as e:
52
  # Return the error message