File size: 1,530 Bytes
aae4949
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
import requests


class Completion:
    @staticmethod
    def create(prompt: str):
        """
        Creates a completion by sending a POST request to a remote server.

        Args:
            prompt (str): The prompt string to be sent for completion.

        Returns:
            str: The completion generated by the server.

        Raises:
            Exception: If unable to fetch the response from the server.
        """
        headers = {
            "Origin": "https://chatllama.baseten.co",
            "Referer": "https://chatllama.baseten.co/",
            "Accept": "application/json, text/plain, */*",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "en-US,en;q=0.9",
            "Content-Length": "17",
            "Content-Type": "application/json",
            "Sec-Ch-Ua": '"Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"',
            "Sec-Ch-Ua-Mobile": "?0",
            "Sec-Ch-Ua-Platform": "Windows",
            "Sec-Fetch-Dest": "empty",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Site": "cross-site",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
        }
        r = requests.post(
            "https://us-central1-arched-keyword-306918.cloudfunctions.net/run-inference-1",
            headers=headers,
            json={"prompt": prompt},
        ).json()
        try:
            return r["completion"]
        except:
            raise Exception("Unable to fetch the response.")