import requests import os # Hugging Face APIエンドポイントと認証トークン api_url = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2" headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"} # クエリのメッセージ payload = { "inputs": "Which of the depicted countries has the best food?", "parameters": {"max_new_tokens": 512} } # APIリクエスト response = requests.post(api_url, headers=headers, json=payload) # 結果表示 if response.status_code == 200: print("Response:", response.json()) else: print(f"Error {response.status_code}: {response.text}")