From 8fad5a12a0a68a87d04db50c542260b01ea6aef4 Mon Sep 17 00:00:00 2001 From: George Mallard Date: Sat, 10 Feb 2024 07:05:52 -0600 Subject: [PATCH] Update utils.py - This is a utility function standalone.get_cli_input() This function adds compatibility to Visual Studio Community edition. --- client/fabric/utils.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/client/fabric/utils.py b/client/fabric/utils.py index c60ffc6..c9f397d 100644 --- a/client/fabric/utils.py +++ b/client/fabric/utils.py @@ -3,6 +3,7 @@ import os from openai import OpenAI import pyperclip import sys +import platform from dotenv import load_dotenv from requests.exceptions import HTTPError from tqdm import tqdm @@ -174,6 +175,25 @@ class Standalone: print(model.get("id")) else: print(f"Failed to fetch models: HTTP {response.status_code}") + + def get_cli_input(self): + """ aided by ChatGPT; uses platform library + accepts either piped input or console input + from either Windows or Linux + + Args: + none + Returns: + string from either user or pipe + """ + system = platform.system() + if system == 'Windows': + if not sys.stdin.isatty(): # Check if input is being piped + return sys.stdin.readline().strip() # Read piped input + else: + return input("Enter Question: ") # Prompt user for input from console + else: + return sys.stdin.read() class Update: