Spaces:
Runtime error
Runtime error
Zwea Htet
commited on
Commit
•
2b31c7d
1
Parent(s):
ef2a3f4
add utils
Browse files- utils/util.py +33 -0
utils/util.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
|
4 |
+
def validate(token: str):
|
5 |
+
api_endpoint = "https://api.openai.com/v1/chat/completions"
|
6 |
+
api_key = token
|
7 |
+
|
8 |
+
headers = {
|
9 |
+
"Content-Type" : "application/json",
|
10 |
+
"Authorization": f"Bearer {api_key}"
|
11 |
+
}
|
12 |
+
|
13 |
+
messages = [
|
14 |
+
{"role": "user", "content": "Say this is a test!"}
|
15 |
+
]
|
16 |
+
|
17 |
+
data = {
|
18 |
+
"model": "gpt-3.5-turbo",
|
19 |
+
"messages": messages
|
20 |
+
}
|
21 |
+
|
22 |
+
response = requests.post(api_endpoint, json=data, headers=headers)
|
23 |
+
return response
|
24 |
+
|
25 |
+
def create_index(model):
|
26 |
+
index = model.initialize_index("bloomLlama")
|
27 |
+
return index
|
28 |
+
|
29 |
+
def get_response(vector_index, query_str):
|
30 |
+
print("query_str: ", query_str)
|
31 |
+
query_engine = vector_index.as_query_engine()
|
32 |
+
response = query_engine.query(query_str)
|
33 |
+
return response
|