trustgraph/test-api

69 lines
1.3 KiB
Text
Raw Normal View History

2024-11-20 16:57:46 +00:00
#!/usr/bin/env python3
import requests
import json
import sys
url = "http://localhost:8088/api/v1/"
############################################################################
input = {
"system": "Respond in French. Use long word, form of numbers, no digits",
# "prompt": "Add 2 and 12"
"prompt": "Add 12 and 14, and then make a poem about llamas which incorporates that number. Then write a joke about llamas"
}
resp = requests.post(
f"{url}text-completion",
json=input,
)
2024-11-20 17:44:00 +00:00
resp = resp.json()
if "error" in resp:
print(f"Error: {resp['error']}")
sys.exit(1)
print(resp["response"])
2024-11-20 16:57:46 +00:00
############################################################################
input = {
"id": "question",
"variables": {
2024-11-20 17:44:00 +00:00
"question": "Write a joke about llamas."
2024-11-20 16:57:46 +00:00
}
}
resp = requests.post(
f"{url}prompt",
json=input,
)
2024-11-20 17:44:00 +00:00
if "error" in resp:
print(f"Error: {resp['error']}")
sys.exit(1)
print(resp["response"])
2024-11-20 16:57:46 +00:00
2024-11-20 17:44:00 +00:00
sys.exit(0)
2024-11-20 16:57:46 +00:00
############################################################################
input = {
"id": "extract-definitions",
"variables": {
"text": "A cat is a large mammal."
}
}
resp = requests.post(
f"{url}prompt",
json=input,
)
print(json.dumps(resp.json()["object"], indent=4))
############################################################################