Updated with try catch

This commit is contained in:
Helge-Mikael Nordgård 2025-01-23 20:04:51 +01:00
parent 66547eef54
commit 2c2c1cd49c

View File

@ -14,7 +14,7 @@ class Pipeline:
OR_KEY: str OR_KEY: str
def __init__(self): def __init__(self):
self.name = "00 Basic Openrouter Chat" self.name = "Basic Openrouter Chat"
self.valves = self.Valves( self.valves = self.Valves(
**{ **{
"pipelines": ["*"], "pipelines": ["*"],
@ -31,6 +31,7 @@ class Pipeline:
pass pass
def pipe(self, user_message: str, model_id: str, messages: List[dict], body: dict) -> Union[str, Generator, Iterator]: def pipe(self, user_message: str, model_id: str, messages: List[dict], body: dict) -> Union[str, Generator, Iterator]:
try:
response = requests.post( response = requests.post(
url = self.valves.OR_URL, url = self.valves.OR_URL,
headers = { headers = {
@ -49,3 +50,9 @@ class Pipeline:
) )
return response return response
except requests.HTTPError as e:
logging.error(f"Clientresponse error: {e}")
return "HTTP backend error"
except Exception as e:
logging.error(f"Unexpected error: {e}")
return f"Unexpected error: {e}"