File size: 1,112 Bytes
af23ed2 a158524 af23ed2 a583c19 a158524 af23ed2 a583c19 af23ed2 a583c19 af23ed2 a158524 af23ed2 |
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 |
import requests
import os
from emotion_filter import rewrite_with_persona
# NIMOモデル(指示応答型)
API_URL = "https://api-inference.huggingface.co/models/rinna/japanese-gpt-neox-3.6b-instruction-ppo"
API_TOKEN = os.getenv("neko")
headers = {
"Authorization": f"Bearer {API_TOKEN}"
}
def call_external_api(input_text):
try:
payload = {
"inputs": input_text,
"parameters": {
"max_new_tokens": 160,
"temperature": 0.8,
"do_sample": True,
"repetition_penalty": 1.2
}
}
response = requests.post(API_URL, headers=headers, json=payload, timeout=30)
response.raise_for_status()
generated = response.json()
if isinstance(generated, list) and "generated_text" in generated[0]:
raw_text = generated[0]["generated_text"]
return rewrite_with_persona(raw_text, emotion="gentle")
else:
return "[API応答形式が不明です]"
except Exception as e:
return f"[Hugging Face APIエラー] {str(e)}"
|