Skip to content

Commit

Permalink
done with integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: José Ulises Niño Rivera <[email protected]>
  • Loading branch information
junr03 committed Oct 4, 2024
1 parent 60909be commit 2bbfc56
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 109 deletions.
32 changes: 15 additions & 17 deletions arch/src/filter_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ impl FilterContext {
embedding_type: EmbeddingType,
prompt_target_name: String,
) {
let prompt_target = self.prompt_targets.get(&prompt_target_name).expect(
format!(
"Received embeddings response for unknown prompt target name={}",
prompt_target_name
)
.as_str(),
);
let prompt_target = self
.prompt_targets
.get(&prompt_target_name)
.unwrap_or_else(|| {
panic!(
"Received embeddings response for unknown prompt target name={}",
prompt_target_name
)
});

let body = self
.get_http_call_response_body(0, body_size)
Expand All @@ -153,7 +155,7 @@ impl FilterContext {
};

let embeddings = embedding_response.data.remove(0).embedding;
log::info!(
debug!(
"Adding embeddings for prompt target name: {:?}, description: {:?}, embedding type: {:?}",
prompt_target.name,
prompt_target.description,
Expand All @@ -164,13 +166,13 @@ impl FilterContext {
match entry {
Entry::Occupied(_) => {
entry.and_modify(|e| {
if e.contains_key(&embedding_type) {
if let Entry::Vacant(e) = e.entry(embedding_type) {
e.insert(embeddings);
} else {
panic!(
"Duplicate {:?} for prompt target with name=\"{}\"",
&embedding_type, prompt_target.name
)
} else {
e.insert(embedding_type, embeddings);
}
});
}
Expand Down Expand Up @@ -246,7 +248,6 @@ impl RootContext for FilterContext {
prompt_targets.insert(pt.name.clone(), pt.clone());
}
self.prompt_targets = Rc::new(prompt_targets);
debug!("Setting prompt target config value");

ratelimit::ratelimits(config.ratelimits);

Expand All @@ -269,9 +270,7 @@ impl RootContext for FilterContext {
);

// No StreamContext can be created until the Embedding Store is fully initialized.
if self.embeddings_store.is_none() {
return None;
}
self.embeddings_store.as_ref()?;

Some(Box::new(StreamContext::new(
context_id,
Expand All @@ -285,8 +284,7 @@ impl RootContext for FilterContext {
.expect("LLM Providers must exist when Streams are being created"),
),
Rc::clone(
&self
.embeddings_store
self.embeddings_store
.as_ref()
.expect("Embeddings Store must exist when StreamContext is being constructed"),
),
Expand Down
11 changes: 8 additions & 3 deletions arch/src/http.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::stats::{Gauge, IncrementingMetric};
use log::debug;
use proxy_wasm::traits::Context;
use std::{cell::RefCell, collections::HashMap, time::Duration};
use std::{cell::RefCell, collections::HashMap, fmt::Debug, time::Duration};

#[derive(Debug)]
pub struct CallArgs<'a> {
Expand Down Expand Up @@ -30,9 +31,13 @@ impl<'a> CallArgs<'a> {
}

pub trait Client: Context {
type CallContext;
type CallContext: Debug;

fn http_call(&self, call_args: CallArgs, call_context: Self::CallContext) {
debug!(
"dispatching http call with args={:?} context={:?}",
call_args, call_context
);
let id = self
.dispatch_http_call(
call_args.upstream,
Expand All @@ -54,7 +59,7 @@ pub trait Client: Context {

fn add_call_context(&self, id: u32, call_context: Self::CallContext) {
let callouts = self.callouts();
if let Some(_) = callouts.borrow_mut().insert(id, call_context) {
if callouts.borrow_mut().insert(id, call_context).is_some() {
panic!("Duplicate http call with id={}", id);
}
self.active_http_calls().increment(1);
Expand Down
2 changes: 1 addition & 1 deletion arch/src/llm_providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl LlmProviders {
}

pub fn get(&self, name: &str) -> Option<Rc<LlmProvider>> {
self.providers.get(name).map(|rc| rc.clone())
self.providers.get(name).cloned()
}
}

Expand Down
Loading

0 comments on commit 2bbfc56

Please sign in to comment.