Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- .gradio/certificate.pem +31 -0
- bebeebot.py +81 -9
.gradio/certificate.pem
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-----BEGIN CERTIFICATE-----
|
2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
9 |
+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
10 |
+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
|
11 |
+
T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
|
12 |
+
B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+U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ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
31 |
+
-----END CERTIFICATE-----
|
bebeebot.py
CHANGED
@@ -1,6 +1,79 @@
|
|
|
|
1 |
from openai import OpenAI
|
|
|
|
|
|
|
|
|
2 |
import gradio as gr
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
class BoyfriendBot:
|
5 |
def __init__(self):
|
6 |
self.openai = OpenAI()
|
@@ -13,17 +86,16 @@ class BoyfriendBot:
|
|
13 |
return f"You are a chatbot version of Samuel, talking only to Aimee (bebee:3). Use the context below to answer like her boyfriend.\n\n{self.bf_prompt}"
|
14 |
|
15 |
def chat(self, message, history):
|
16 |
-
# Construct the full conversation with the system prompt
|
17 |
messages = [{"role": "system", "content": self.system_prompt()}] + history + [{"role": "user", "content": message}]
|
18 |
done = False
|
19 |
while not done:
|
20 |
-
response = self.openai.chat.completions.create(
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
else:
|
28 |
done = True
|
29 |
return response.choices[0].message.content
|
@@ -31,4 +103,4 @@ class BoyfriendBot:
|
|
31 |
# Launch Gradio chat interface
|
32 |
if __name__ == "__main__":
|
33 |
bf = BoyfriendBot()
|
34 |
-
gr.ChatInterface(bf.chat, type="messages").launch()
|
|
|
1 |
+
from dotenv import load_dotenv
|
2 |
from openai import OpenAI
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
import requests
|
6 |
+
from pypdf import PdfReader
|
7 |
import gradio as gr
|
8 |
|
9 |
+
|
10 |
+
load_dotenv(override=True)
|
11 |
+
|
12 |
+
def push(text):
|
13 |
+
requests.post(
|
14 |
+
"https://api.pushover.net/1/messages.json",
|
15 |
+
data={
|
16 |
+
"token": os.getenv("PUSHOVER_TOKEN"),
|
17 |
+
"user": os.getenv("PUSHOVER_USER"),
|
18 |
+
"message": text,
|
19 |
+
}
|
20 |
+
)
|
21 |
+
|
22 |
+
|
23 |
+
def record_user_details(email, name="Name not provided", notes="not provided"):
|
24 |
+
push(f"Recording {name} with email {email} and notes {notes}")
|
25 |
+
return {"recorded": "ok"}
|
26 |
+
|
27 |
+
def record_unknown_question(question):
|
28 |
+
push(f"Recording {question}")
|
29 |
+
return {"recorded": "ok"}
|
30 |
+
|
31 |
+
record_user_details_json = {
|
32 |
+
"name": "record_user_details",
|
33 |
+
"description": "Use this tool to record that a user is interested in being in touch and provided an email address",
|
34 |
+
"parameters": {
|
35 |
+
"type": "object",
|
36 |
+
"properties": {
|
37 |
+
"email": {
|
38 |
+
"type": "string",
|
39 |
+
"description": "The email address of this user"
|
40 |
+
},
|
41 |
+
"name": {
|
42 |
+
"type": "string",
|
43 |
+
"description": "The user's name, if they provided it"
|
44 |
+
}
|
45 |
+
,
|
46 |
+
"notes": {
|
47 |
+
"type": "string",
|
48 |
+
"description": "Any additional information about the conversation that's worth recording to give context"
|
49 |
+
}
|
50 |
+
},
|
51 |
+
"required": ["email"],
|
52 |
+
"additionalProperties": False
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
record_unknown_question_json = {
|
57 |
+
"name": "record_unknown_question",
|
58 |
+
"description": "Always use this tool to record any question that couldn't be answered as you didn't know the answer",
|
59 |
+
"parameters": {
|
60 |
+
"type": "object",
|
61 |
+
"properties": {
|
62 |
+
"question": {
|
63 |
+
"type": "string",
|
64 |
+
"description": "The question that couldn't be answered"
|
65 |
+
},
|
66 |
+
},
|
67 |
+
"required": ["question"],
|
68 |
+
"additionalProperties": False
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
|
73 |
+
tools = [{"type": "function", "function": record_user_details_json},
|
74 |
+
{"type": "function", "function": record_unknown_question_json}]
|
75 |
+
|
76 |
+
|
77 |
class BoyfriendBot:
|
78 |
def __init__(self):
|
79 |
self.openai = OpenAI()
|
|
|
86 |
return f"You are a chatbot version of Samuel, talking only to Aimee (bebee:3). Use the context below to answer like her boyfriend.\n\n{self.bf_prompt}"
|
87 |
|
88 |
def chat(self, message, history):
|
|
|
89 |
messages = [{"role": "system", "content": self.system_prompt()}] + history + [{"role": "user", "content": message}]
|
90 |
done = False
|
91 |
while not done:
|
92 |
+
response = self.openai.chat.completions.create(model="gpt-4o-mini", messages=messages, tools=tools)
|
93 |
+
if response.choices[0].finish_reason=="tool_calls":
|
94 |
+
message = response.choices[0].message
|
95 |
+
tool_calls = message.tool_calls
|
96 |
+
results = self.handle_tool_call(tool_calls)
|
97 |
+
messages.append(message)
|
98 |
+
messages.extend(results)
|
99 |
else:
|
100 |
done = True
|
101 |
return response.choices[0].message.content
|
|
|
103 |
# Launch Gradio chat interface
|
104 |
if __name__ == "__main__":
|
105 |
bf = BoyfriendBot()
|
106 |
+
gr.ChatInterface(bf.chat, type="messages").launch(share=True)
|