File size: 1,863 Bytes
89a513c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
import requests
import json


def generate(query, model="reka-core", system_prompt="Be Helpful and Friendly. Keep your response straightfoward, short and concise", use_search_engine=False, use_code_interpreter=False):
# Define the request URL
    api_endpoint = "https://chat.reka.ai/api/chat"

    access_token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjlkbnNsSDdfZlJNNWRXNkFlc1piSiJ9.eyJpc3MiOiJodHRwczovL2F1dGgucmVrYS5haS8iLCJzdWIiOiJnb29nbGUtb2F1dGgyfDExNDMxMzYxMTUyMDY1OTgxNTAxOSIsImF1ZCI6WyJodHRwczovL2FwaS5yZWthLmFpIiwiaHR0cHM6Ly9wcm9kdWN0aW9uLXJla2EtYWkuZXUuYXV0aDAuY29tL3VzZXJpbmZvIl0sImlhdCI6MTcxNDA1Mzc0NCwiZXhwIjoxNzE0MTQwMTQ0LCJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGVtYWlsIG9mZmxpbmVfYWNjZXNzIiwiYXpwIjoiYmFxNFExOG9Tc0JpV053RGFOQzRtNWhmZ1FHd1V1cE0ifQ.WwExsvIaCc9hxif6l9syUtdjUQI7CUGttXihxIqaDDRQunTF_nK3Ng4QhsGImQKcdZZ608PAGnjdaLeB-5qsocqgovR4Kr9UxuLB4rQ0JtbsrPcCJi3gqFCtfx23-HO8RdrTzmXqd1PVhQTIIX6e65Mg84bgqG_KvHTnRe34yqUIcRsL2DIApk3yl7FrQHOLMaIJ-qjrvcLRVPcpCPUHj_uP5rh63haikt9dRKogSPQiuHPkoHOjGBU1LpYuAMSJZZC2lAM7OV7gFqgB5xvDn9zFSSuUSq0MYhvzl7Vlpg9MZ1dcL79w5m1OitWClXXpt9oqE2TiJgx6eGkUUx_aqw"

    # Define the headers
    headers = {
        "Authorization": f"Bearer {access_token}",
    }

    payload = {

        "conversation_history": [
            {"type": "human", "text": f"## SYSTEM PROMPT: {system_prompt}\n\n## QUERY: {query}"},
        ],

        "stream": False,
        "use_search_engine": use_search_engine,
        "use_code_interpreter": use_code_interpreter,
        "model_name": model,
        # "model_name": "reka-flash",
        # "model_name": "reka-edge",
    }

    # Make the POST request
    response = requests.post(api_endpoint, headers=headers, json=payload)

    # Print the response content (if needed)
    try: return json.loads(response.content)['text'].strip()
    except Exception as e: return f"Error: {e}"