Skip to content

Commit

Permalink
fix:github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
mertakman committed Nov 7, 2024
1 parent 1959c96 commit 1b78bf1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ jobs:
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Build Examples
run: cargo build --verbose --examples
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
httpmock = "0.7.0"

[dev-dependencies]
tokio = { version="1.41.0", features = ["full"] }
lambda_runtime = "0.13.0"
25 changes: 24 additions & 1 deletion examples/aws-lambda/main.rs
Original file line number Diff line number Diff line change
@@ -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<Request>) -> Result<Response, Error> {
let (request, _context) = event.into_parts();
let message = format!("Hello, {}!", request.name);
Ok(Response { message })
}
1 change: 0 additions & 1 deletion src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ impl QstashClient {

#[cfg(test)]
mod tests {
use super::*;
}
3 changes: 0 additions & 3 deletions src/llm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions src/llm_types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::errors::QstashError;
use bytes::Bytes;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -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;
Expand All @@ -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<Vec<u8>> {
fn extract_next_message(&mut self, chunk: &Vec<u8>) -> Option<Vec<u8>> {
// Append new chunk to existing buffer
self.buffer.extend_from_slice(chunk);

Expand Down

0 comments on commit 1b78bf1

Please sign in to comment.