|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import sys |
|
import argparse |
|
|
|
try: |
|
import pollinations |
|
except ImportError: |
|
print("Module 'pollinations' not found. Install it with: pip install pollinations pollinations.ai", file=sys.stderr) |
|
sys.exit(2) |
|
|
|
def response(output): |
|
try: |
|
if hasattr(output, "text"): |
|
print(output.text) |
|
return |
|
if isinstance(output, dict) and "text" in output: |
|
print(output["text"]) |
|
return |
|
if isinstance(output, (list, tuple)): |
|
try: |
|
print("".join(map(str, output))) |
|
return |
|
except Exception: |
|
pass |
|
except Exception: |
|
pass |
|
print(str(output)) |
|
|
|
def main(): |
|
parser = argparse.ArgumentParser(description="UltimaX Intelligence") |
|
parser.add_argument("text", nargs="*", help="Helper for the user input.") |
|
parser.add_argument("--no-stream", dest="stream", action="store_false", help="Use non-streaming mode.") |
|
args = parser.parse_args() |
|
|
|
if not args.text: |
|
if sys.stdin.isatty(): |
|
print("Empty input. Request cancelled.", file=sys.stderr) |
|
sys.exit(1) |
|
input = sys.stdin.read() |
|
elif len(args.text) == 1 and args.text[0] == "-": |
|
if sys.stdin.isatty(): |
|
print("Empty input. Request cancelled.", file=sys.stderr) |
|
sys.exit(1) |
|
input = sys.stdin.read() |
|
else: |
|
input = " ".join(args.text) |
|
|
|
|
|
if not input or input.strip() == "": |
|
print("Empty input. Request cancelled.", file=sys.stderr) |
|
sys.exit(1) |
|
|
|
|
|
try: |
|
model = pollinations.Text() |
|
except Exception: |
|
print("Failed to construct default model.", file=sys.stderr) |
|
import traceback |
|
traceback.print_exc() |
|
sys.exit(1) |
|
|
|
try: |
|
if args.stream: |
|
for token in model(input, stream=True): |
|
try: |
|
if isinstance(token, (str, bytes)): |
|
print(token.decode() if isinstance(token, bytes) else token, end="", flush=True) |
|
elif isinstance(token, dict) and "text" in token: |
|
print(token["text"], end="", flush=True) |
|
elif hasattr(token, "text"): |
|
print(token.text, end="", flush=True) |
|
else: |
|
print(str(token), end="", flush=True) |
|
except Exception: |
|
print(str(token), end="", flush=True) |
|
print() |
|
else: |
|
output = model(input, stream=False) |
|
response(output) |
|
except KeyboardInterrupt: |
|
print("\nInterrupted by user.", file=sys.stderr) |
|
sys.exit(130) |
|
except Exception: |
|
print("Error while calling the model:", file=sys.stderr) |
|
import traceback |
|
traceback.print_exc() |
|
sys.exit(1) |
|
|
|
main() |