Skip to content

Commit e0c698b

Browse files
author
Rutik Thakre
committed
wip
1 parent 5de3e14 commit e0c698b

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

Makefile.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,20 @@ golem-cli app clean
329329
golem-cli app build -b ollama-debug
330330
'''
331331

332+
[tasks.build-test-ollama]
333+
dependencies = ["build-ollama"]
334+
description = "Builds all test components with golem-cli"
335+
install_crate = "cargo-binstall"
336+
script = '''
337+
cargo-binstall golem-cli@1.2.2-dev.11 --locked --force --no-confirm
338+
cargo-binstall wac-cli --locked --force --no-confirm
339+
cd test
340+
golem-cli --version
341+
golem-cli app clean
342+
golem-cli app build -b ollama-debug
343+
'''
344+
345+
332346
[tasks.set-version]
333347
description = "Sets the version in all Cargo.toml files to the value of the VERSION environment variable"
334348
condition = { env_set = ["VERSION"] }

llm-ollama/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod conversions;
2020
struct OllamaChatStream {
2121
stream: RefCell<Option<EventSource>>,
2222
failure: Option<Error>,
23-
finished: RefCell<bool>,
23+
finished: RefCell<bool>,
2424
}
2525

2626
impl OllamaChatStream {
@@ -68,25 +68,25 @@ impl LlmChatStreamState for OllamaChatStream {
6868
self.stream.borrow_mut()
6969
}
7070

71-
fn decode_message(&self, raw: &str) -> Result<Option<StreamEvent>, String> {
71+
fn decode_message(&self, raw: &str) -> Result<Option<StreamEvent>, String> {
7272
println!("OllamaChatStream::decode_message");
73-
trace!("Parsing NDJSON line: {raw}");
73+
trace!("Parsing NDJSON line: {raw}");
7474
let json: serde_json::Value = serde_json::from_str(raw.trim())
7575
.map_err(|e| format!("JSON parse error: {e}"))?;
7676

7777
if json.get("done").and_then(|v| v.as_bool()).unwrap_or(false) {
7878
return Ok(Some(StreamEvent::Finish(ResponseMetadata {
7979
finish_reason: Some(FinishReason::Stop),
8080
usage: None,
81-
provider_id: None,
81+
provider_id: None,
8282
timestamp: None,
8383
provider_metadata_json: None,
8484
})));
8585
}
8686

8787
if let Some(message) = json.get("message") {
8888
let mut content = Vec::new();
89-
89+
9090
if let Some(text) = message.get("content").and_then(|c| c.as_str()) {
9191
if !text.is_empty() {
9292
content.push(ContentPart::Text(text.to_string()));

llm/src/chat_stream.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ pub struct LlmChatStream<T> {
1919

2020
impl<T: LlmChatStreamState> LlmChatStream<T> {
2121
pub fn new(implementation: T) -> Self {
22+
println!("LlmChatStream::new");
2223
Self { implementation }
2324
}
2425

2526
pub fn subscribe(&self) -> Pollable {
27+
println!("LlmChatStream::subscribe");
2628
if let Some(stream) = self.implementation.stream().as_ref() {
2729
stream.subscribe()
2830
} else {
@@ -33,6 +35,7 @@ impl<T: LlmChatStreamState> LlmChatStream<T> {
3335

3436
impl<T: LlmChatStreamState> GuestChatStream for LlmChatStream<T> {
3537
fn get_next(&self) -> Option<Vec<StreamEvent>> {
38+
println!("LlmChatStream::get_next");
3639
if self.implementation.is_finished() {
3740
return Some(vec![]);
3841
}
@@ -99,6 +102,7 @@ impl<T: LlmChatStreamState> GuestChatStream for LlmChatStream<T> {
99102
}
100103

101104
fn blocking_get_next(&self) -> Vec<StreamEvent> {
105+
println!("LlmChatStream::blocking_get_next");
102106
let pollable = self.subscribe();
103107
let mut result = Vec::new();
104108
loop {

llm/src/event_source/event_stream.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl EventStream {
167167
pub fn poll_next(
168168
&mut self,
169169
) -> Poll<Option<Result<MessageEvent, EventStreamError<StreamError>>>> {
170-
println!("EventStream::poll_next");
170+
println!("EventStream::poll_next buffer {} ", self.buffer.as_str());
171171
trace!("Polling for next event");
172172

173173
match parse_event(&mut self.buffer, &mut self.builder) {
@@ -270,18 +270,17 @@ fn parse_event<E>(
270270
buffer: &mut String,
271271
builder: &mut EventBuilder,
272272
) -> Result<Option<MessageEvent>, EventStreamError<E>> {
273-
println!("poll_next->parse_event");
274273
if buffer.is_empty() {
275274
return Ok(None);
276275
}
277276
loop {
278-
match line(buffer.as_ref()) {
279-
Ok((rem, next_line)) => {
280-
builder.add(next_line);
281-
let consumed = buffer.len() - rem.len();
282-
let rem = buffer.split_off(consumed);
283-
*buffer = rem;
284-
if builder.is_complete {
277+
match line(buffer.as_ref()) {
278+
Ok((rem, next_line)) => {
279+
builder.add(next_line);
280+
let consumed = buffer.len() - rem.len();
281+
let rem = buffer.split_off(consumed);
282+
*buffer = rem;
283+
if builder.is_complete {
285284
if let Some(event) = builder.dispatch() {
286285
return Ok(Some(event));
287286
}

0 commit comments

Comments
 (0)