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,21 +31,28 @@ 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]:
response = requests.post( try:
url = self.valves.OR_URL, response = requests.post(
headers = { url = self.valves.OR_URL,
"Authorization": f"Bearer {self.valves.OR_KEY}" headers = {
}, "Authorization": f"Bearer {self.valves.OR_KEY}"
},
data = json.dumps({ data = json.dumps({
"model": self.valves.OR_MODEL, "model": self.valves.OR_MODEL,
"messages": [ "messages": [
{ {
"role": "user", "role": "user",
"content": user_message "content": user_message
} }
] ]
}) })
) )
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}"