Updated with try catch
This commit is contained in:
parent
66547eef54
commit
2c2c1cd49c
|
|
@ -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}"
|
||||
Loading…
Reference in New Issue
Block a user