# 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']