Skip to content

Commit

Permalink
update prompt instruct builder to use new db format
Browse files Browse the repository at this point in the history
  • Loading branch information
aprxi committed Sep 25, 2024
1 parent 3e546b1 commit 72cb3ab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
1 change: 0 additions & 1 deletion lumni/src/apps/builtin/llm/prompt/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ async fn interactive_mode(
) -> Result<(), ApplicationError> {
let app = App::new(prompt_instruction, Arc::clone(&db_conn)).await?;
let mut stdout = io::stdout().lock();

// Enable raw mode and setup the screen
if let Err(e) = enable_raw_mode() {
execute!(stdout, Show, LeaveAlternateScreen)?;
Expand Down
32 changes: 19 additions & 13 deletions lumni/src/apps/builtin/llm/prompt/src/chat/db/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,36 @@ impl UserProfileDbHandler {
pub async fn model_backend(
&mut self,
) -> Result<Option<ModelBackend>, ApplicationError> {
let user_profile = self.profile.clone();

if let Some(profile) = user_profile {
if let Some(profile) = self.profile.clone() {
self.unlock_profile_settings(&profile).await?;
let settings = self
.get_configuration_parameters(&profile.into(), MaskMode::Unmask)
.await?;

let model_server = match settings
.get("__TEMPLATE.__MODEL_SERVER")
.and_then(|v| v.as_str())
let provider = match settings
.get("__section.provider")
.and_then(|v| v.as_object())
{
Some(server) => server,
Some(provider) => provider,
None => return Ok(None),
};

let server = ModelServer::from_str(model_server)?;
let model_server =
match provider.get("__type").and_then(|v| v.as_str()) {
Some(server) => server,
None => return Ok(None),
};

let model = settings
.get("__TEMPLATE.MODEL_IDENTIFIER")
.and_then(|v| v.as_str())
.map(|identifier| ModelSpec::new_with_validation(identifier))
.transpose()?;
let server = ModelServer::from_str(model_server)?;

let model =
match provider.get("model_identifier").and_then(|v| v.as_str())
{
Some(identifier) => {
Some(ModelSpec::new_with_validation(identifier)?)
}
None => return Ok(None),
};
Ok(Some(ModelBackend { server, model }))
} else {
Ok(None)
Expand Down
8 changes: 4 additions & 4 deletions lumni/src/apps/builtin/llm/prompt/src/chat/prompt/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ impl PromptInstructionBuilder {
"Failed to get model backend".to_string(),
)
})?;

// TODO: assistant, user_options and instructions should be loaded from
// the profile if not yet defined. Note that the current profile does not yet support
// configuring these. Adding support within profile should be done first.
Expand Down Expand Up @@ -136,7 +135,6 @@ impl PromptInstructionBuilder {
initial_messages: Some(initial_messages),
parent: None,
};

let mut db_handler = self.db_conn.get_conversation_handler(None);
let conversation_id = self.db_conn.fetch_last_conversation_id().await?;

Expand All @@ -149,7 +147,10 @@ impl PromptInstructionBuilder {
Some(PromptInstruction::from_reader(&db_handler).await?)
}
Ok(_) => None,
Err(e) => return Err(e.into()),
Err(e) => {
log::warn!("Failed to check if conversation is equal: {}", e);
None
}
}
} else {
None
Expand All @@ -163,7 +164,6 @@ impl PromptInstructionBuilder {
.await?
}
};

Ok(prompt_instruction)
}
}
Expand Down

0 comments on commit 72cb3ab

Please sign in to comment.