Karthik Raja commited on
Commit
c440694
1 Parent(s): 9bc6407

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -7
app.py CHANGED
@@ -16,16 +16,36 @@ def load_cv():
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", "content":"You are a helpful assistant that can only answer questions about Karthik Raja"},
24
- {"role": "user", "content":"{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)
@@ -36,7 +56,7 @@ iface = gr.Interface(
36
  inputs=gr.Textbox(label="Ask a question, that you would like to ask Karthik"),
37
  outputs="text",
38
  title="AI Clone",
39
- description="Interact with an AI clone for recruiting or for fun :) "
40
  )
41
 
42
  iface.launch()
 
16
  # Extract information from the CV
17
  cv_text = load_cv()
18
 
19
+ # Initialize a history list to keep track of the conversation
20
+ history = []
21
+
22
  def chat_with_ai(user_input):
23
+ global history
24
+
25
+ # Append user message to history
26
+ history.append({"role": "user", "content": user_input})
27
+
28
+ # Limit history to the last 20 messages
29
+ if len(history) > 20:
30
+ history = history[-20:]
31
+
32
+ # Prepare the messages for the API call, including the CV text
33
+ messages = [
34
+ {"role": "system", "content": "You are Karthik Raja, and the following details are your academic and research achievements and industry experiences."},
35
+ {"role": "system", "content": cv_text}
36
+ ] + history
37
+
38
+ # Make the API call
39
  completion = client.chat.completions.create(
40
+ model="gpt-3.5-turbo",
41
+ messages=messages
 
 
 
42
  )
43
 
44
+ assistant_message = completion.choices[0].message
45
+ # Append assistant message to history
46
+ history.append(assistant_message)
47
+
48
+ return assistant_message['content']
49
 
50
  def main(user_input):
51
  response = chat_with_ai(user_input)
 
56
  inputs=gr.Textbox(label="Ask a question, that you would like to ask Karthik"),
57
  outputs="text",
58
  title="AI Clone",
59
+ description="Interact with an AI clone for recruiting or for fun :)"
60
  )
61
 
62
  iface.launch()