Spaces:
Running
Running
marcellopoliti
commited on
Commit
•
972d86d
1
Parent(s):
fdbd104
add askbrian from brian api
Browse files- pages/ask_brian.py +31 -0
pages/ask_brian.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
|
4 |
+
api_key = st.secrets["BRIAN_API_KEY"]
|
5 |
+
|
6 |
+
|
7 |
+
def send_post_request(prompt, kb):
|
8 |
+
url = " https://api.brianknows.org/api/v0/agent/knowledge"
|
9 |
+
data = {"prompt": prompt, "kb": kb}
|
10 |
+
headers = {
|
11 |
+
"Content-Type": "application/json",
|
12 |
+
"X-Brian-Api-Key": api_key, # Include the API key in the headers
|
13 |
+
}
|
14 |
+
|
15 |
+
response = requests.post(url, json=data, headers=headers)
|
16 |
+
|
17 |
+
if response.status_code == 200:
|
18 |
+
return response.json() # Returns the JSON response if successful
|
19 |
+
else:
|
20 |
+
return (
|
21 |
+
response.status_code,
|
22 |
+
response.text,
|
23 |
+
) # Returns the status code and error if not successful
|
24 |
+
|
25 |
+
|
26 |
+
# Example usage:
|
27 |
+
kb_name = st.text_input(label="kb_name")
|
28 |
+
query = st.text_input(label="query")
|
29 |
+
if st.button("askbrian"):
|
30 |
+
result = send_post_request(query, kb_name)
|
31 |
+
st.json(result)
|