tharun1507 commited on
Commit
4931468
·
verified ·
1 Parent(s): ef6f7d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -1,10 +1,11 @@
1
  # -*- coding: utf-8 -*-
 
2
  import gradio as gr
3
  import openai
4
  import os
5
 
6
  # Configure the OpenAI API key
7
- openai.api_key = os.getenv('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') # Ensure your API key is set in environment variables
8
 
9
  def get_completion(code_snippet):
10
  # Code examples to illustrate the output
@@ -43,12 +44,13 @@ def get_completion(code_snippet):
43
  """
44
 
45
  try:
46
- completion = openai.ChatCompletion.create(
 
47
  model="gpt-3.5-turbo", # Specify the model
48
  messages=[{"role": "user", "content": prompt}],
49
  max_tokens=500
50
  )
51
- return completion.choices[0].message['content']
52
  except Exception as e:
53
  return f"An error occurred: {str(e)}"
54
 
 
1
  # -*- coding: utf-8 -*-
2
+
3
  import gradio as gr
4
  import openai
5
  import os
6
 
7
  # Configure the OpenAI API key
8
+ openai.api_key = os.getenv('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') # Ensure your API key is set in environment variables
9
 
10
  def get_completion(code_snippet):
11
  # Code examples to illustrate the output
 
44
  """
45
 
46
  try:
47
+ # Updated to use openai.ChatCompletion.create
48
+ response = openai.ChatCompletion.create(
49
  model="gpt-3.5-turbo", # Specify the model
50
  messages=[{"role": "user", "content": prompt}],
51
  max_tokens=500
52
  )
53
+ return response['choices'][0]['message']['content']
54
  except Exception as e:
55
  return f"An error occurred: {str(e)}"
56