|
|
|
|
|
|
|
|
|
import requests |
|
import json |
|
import time |
|
|
|
|
|
API_URL = "https://api-inference.huggingface.co/models/chendren/deepseek-dnd-lora" |
|
headers = { |
|
"Content-Type": "application/json", |
|
|
|
"Authorization": "Bearer YOUR_API_TOKEN" |
|
} |
|
|
|
|
|
test_prompts = [ |
|
"Create a D&D character with the following details: Race: Half-Elf, Class: Bard, Background: Entertainer", |
|
"Design a D&D adventure hook set in a dark forest", |
|
"Create a magical item for D&D 5e that would be suitable for a level 5 rogue", |
|
"Write a description for a fantasy tavern in a D&D setting" |
|
] |
|
|
|
def query(payload): |
|
""" |
|
Send a query to the Hugging Face API |
|
""" |
|
response = requests.post(API_URL, headers=headers, json=payload) |
|
|
|
if response.status_code == 503: |
|
|
|
print("Model is loading. Waiting...") |
|
time.sleep(20) |
|
return query(payload) |
|
|
|
return response.json() |
|
|
|
|
|
for i, prompt in enumerate(test_prompts): |
|
print(f"\n==== Test Prompt {i+1} ====") |
|
print(prompt) |
|
print("\n==== Response ====") |
|
|
|
|
|
full_prompt = f"You are a Dungeons & Dragons assistant. {prompt}" |
|
|
|
|
|
payload = { |
|
"inputs": full_prompt, |
|
"parameters": { |
|
"max_new_tokens": 500, |
|
"temperature": 0.7, |
|
"top_p": 0.9, |
|
"top_k": 50, |
|
"repetition_penalty": 1.1, |
|
"do_sample": True |
|
} |
|
} |
|
|
|
try: |
|
result = query(payload) |
|
print(json.dumps(result, indent=2)) |
|
except Exception as e: |
|
print(f"Error: {e}") |
|
|
|
print("\n" + "="*50) |
|
|
|
|
|
time.sleep(3) |
|
|
|
print("\nTesting complete!") |