Skip to content

Commit

Permalink
resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
anish-palakurthi committed Jun 28, 2024
1 parent 92daa2d commit 25b6bd4
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 35 deletions.
Empty file.
1 change: 0 additions & 1 deletion engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion engine/baml-lib/jinja/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ serde_json.workspace = true
log = "0.4.14"
strsim = "0.11.1"
colored = "2.1.0"
wasm-bindgen = "0.2.92"

[dev-dependencies]
env_logger = "0.11.3"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod stream;
use anyhow::Result;
use baml_types::BamlValue;

use either::Either;
use instant::Duration;
use internal_baml_core::ir::repr::IntermediateRepr;
use internal_baml_jinja::RenderedChatMessage;
Expand Down
35 changes: 7 additions & 28 deletions engine/baml-runtime/src/internal/llm_client/traits/mod.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
use std::{fmt::format, pin::Pin};

use anyhow::Result;
use async_std::stream;

mod chat;
mod completion;
pub use self::{
chat::{WithChat, WithStreamChat},
completion::{WithCompletion, WithNoCompletion, WithStreamCompletion},
};
use super::{
primitive::request::RequestBuilder, retry_policy::CallablePolicy, LLMResponse, ModelFeatures,
};
use crate::HashMap;
use super::{primitive::request::RequestBuilder, LLMResponse, ModelFeatures};

use crate::{internal::prompt_renderer::PromptRenderer, RuntimeContext};
use baml_types::{BamlMedia, BamlMediaType, BamlValue, MediaBase64};
use base64::encode;
use futures::stream::{StreamExt, TryStreamExt};
use futures::stream::StreamExt;
use infer;
use internal_baml_core::ir::repr::IntermediateRepr;
use internal_baml_jinja::{ChatMessagePart, RenderedChatMessage};
Expand All @@ -24,7 +22,6 @@ use reqwest::get;
use reqwest::header::HeaderMap;

use reqwest::Url;
use reqwest::{Request, Response};

use shell_escape::escape;
use std::borrow::Cow;
Expand Down Expand Up @@ -69,25 +66,7 @@ pub trait WithPrompt<'ir> {
stream: bool,
) -> Result<String>;
}
fn request_to_string(request: &Request) -> Result<String, reqwest::Error> {
let mut result = String::new();

// Add method and URL
result.push_str(&format!("{} {}\n", request.method(), request.url()));
// Add headers
for (key, value) in request.headers() {
result.push_str(&format!("{}: {:?}\n", key, value));
}

// Add body
if let Some(body) = request.body() {
let body_bytes = body.as_bytes().unwrap_or_default();
let body_str = String::from_utf8_lossy(body_bytes);
result.push_str(&format!("\n\n{}", body_str));
}

Ok(result)
}
impl<T> WithSingleCallable for T
where
T: WithClient + WithChat + WithCompletion,
Expand Down Expand Up @@ -402,19 +381,19 @@ where
let rendered_prompt = RenderedPrompt::Chat(prompt.clone());

let chat_messages = self.curl_call(ctx, &rendered_prompt).await?;
let request_builder = self.build_request(either::Right(&chat_messages), false);
let request_builder = self.build_request(either::Right(&chat_messages), stream);
let mut request = request_builder.build()?;
let url_header_value = {
let headers = request.headers_mut();
let url_header_value = headers
.get("baml-render-url")
.ok_or(anyhow::anyhow!("Missing header 'baml-original-url'"))?;
.ok_or(anyhow::anyhow!("Missing header 'baml-render-url'"))?;
url_header_value.to_owned()
};

let url_str = url_header_value
.to_str()
.map_err(|_| anyhow::anyhow!("Invalid header 'baml-original-url'"))?;
.map_err(|_| anyhow::anyhow!("Invalid header 'baml-render-url'"))?;
let new_url = Url::from_str(url_str)?;
*request.url_mut() = new_url;

Expand Down
4 changes: 2 additions & 2 deletions engine/baml-schema-wasm/src/runtime_wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use baml_runtime::{
internal::llm_client::LLMResponse, BamlRuntime, DiagnosticsError, IRHelper, RenderedPrompt,
};
use baml_types::{BamlMap, BamlValue};
use either::Either;

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
use wasm_bindgen::convert::IntoWasmAbi;

use wasm_bindgen::prelude::*;

//Run: wasm-pack test --firefox --headless --features internal,wasm
Expand Down
2 changes: 0 additions & 2 deletions typescript/playground-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@
"@baml/common": "workspace:^",
"@codemirror/lang-javascript": "^6.2.2",
"@codemirror/lang-python": "^6.1.6",
"@fortawesome/free-solid-svg-icons": "^6.5.2",
"@fortawesome/react-fontawesome": "^0.2.2",
"@gloo-ai/baml-schema-wasm-web": "*",
"@hookform/resolvers": "^3.3.4",
"@radix-ui/react-accordion": "^1.1.2",
Expand Down

0 comments on commit 25b6bd4

Please sign in to comment.