File size: 1,275 Bytes
b85c00c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a0859a
 
 
 
 
 
 
b85c00c
 
 
 
 
 
 
 
 
1a0859a
b85c00c
 
 
 
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
# RESPONSE
import requests

# Define the URL
url = "https://wcza44xtt6.execute-api.us-west-2.amazonaws.com/default/llama-osu"


def new_data():
    data = {
        "inputs": [
            [
            ]
        ],
        "parameters": {
            "max_new_tokens": 500,
            "top_p": 0.9,           # if you set top p to 0.9, the model will only consider the most likely words that make up 90% of the probability mass.
            "temperature": 0.2      # creative level from 0 to 1 (the higher the more creative)
        }
    }
    return data


def func_trim_data(data):
    trimmed_data = new_data()
    trimmed_data['inputs'][0] = data['inputs'][0][-9:]

    return trimmed_data


data = new_data()
def get_response(prompt: str) -> str:
    if(prompt.lower() == 'reset'):
        global data
        data = new_data()
        return "You can start a new conversation"
    else:
        _dict = {"role": "user", "content": f"{prompt}" + " (Make your answer brief with several sentences)"}
        data["inputs"][0].append(_dict)
        response = requests.post(url, json=func_trim_data(data))
        response_dict = response.json()[0]['generation']
        data["inputs"][0].append(response_dict)

        return response.json()[0]['generation']['content']