| 232 | |
| 233 | |
| 234 | def HuggingfaceAPI(input_query: str): |
| 235 | model_id = "gpt-neox-20b" |
| 236 | API_TOKEN = "YOUR_API_TOKEN" |
| 237 | API_URL = "https://api-inference.huggingface.co/models/{model_id}".format( |
| 238 | model_id=model_id |
| 239 | ) |
| 240 | headers = {"Authorization": f"Bearer {API_TOKEN}".format(API_TOKEN=API_TOKEN)} |
| 241 | |
| 242 | def query(payload): |
| 243 | data = json.dumps(payload) |
| 244 | response = requests.request("POST", API_URL, headers=headers, data=data) |
| 245 | return json.loads(response.content.decode("utf-8")) |
| 246 | |
| 247 | data = query(input_query) |
| 248 | return data[0]["generated_text"] |
| 249 | |
| 250 | |
| 251 | """ |