mirror of
https://github.com/katanemo/plano.git
synced 2026-04-25 00:36:34 +02:00
Move shared types into their own crate (#41)
Signed-off-by: José Ulises Niño Rivera <junr03@users.noreply.github.com>
This commit is contained in:
parent
4dd1f3693e
commit
d98517f240
13 changed files with 1435 additions and 14 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,5 +1,6 @@
|
|||
envoyfilter/target
|
||||
envoyfilter/qdrant_data/
|
||||
public-types/target
|
||||
embedding-server/venv/
|
||||
chatbot-ui/venv/
|
||||
__pycache__
|
||||
|
|
|
|||
9
envoyfilter/Cargo.lock
generated
9
envoyfilter/Cargo.lock
generated
|
|
@ -918,6 +918,7 @@ dependencies = [
|
|||
"open-message-format-embeddings",
|
||||
"proxy-wasm",
|
||||
"proxy-wasm-test-framework",
|
||||
"public-types",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_yaml",
|
||||
|
|
@ -1377,6 +1378,14 @@ dependencies = [
|
|||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "public-types"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"open-message-format-embeddings",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quanta"
|
||||
version = "0.12.3"
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ serde_yaml = "0.9.34"
|
|||
serde_json = "1.0"
|
||||
md5 = "0.7.0"
|
||||
open-message-format-embeddings = { path = "../open-message-format/clients/omf-embeddings-rust" }
|
||||
public-types = { path = "../public-types" }
|
||||
http = "1.1.0"
|
||||
governor = "0.6.3"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
use crate::common_types::{
|
||||
CallContext, EmbeddingRequest, StoreVectorEmbeddingsRequest, VectorPoint,
|
||||
};
|
||||
use crate::configuration::{Configuration, PromptTarget};
|
||||
use crate::consts::DEFAULT_EMBEDDING_MODEL;
|
||||
use crate::ratelimit;
|
||||
use crate::stats::{Gauge, RecordingMetric};
|
||||
|
|
@ -13,6 +9,10 @@ use open_message_format_embeddings::models::{
|
|||
};
|
||||
use proxy_wasm::traits::*;
|
||||
use proxy_wasm::types::*;
|
||||
use public_types::common_types::{
|
||||
CallContext, EmbeddingRequest, StoreVectorEmbeddingsRequest, VectorPoint,
|
||||
};
|
||||
use public_types::configuration::{Configuration, PromptTarget};
|
||||
use serde_json::to_string;
|
||||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ use filter_context::FilterContext;
|
|||
use proxy_wasm::traits::*;
|
||||
use proxy_wasm::types::*;
|
||||
|
||||
mod common_types;
|
||||
mod configuration;
|
||||
mod consts;
|
||||
mod filter_context;
|
||||
mod ratelimit;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::configuration;
|
||||
use crate::configuration::{Limit, Ratelimit, TimeUnit};
|
||||
use governor::{DefaultKeyedRateLimiter, InsufficientCapacity, Quota};
|
||||
use public_types::configuration;
|
||||
use public_types::configuration::{Limit, Ratelimit, TimeUnit};
|
||||
use std::num::{NonZero, NonZeroU32};
|
||||
use std::sync::RwLock;
|
||||
use std::{collections::HashMap, sync::OnceLock};
|
||||
|
|
@ -376,8 +376,8 @@ fn different_provider_can_have_different_limits_with_the_same_keys() {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::ratelimits;
|
||||
use crate::configuration;
|
||||
use configuration::{Limit, Ratelimit, TimeUnit};
|
||||
use public_types::configuration;
|
||||
use std::num::NonZero;
|
||||
use std::thread;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,3 @@
|
|||
use crate::common_types::{
|
||||
open_ai::{ChatCompletions, Message},
|
||||
NERRequest, NERResponse, SearchPointsRequest, SearchPointsResponse,
|
||||
};
|
||||
use crate::configuration::{Entity, PromptTarget};
|
||||
use crate::consts::{
|
||||
DEFAULT_COLLECTION_NAME, DEFAULT_EMBEDDING_MODEL, DEFAULT_NER_MODEL, DEFAULT_NER_THRESHOLD,
|
||||
DEFAULT_PROMPT_TARGET_THRESHOLD, SYSTEM_ROLE, USER_ROLE,
|
||||
|
|
@ -16,6 +11,11 @@ use open_message_format_embeddings::models::{
|
|||
};
|
||||
use proxy_wasm::traits::*;
|
||||
use proxy_wasm::types::*;
|
||||
use public_types::common_types::{
|
||||
open_ai::{ChatCompletions, Message},
|
||||
NERRequest, NERResponse, SearchPointsRequest, SearchPointsResponse,
|
||||
};
|
||||
use public_types::configuration::{Entity, PromptTarget};
|
||||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use http::StatusCode;
|
||||
use proxy_wasm_test_framework::tester;
|
||||
use proxy_wasm_test_framework::types::{Action, BufferType, MapType, MetricType, ReturnType};
|
||||
use public_types::common_types::Entity;
|
||||
use serial_test::serial;
|
||||
use std::path::Path;
|
||||
|
||||
|
|
@ -177,3 +178,92 @@ fn bad_request_to_open_ai_chat_completions() {
|
|||
.execute_and_expect(ReturnType::Action(Action::Pause))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn delete_me_in_next_pr_successful_request_to_open_ai_chat_completions() {
|
||||
let ner_response = Entity {
|
||||
score: 0.7,
|
||||
text: String::from("hello"),
|
||||
label: String::from("hello"),
|
||||
};
|
||||
let ner_response_buffer = serde_json::to_string(&ner_response).unwrap();
|
||||
println!("{} is my length", ner_response_buffer.len());
|
||||
|
||||
let args = tester::MockSettings {
|
||||
wasm_path: wasm_module(),
|
||||
quiet: false,
|
||||
allow_unexpected: false,
|
||||
};
|
||||
let mut module = tester::mock(args).unwrap();
|
||||
|
||||
module
|
||||
.call_start()
|
||||
.execute_and_expect(ReturnType::None)
|
||||
.unwrap();
|
||||
|
||||
// Setup Filter
|
||||
let root_context = 1;
|
||||
|
||||
module
|
||||
.call_proxy_on_context_create(root_context, 0)
|
||||
.expect_metric_creation(MetricType::Gauge, "active_http_calls")
|
||||
.execute_and_expect(ReturnType::None)
|
||||
.unwrap();
|
||||
|
||||
// Setup HTTP Stream
|
||||
let http_context = 2;
|
||||
|
||||
module
|
||||
.call_proxy_on_context_create(http_context, root_context)
|
||||
.execute_and_expect(ReturnType::None)
|
||||
.unwrap();
|
||||
|
||||
// Request Headers
|
||||
module
|
||||
.call_proxy_on_request_headers(http_context, 0, false)
|
||||
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some(":host"))
|
||||
.returning(Some("api.openai.com"))
|
||||
.expect_add_header_map_value(
|
||||
Some(MapType::HttpRequestHeaders),
|
||||
Some("content-length"),
|
||||
Some(""),
|
||||
)
|
||||
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some(":path"))
|
||||
.returning(Some("/llmrouting"))
|
||||
.expect_add_header_map_value(
|
||||
Some(MapType::HttpRequestHeaders),
|
||||
Some(":path"),
|
||||
Some("/v1/chat/completions"),
|
||||
)
|
||||
.execute_and_expect(ReturnType::Action(Action::Continue))
|
||||
.unwrap();
|
||||
|
||||
// Request Body
|
||||
let chat_completions_request_body = "\
|
||||
{\
|
||||
\"messages\": [\
|
||||
{\
|
||||
\"role\": \"system\",\
|
||||
\"content\": \"You are a poetic assistant, skilled in explaining complex programming concepts with creative flair.\"\
|
||||
},\
|
||||
{\
|
||||
\"role\": \"user\",\
|
||||
\"content\": \"Compose a poem that explains the concept of recursion in programming.\"\
|
||||
}\
|
||||
]\
|
||||
}";
|
||||
|
||||
module
|
||||
.call_proxy_on_request_body(
|
||||
http_context,
|
||||
chat_completions_request_body.len() as i32,
|
||||
true,
|
||||
)
|
||||
.expect_get_buffer_bytes(Some(BufferType::HttpRequestBody))
|
||||
.returning(Some(chat_completions_request_body))
|
||||
// TODO: assert that the model field was added.
|
||||
.expect_set_buffer_bytes(Some(BufferType::HttpRequestBody), None)
|
||||
.execute_and_expect(ReturnType::Action(Action::Pause))
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
|||
1312
public-types/Cargo.lock
generated
Normal file
1312
public-types/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
8
public-types/Cargo.toml
Normal file
8
public-types/Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "public-types"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
open-message-format-embeddings = { path = "../open-message-format/clients/omf-embeddings-rust" }
|
||||
2
public-types/src/lib.rs
Normal file
2
public-types/src/lib.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pub mod common_types;
|
||||
pub mod configuration;
|
||||
Loading…
Add table
Add a link
Reference in a new issue