Run this model with HF Jobs

Run RysoAI/tinyqa-1-moss on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/RysoAI/tinyqa-1-moss. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/RysoAI/tinyqa-1-moss on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
tinyqa-1-moss / code /tinyqa /server.py
RysoAI's picture
RysoAI TinyQA-1 Moss
b257ec0
Raw History Blame Contribute Delete
1.8 kB
import argparse, json, os, sys, threading, urllib.parse
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from tinyqa import pipeline as webqa
STACK = None
LOCK = threading.Lock()
KEEP = ('tier', 'lead', 'cited', 'span', 'support', 'url', 'title', 'verified_by')
class H(BaseHTTPRequestHandler):
def log_message(self, *a):
pass
def _json(self, obj, code=200):
body = json.dumps(obj, ensure_ascii=False).encode()
self.send_response(code)
self.send_header('Content-Type', 'application/json')
self.send_header('Content-Length', str(len(body)))
self.end_headers()
self.wfile.write(body)
def do_GET(self):
u = urllib.parse.urlparse(self.path)
if u.path == '/health':
return self._json({'ok': True, 'models': STACK is not None})
if u.path != '/ask':
return self._json({'error': 'not found'}, 404)
qs = urllib.parse.parse_qs(u.query)
q = qs.get('q', [''])[0].strip()
provider = qs.get('provider', ['ddgs'])[0]
if not q:
return self._json({'tier': 3, 'why': 'empty question'})
with LOCK:
out = STACK.answer(q, provider=provider)
webqa.save_caches()
self._json({k: out.get(k) for k in KEEP})
def main():
global STACK
ap = argparse.ArgumentParser()
ap.add_argument('--port', type=int, default=8091)
a = ap.parse_args()
s = webqa.Stack()
s.rank.predict([('warm up', 'warm up')], show_progress_bar=False)
s.verify.predict([('warm up', 'warm up')], show_progress_bar=False)
STACK = s
print(f'[moss] models loaded on 127.0.0.1:{a.port}', flush=True)
ThreadingHTTPServer(('127.0.0.1', a.port), H).serve_forever()
if __name__ == '__main__':
main()