diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9fd45e0..04ec63a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -20,3 +20,5 @@ jobs: run: cargo build --verbose - name: Run tests run: cargo test --verbose + - name: Build Examples + run: cargo build --verbose --examples \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 0967fea..0360680 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,11 +7,13 @@ edition = "2021" base64 = "0.22.1" serde = { version = "1.0", features = ["derive"] } -reqwest = { version = "0.11", features = ["json"] } -bytes = "1.7.2" +reqwest = { version = "0.12", features = ["json"] } serde_json = "=1.0.1" urlencoding = "2.1.3" http = "1.1.0" -tokio = { version="1.41.0", features = ["full"] } futures = "0.3" -httpmock = "0.7.0" \ No newline at end of file +httpmock = "0.7.0" + +[dev-dependencies] +tokio = { version="1.41.0", features = ["full"] } +lambda_runtime = "0.13.0" diff --git a/examples/aws-lambda/main.rs b/examples/aws-lambda/main.rs index f328e4d..c1c66fd 100644 --- a/examples/aws-lambda/main.rs +++ b/examples/aws-lambda/main.rs @@ -1 +1,24 @@ -fn main() {} +use lambda_runtime::{service_fn, LambdaEvent, Error}; +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize)] +struct Request { + pub name: String, +} + +#[derive(Serialize)] +struct Response { + pub message: String, +} + +#[tokio::main] +async fn main() -> Result<(), Error> { + let func = service_fn(func_handler); + lambda_runtime::run(func).await +} + +async fn func_handler(event: LambdaEvent) -> Result { + let (request, _context) = event.into_parts(); + let message = format!("Hello, {}!", request.name); + Ok(Response { message }) +} diff --git a/src/events.rs b/src/events.rs index b48f7eb..8d8d23e 100644 --- a/src/events.rs +++ b/src/events.rs @@ -30,5 +30,4 @@ impl QstashClient { #[cfg(test)] mod tests { - use super::*; } diff --git a/src/llm.rs b/src/llm.rs index 2bdf901..191abf3 100644 --- a/src/llm.rs +++ b/src/llm.rs @@ -21,9 +21,6 @@ impl QstashClient { ) .json(&chat_completion_request); - if Some(true) == chat_completion_request.stream { - println!("Request: {:?}", request); - } let response = self.client.send_request(request).await?; match chat_completion_request.stream { diff --git a/src/llm_types.rs b/src/llm_types.rs index 8358f46..757b7fd 100644 --- a/src/llm_types.rs +++ b/src/llm_types.rs @@ -1,5 +1,4 @@ use crate::errors::QstashError; -use bytes::Bytes; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] @@ -241,9 +240,8 @@ impl StreamResponse { Some(c) => c, None => return Ok(ChunkType::Done()), }; - // Now we can mutably borrow self for extract_next_message - if let Some(message) = self.extract_next_message(&chunk) { + if let Some(message) = self.extract_next_message(&chunk.to_vec()) { match message.as_slice() { b"[DONE]" => { self.response = None; @@ -256,7 +254,7 @@ impl StreamResponse { } // Takes a chunk of bytes and returns a complete message if available - fn extract_next_message(&mut self, chunk: &Bytes) -> Option> { + fn extract_next_message(&mut self, chunk: &Vec) -> Option> { // Append new chunk to existing buffer self.buffer.extend_from_slice(chunk);