sandeepmhaske commited on
Commit
056f594
·
verified ·
1 Parent(s): 977fe80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -1
app.py CHANGED
@@ -3,8 +3,35 @@ import os
3
  from openai import OpenAI
4
  from dotenv import load_dotenv, find_dotenv
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  def greet(name):
7
- return name
8
 
9
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
10
  iface.launch()
 
3
  from openai import OpenAI
4
  from dotenv import load_dotenv, find_dotenv
5
 
6
+ _ = load_dotenv(find_dotenv()) # read local .env file
7
+ os.environ['OPENAI_API_KEY'] = "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"
8
+ client = OpenAI()
9
+
10
+ # account for deprecation of LLM model
11
+ import datetime
12
+ # Get the current date
13
+ current_date = datetime.datetime.now().date()
14
+
15
+ # Define the date after which the model should be set to "gpt-3.5-turbo"
16
+ target_date = datetime.date(2024, 6, 12)
17
+
18
+ # Set the model variable based on the current date
19
+ if current_date > target_date:
20
+ llm_model = "gpt-3.5-turbo"
21
+ else:
22
+ llm_model = "gpt-3.5-turbo-0301"
23
+
24
+ def get_completion(prompt, model=llm_model):
25
+ messages = [{"role": "user", "content": prompt}]
26
+ response = client.chat.completions.create(
27
+ model=model,
28
+ messages=messages,
29
+ temperature=0,
30
+ )
31
+ return response.choices[0].message.content
32
+
33
  def greet(name):
34
+ return get_completion(name)
35
 
36
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
37
  iface.launch()