dylanmeca commited on
Commit
2dbae7a
·
1 Parent(s): ad97d36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -18
app.py CHANGED
@@ -9,24 +9,20 @@ class chatgpt:
9
 
10
  # Getting responses using the OpenAI API
11
  def answer_chatgpt(self, api_key, message, history):
12
- try:
13
- self.history = history or []
14
- prompt = f"{message}"
15
- self.conversation.append({"role": "user", "content": f"{prompt}"})
16
- # OPENAI API KEY
17
- openai.api_key = api_key
18
- response = openai.ChatCompletion.create(
19
- model=self.model_id,
20
- messages=self.conversation
21
- )
22
- # Displaying the answer on the screen
23
- answer = response["choices"][0]["message"]["content"]
24
- self.history.append((message, answer))
25
- self.conversation.append({'role': response.choices[0].message.role, 'content': response.choices[0].message.content})
26
- return self.history, self.history
27
- except* TypeError as error:
28
- gr.Error(f"{error.exceptions}")
29
-
30
 
31
  def Clean(self):
32
  self.history.clear()
 
9
 
10
  # Getting responses using the OpenAI API
11
  def answer_chatgpt(self, api_key, message, history):
12
+ self.history = history or []
13
+ prompt = f"{message}"
14
+ self.conversation.append({"role": "user", "content": f"{prompt}"})
15
+ # OPENAI API KEY
16
+ openai.api_key = api_key
17
+ response = openai.ChatCompletion.create(
18
+ model=self.model_id,
19
+ messages=self.conversation
20
+ )
21
+ # Displaying the answer on the screen
22
+ answer = response["choices"][0]["message"]["content"]
23
+ self.history.append((message, answer))
24
+ self.conversation.append({'role': response.choices[0].message.role, 'content': response.choices[0].message.content})
25
+ return self.history, self.history
 
 
 
 
26
 
27
  def Clean(self):
28
  self.history.clear()