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
def __init__(self):
self.name = "00 Basic Openrouter Chat"
self.name = "Basic Openrouter Chat"
self.valves = self.Valves(
**{
"pipelines": ["*"],
@ -31,21 +31,28 @@ class Pipeline:
pass
def pipe(self, user_message: str, model_id: str, messages: List[dict], body: dict) -> Union[str, Generator, Iterator]:
response = requests.post(
url = self.valves.OR_URL,
headers = {
"Authorization": f"Bearer {self.valves.OR_KEY}"
},
try:
response = requests.post(
url = self.valves.OR_URL,
headers = {
"Authorization": f"Bearer {self.valves.OR_KEY}"
},
data = json.dumps({
"model": self.valves.OR_MODEL,
"messages": [
{
"role": "user",
"content": user_message
}
]
})
)
data = json.dumps({
"model": self.valves.OR_MODEL,
"messages": [
{
"role": "user",
"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}"