Compare commits
2 commits
38f9eeac0f
...
18a84ef4cb
| Author | SHA1 | Date | |
|---|---|---|---|
| 18a84ef4cb | |||
| 88c5a0c158 |
2 changed files with 30 additions and 1 deletions
BIN
module.wasm
BIN
module.wasm
Binary file not shown.
31
src/lib.rs
31
src/lib.rs
|
|
@ -35,7 +35,7 @@ pub fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
||||||
prompt: &prompt,
|
prompt: &prompt,
|
||||||
};
|
};
|
||||||
let result = crate::llm::chat_with_identity(&client, ¶ms)
|
let result = crate::llm::chat_with_identity(&client, ¶ms)
|
||||||
.map_err(|e| ModuleError::internal(e.to_string()))?;
|
.map_err(|e| llm_error_to_module_error(e, &endpoint, &model))?;
|
||||||
|
|
||||||
Ok(Outputs::new()
|
Ok(Outputs::new()
|
||||||
.with_text("response", result.response)
|
.with_text("response", result.response)
|
||||||
|
|
@ -51,6 +51,35 @@ fn payload_text(p: &Payload) -> Option<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Turn a transport/protocol error into a message that names the
|
||||||
|
/// likely cause and the fix, instead of a raw `ConnectionRefused`.
|
||||||
|
/// The endpoint is Ollama-shaped by default, so a connect failure
|
||||||
|
/// almost always means Ollama isn't running or the model isn't
|
||||||
|
/// pulled.
|
||||||
|
fn llm_error_to_module_error(e: crate::llm::LlmError, endpoint: &str, model: &str) -> ModuleError {
|
||||||
|
use crate::llm::LlmError;
|
||||||
|
match e {
|
||||||
|
LlmError::Http(detail) => ModuleError::internal(format!(
|
||||||
|
"LLM endpoint {endpoint} not reachable ({detail}). Is Ollama running? \
|
||||||
|
Start it with `ollama serve`, then pull the model with `ollama pull {model}`. \
|
||||||
|
If the LLM runs elsewhere, set the `endpoint` input to its /api URL."
|
||||||
|
)),
|
||||||
|
LlmError::Status(404) => ModuleError::internal(format!(
|
||||||
|
"LLM endpoint {endpoint} returned 404 for model '{model}' — the model is \
|
||||||
|
likely not pulled. Run `ollama pull {model}` (or check the model name)."
|
||||||
|
)),
|
||||||
|
LlmError::Status(code) => ModuleError::internal(format!(
|
||||||
|
"LLM endpoint {endpoint} returned HTTP {code} for model '{model}'."
|
||||||
|
)),
|
||||||
|
LlmError::Decode(detail) => ModuleError::internal(format!(
|
||||||
|
"LLM response from {endpoint} was not valid Ollama JSON: {detail}"
|
||||||
|
)),
|
||||||
|
LlmError::MissingInput(name) => ModuleError::invalid_input(format!(
|
||||||
|
"missing required input '{name}'"
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
fn make_client() -> WakiClient {
|
fn make_client() -> WakiClient {
|
||||||
WakiClient
|
WakiClient
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue