bstraehle commited on
Commit
16d66ad
1 Parent(s): 03971e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -17,7 +17,7 @@
17
  import gradio as gr
18
  import openai, os, time
19
 
20
- from datetime import datetime
21
  from openai import OpenAI
22
  from utils import function_to_schema, show_json
23
 
@@ -25,10 +25,11 @@ client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
25
 
26
  assistant, thread = None, None
27
 
28
- def get_current_date():
29
- """Use to get the current date."""
30
- print(f"Current date: {datetime.now()}")
31
- return datetime.now()
 
32
 
33
  def create_assistant(client):
34
  assistant = client.beta.assistants.create(
@@ -41,7 +42,7 @@ def create_assistant(client):
41
  model="gpt-4o",
42
  tools=[
43
  {"type": "code_interpreter"},
44
- {"type": "function", "function": function_to_schema(get_current_date)},
45
  ],
46
  )
47
 
@@ -170,7 +171,7 @@ def chat(message, history):
170
  global client, assistant, thread
171
 
172
  if assistant == None:
173
- assistant = load_assistant(client)
174
 
175
  if thread == None or len(history) == 0:
176
  thread = create_thread(client)
 
17
  import gradio as gr
18
  import openai, os, time
19
 
20
+ from datetime import date
21
  from openai import OpenAI
22
  from utils import function_to_schema, show_json
23
 
 
25
 
26
  assistant, thread = None, None
27
 
28
+ def today_tool(text: str) -> str:
29
+ """Returns today's date. Use this for any questions related to knowing today's date.
30
+ The input should always be an empty string, and this function will always return today's date.
31
+ Any date mathematics should occur outside this function."""
32
+ return str(date.today())
33
 
34
  def create_assistant(client):
35
  assistant = client.beta.assistants.create(
 
42
  model="gpt-4o",
43
  tools=[
44
  {"type": "code_interpreter"},
45
+ {"type": "function", "function": function_to_schema(today_tool)},
46
  ],
47
  )
48
 
 
171
  global client, assistant, thread
172
 
173
  if assistant == None:
174
+ assistant = create_assistant(client)
175
 
176
  if thread == None or len(history) == 0:
177
  thread = create_thread(client)