Skip to content

Commit

Permalink
code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
aprxi committed Jul 12, 2024
1 parent fa8450c commit c9ff573
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 51 deletions.
49 changes: 2 additions & 47 deletions lumni/src/apps/builtin/llm/prompt/src/chat/db/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use rusqlite::Error as SqliteError;

use super::connector::DatabaseConnector;
use super::schema::{
Attachment, AttachmentData, AttachmentId, Conversation, ConversationId,
Exchange, ExchangeId, Message, MessageId,
Attachment, AttachmentData, Conversation, ConversationId,
Exchange, Message,
};

pub struct ConversationDatabaseStore {
Expand Down Expand Up @@ -52,57 +52,12 @@ impl ConversationDatabaseStore {
})
}

pub fn store_new_exchange(
&mut self,
exchange: &Exchange,
) -> Result<ExchangeId, SqliteError> {
let exchange_sql = format!(
"INSERT INTO exchanges (conversation_id, model_id, system_prompt, \
completion_options, prompt_options, completion_tokens, \
prompt_tokens, created_at, previous_exchange_id, is_deleted)
VALUES ({}, {}, {}, {}, {}, {}, {}, {}, {}, {});",
exchange.conversation_id.0,
exchange.model_id.0,
exchange.system_prompt.as_ref().map_or(
"NULL".to_string(),
|s| format!("'{}'", s.replace("'", "''"))
),
exchange.completion_options.as_ref().map_or(
"NULL".to_string(),
|v| format!("'{}'", v.to_string().replace("'", "''"))
),
exchange.prompt_options.as_ref().map_or(
"NULL".to_string(),
|v| format!("'{}'", v.to_string().replace("'", "''"))
),
exchange
.completion_tokens
.map_or("NULL".to_string(), |t| t.to_string()),
exchange
.prompt_tokens
.map_or("NULL".to_string(), |t| t.to_string()),
exchange.created_at,
exchange
.previous_exchange_id
.map_or("NULL".to_string(), |id| id.0.to_string()),
exchange.is_deleted
);

self.db.queue_operation(exchange_sql);

self.db.process_queue_with_result(|tx| {
let id = tx.last_insert_rowid();
Ok(ExchangeId(id))
})
}

pub fn store_finalized_exchange(
&mut self,
exchange: &Exchange,
messages: &[Message],
attachments: &[Attachment],
) -> Result<(), SqliteError> {
// Start a transaction
// Insert the exchange
let exchange_sql = format!(
"INSERT INTO exchanges (conversation_id, model_id, system_prompt,
Expand Down
4 changes: 0 additions & 4 deletions lumni/src/apps/builtin/llm/prompt/src/chat/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ impl PromptInstruction {

// Create a new Conversation in the database
let conversation_id = {
//let mut db_lock = db_conn.cache.lock().unwrap();
//db_lock.new_conversation("New Conversation", &db_conn.store, None)
db_conn.new_conversation("New Conversation", None)?
};
prompt_instruction.current_conversation_id = conversation_id;
Expand Down Expand Up @@ -211,7 +209,6 @@ impl PromptInstruction {
let system_prompt_token_length = self.get_n_keep().unwrap_or(0);

// add the partial exchange (question) to the conversation
//let last_exchange = store.get_last_exchange(self.current_conversation_id)?;
let mut cache = db_conn.cache.lock().unwrap();
let exchange = self.subsequent_exchange(&mut cache);

Expand Down Expand Up @@ -259,7 +256,6 @@ impl PromptInstruction {
break;
}
}

if total_tokens >= max_token_length {
break;
}
Expand Down

0 comments on commit c9ff573

Please sign in to comment.