Skip to content

Commit

Permalink
handle a bit more errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckyBlender committed Oct 5, 2024
1 parent c25c49b commit 6d62a45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/apis/together.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::Result;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use std::env;
Expand Down Expand Up @@ -44,12 +45,7 @@ impl TogetherClient {
}
}

pub async fn submit_request(
&self,
prompt: ImageRequest,
) -> Result<ImageResponse, reqwest::Error> {
// base64 image

pub async fn submit_request(&self, prompt: ImageRequest) -> Result<ImageResponse> {
let response = self
.client
.post("https://api.together.xyz/v1/images/generations")
Expand All @@ -62,6 +58,10 @@ impl TogetherClient {
.send()
.await?;

if !response.status().is_success() {
return Err(anyhow::anyhow!("Status code: {}", response.status()));
}

let response = response.json::<ImageResponse>().await?;

Ok(response)
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ async fn handle_command(
let res = client.submit_request(request).await;
if let Err(e) = res {
error!("Failed to submit request: {:?}", e);
bot.send_message(message.chat.id, format!("error: {e:?}"))
.reply_parameters(ReplyParameters::new(message.id))
.await
.unwrap();
return Ok(lambda_http::Response::builder()
.status(200)
.body(String::new())
Expand Down

0 comments on commit 6d62a45

Please sign in to comment.