Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,7 @@
|
|
17 |
import gradio as gr
|
18 |
import openai, os, time
|
19 |
|
20 |
-
from datetime import
|
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
|
29 |
-
"""Use to
|
30 |
-
|
31 |
-
|
|
|
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(
|
45 |
],
|
46 |
)
|
47 |
|
@@ -170,7 +171,7 @@ def chat(message, history):
|
|
170 |
global client, assistant, thread
|
171 |
|
172 |
if assistant == None:
|
173 |
-
assistant =
|
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)
|