Karthik Raja commited on
Commit
f8d30bb
1 Parent(s): 490ea32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -1,6 +1,9 @@
1
  import gradio as gr
2
  import openai
3
  import os
 
 
 
4
 
5
  # Load your OpenAI API key from the environment variable
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
@@ -13,18 +16,16 @@ def load_cv():
13
  # Extract information from the CV
14
  cv_text = load_cv()
15
 
16
- def chat_with_ai(user_input):
17
- messages = [
18
- {"role": "system", "content": "You are a helpful assistant that can only answer questions about Karthik Raja"},
19
- {"role": "user", "content": f"{cv_text}\n\nUser: {user_input}"}
20
- ]
21
-
22
- response = openai.ChatCompletion.create(
23
- model="gpt-3.5-turbo",
24
- messages=messages
25
  )
26
 
27
- return response.choices[0].message['content']
28
 
29
  def main(user_input):
30
  response = chat_with_ai(user_input)
 
1
  import gradio as gr
2
  import openai
3
  import os
4
+ from openai import OpenAI
5
+
6
+ client = OpenAI()
7
 
8
  # Load your OpenAI API key from the environment variable
9
  openai.api_key = os.getenv("OPENAI_API_KEY")
 
16
  # Extract information from the CV
17
  cv_text = load_cv()
18
 
19
+ def chat_with_ai(user_input):
20
+ completion = client.chat.completions.create(
21
+ model="gpt-3.5-turbo",
22
+ messages=[
23
+ {"role": "system", "You are a helpful assistant that can only answer questions about Karthik Raja"},
24
+ {"role": "user", "{cv_text}\n\nUser: {user_input}"}
25
+ ]
 
 
26
  )
27
 
28
+ return completion.choices[0].message
29
 
30
  def main(user_input):
31
  response = chat_with_ai(user_input)