Skip to content

Commit

Permalink
Revert "display for bmt"
Browse files Browse the repository at this point in the history
This reverts commit e438032.
  • Loading branch information
anish-palakurthi committed Jun 19, 2024
1 parent e438032 commit 37582ae
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 45 deletions.
4 changes: 2 additions & 2 deletions engine/baml-lib/baml-types/src/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub enum BamlMediaType {
impl fmt::Display for BamlMediaType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
BamlMediaType::Image => write!(f, "image"),
BamlMediaType::Audio => write!(f, "audio"),
BamlMediaType::Image => write!(f, "Image"),
BamlMediaType::Audio => write!(f, "Audio"),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions engine/baml-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ web-time.workspace = true
static_assertions.workspace = true
mime_guess = "2.0.4"
mime = "0.3.17"

# For tracing
envy = "0.4.2"
chrono = "0.4.38"
Expand All @@ -54,6 +55,7 @@ pin-project-lite = "0.2.14"
async-trait = "0.1.80"
cfg-if = "1.0.0"
include_dir = "0.7.3"

[target.'cfg(target_arch = "wasm32")'.dependencies]
serde-wasm-bindgen = "0.6.5"
wasm-bindgen = { version = "^0.2.74", features = ["serde-serialize"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl RequestBuilder for AnthropicClient {
&self.client
}

async fn build_request(
fn build_request(
&self,
prompt: either::Either<&String, &Vec<RenderedChatMessage>>,
stream: bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl RequestBuilder for GoogleClient {
&self.client
}

async fn build_request(
fn build_request(
&self,
prompt: either::Either<&String, &Vec<RenderedChatMessage>>,
stream: bool,
Expand Down Expand Up @@ -298,49 +298,13 @@ impl RequestBuilder for GoogleClient {

let mut body = json!(self.properties.properties);
let body_obj = body.as_object_mut().unwrap();

match prompt {
either::Either::Left(prompt) => {
body_obj.extend(convert_completion_prompt_to_body(prompt))
}
either::Either::Right(messages) => {
body_obj.extend(convert_chat_prompt_to_body(messages));
if let Some(contents) = body_obj.get("contents").and_then(|c| c.as_array()) {
let mut contents = contents.clone(); // clone contents here

for content in contents.iter_mut() {
if let Some(parts) = content.get_mut("parts").and_then(|p| p.as_array_mut())
{
for part in parts.iter_mut() {
if let Some(file_data) = part.get_mut("fileData") {
if let Some(data_url) =
file_data.get("data").and_then(|d| d.as_str())
{
// Make a curl request to get the media file
let response = reqwest::get(data_url).await.unwrap();
let bytes = response.bytes().await.unwrap();

// Base64 encode the media file
let base64_encoded = base64::encode(&bytes);

// Replace the fileData block with inlineData
let mut inline_data = serde_json::Map::new();
if let Some(mime_type) = file_data.get("mimeType") {
inline_data
.insert("mimeType".to_string(), mime_type.clone());
}
inline_data
.insert("data".to_string(), json!(base64_encoded));

part.as_object_mut()
.unwrap()
.insert("inlineData".to_string(), json!(inline_data));
part.as_object_mut().unwrap().remove("fileData");
}
}
}
}
}
}
body_obj.extend(convert_chat_prompt_to_body(messages))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl RequestBuilder for OpenAIClient {
&self.client
}

async fn build_request(
fn build_request(
&self,
prompt: either::Either<&String, &Vec<RenderedChatMessage>>,
stream: bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::de::DeserializeOwned;
use crate::internal::llm_client::{traits::WithClient, ErrorCode, LLMErrorResponse, LLMResponse};

pub trait RequestBuilder {
async fn build_request(
fn build_request(
&self,
prompt: either::Either<&String, &Vec<RenderedChatMessage>>,
stream: bool,
Expand Down Expand Up @@ -36,7 +36,7 @@ pub async fn make_request(
let (system_now, instant_now) = (web_time::SystemTime::now(), web_time::Instant::now());
log::info!("Making request using client {}", client.context().name);

let req = match client.build_request(prompt, stream).await.build() {
let req = match client.build_request(prompt, stream).build() {
Ok(req) => req,
Err(e) => {
return Err(LLMResponse::LLMFailure(LLMErrorResponse {
Expand Down

0 comments on commit 37582ae

Please sign in to comment.