Address comments from clean up PR (#17)

Signed-off-by: José Ulises Niño Rivera <junr03@users.noreply.github.com>
This commit is contained in:
José Ulises Niño Rivera 2024-07-22 14:29:12 -07:00 committed by GitHub
parent 7ae2d918e8
commit a59c7df2a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 18 deletions

View file

@ -52,3 +52,20 @@ pub struct VectorPoint {
pub struct CreateVectorStorePoints { pub struct CreateVectorStorePoints {
pub points: Vec<VectorPoint>, pub points: Vec<VectorPoint>,
} }
pub mod open_ai {
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChatCompletions {
#[serde(default)]
pub model: String,
pub messages: Vec<Message>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Message {
pub role: String,
pub content: String,
}
}

View file

@ -15,7 +15,6 @@ use proxy_wasm::types::*;
mod common_types; mod common_types;
mod configuration; mod configuration;
mod consts; mod consts;
mod llm_backend;
mod stats; mod stats;
proxy_wasm::main! {{ proxy_wasm::main! {{
@ -81,7 +80,7 @@ impl HttpContext for StreamContext {
// Deserialize body into spec. // Deserialize body into spec.
// Currently OpenAI API. // Currently OpenAI API.
let mut deserialized_body: llm_backend::ChatCompletions = let mut deserialized_body: common_types::open_ai::ChatCompletions =
match self.get_http_request_body(0, body_size) { match self.get_http_request_body(0, body_size) {
Some(body_bytes) => match serde_json::from_slice(&body_bytes) { Some(body_bytes) => match serde_json::from_slice(&body_bytes) {
Ok(deserialized) => deserialized, Ok(deserialized) => deserialized,
@ -262,7 +261,7 @@ impl FilterContext {
} }
} }
fn create_vector_store_points_worker(&self, body_size: usize) { fn create_vector_store_points_handler(&self, body_size: usize) {
info!("response received for CreateVectorStorePoints"); info!("response received for CreateVectorStorePoints");
if let Some(body) = self.get_http_call_response_body(0, body_size) { if let Some(body) = self.get_http_call_response_body(0, body_size) {
if !body.is_empty() { if !body.is_empty() {
@ -292,7 +291,7 @@ impl Context for FilterContext {
self.embedding_request_handler(body_size, create_embedding_request, prompt_target) self.embedding_request_handler(body_size, create_embedding_request, prompt_target)
} }
common_types::MessageType::CreateVectorStorePoints(_) => { common_types::MessageType::CreateVectorStorePoints(_) => {
self.create_vector_store_points_worker(body_size) self.create_vector_store_points_handler(body_size)
} }
} }
} }

View file

@ -1,14 +0,0 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChatCompletions {
#[serde(default)]
pub model: String,
pub messages: Vec<Message>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Message {
pub role: String,
pub content: String,
}