File size: 785 Bytes
2b31c7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests


def validate(token: str):
    api_endpoint = "https://api.openai.com/v1/chat/completions"
    api_key = token

    headers = {
        "Content-Type" : "application/json",
        "Authorization": f"Bearer {api_key}"
    }

    messages = [
        {"role": "user", "content": "Say this is a test!"}
    ]

    data = {
        "model": "gpt-3.5-turbo",
        "messages": messages
    }

    response = requests.post(api_endpoint, json=data, headers=headers)
    return response

def create_index(model):
    index = model.initialize_index("bloomLlama")
    return index

def get_response(vector_index, query_str):
    print("query_str: ", query_str)
    query_engine = vector_index.as_query_engine()
    response = query_engine.query(query_str)
    return response