mirror of
https://github.com/perstarkse/minne.git
synced 2026-03-12 21:35:40 +01:00
knowledge type select instead of input
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -20,7 +20,8 @@ use crate::{
|
||||
storage::{
|
||||
db::delete_item,
|
||||
types::{
|
||||
knowledge_entity::KnowledgeEntity, knowledge_relationship::KnowledgeRelationship,
|
||||
knowledge_entity::{KnowledgeEntity, KnowledgeEntityType},
|
||||
knowledge_relationship::KnowledgeRelationship,
|
||||
user::User,
|
||||
},
|
||||
},
|
||||
@@ -146,6 +147,7 @@ pub async fn show_knowledge_page(
|
||||
#[derive(Serialize)]
|
||||
pub struct EntityData {
|
||||
entity: KnowledgeEntity,
|
||||
entity_types: Vec<String>,
|
||||
user: User,
|
||||
}
|
||||
|
||||
@@ -160,6 +162,12 @@ pub async fn show_edit_knowledge_entity_form(
|
||||
None => return Ok(Redirect::to("/signin").into_response()),
|
||||
};
|
||||
|
||||
// Get entity types
|
||||
let entity_types: Vec<String> = KnowledgeEntityType::variants()
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect();
|
||||
|
||||
// Get the entity and validate ownership
|
||||
let entity = User::get_and_validate_knowledge_entity(&id, &user.id, &state.surreal_db_client)
|
||||
.await
|
||||
@@ -167,7 +175,11 @@ pub async fn show_edit_knowledge_entity_form(
|
||||
|
||||
let output = render_template(
|
||||
"knowledge/edit_knowledge_entity_modal.html",
|
||||
EntityData { entity, user },
|
||||
EntityData {
|
||||
entity,
|
||||
user,
|
||||
entity_types,
|
||||
},
|
||||
state.templates,
|
||||
)?;
|
||||
|
||||
@@ -184,6 +196,7 @@ pub struct EntityListData {
|
||||
pub struct PatchKnowledgeEntityParams {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub entity_type: String,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
@@ -199,17 +212,18 @@ pub async fn patch_knowledge_entity(
|
||||
};
|
||||
|
||||
// Get the existing entity and validate that the user is allowed
|
||||
let existing_entity =
|
||||
User::get_and_validate_knowledge_entity(&form.id, &user.id, &state.surreal_db_client)
|
||||
.await
|
||||
.map_err(|e| HtmlError::new(e, state.templates.clone()))?;
|
||||
User::get_and_validate_knowledge_entity(&form.id, &user.id, &state.surreal_db_client)
|
||||
.await
|
||||
.map_err(|e| HtmlError::new(e, state.templates.clone()))?;
|
||||
|
||||
let entity_type: KnowledgeEntityType = KnowledgeEntityType::from(form.entity_type);
|
||||
|
||||
// Update the entity
|
||||
KnowledgeEntity::patch(
|
||||
&form.id,
|
||||
&form.name,
|
||||
&form.description,
|
||||
&existing_entity.entity_type,
|
||||
&entity_type,
|
||||
&state.surreal_db_client,
|
||||
&state.openai_client,
|
||||
)
|
||||
|
||||
@@ -2,10 +2,7 @@ use crate::{
|
||||
error::AppError, storage::db::SurrealDbClient, stored_object,
|
||||
utils::embedding::generate_embedding,
|
||||
};
|
||||
use async_openai::{
|
||||
config::{Config, OpenAIConfig},
|
||||
Client,
|
||||
};
|
||||
use async_openai::{config::OpenAIConfig, Client};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
@@ -17,6 +14,11 @@ pub enum KnowledgeEntityType {
|
||||
TextSnippet,
|
||||
// Add more types as needed
|
||||
}
|
||||
impl KnowledgeEntityType {
|
||||
pub fn variants() -> &'static [&'static str] {
|
||||
&["Idea", "Project", "Document", "Page", "TextSnippet"]
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for KnowledgeEntityType {
|
||||
fn from(s: String) -> Self {
|
||||
@@ -101,6 +103,7 @@ impl KnowledgeEntity {
|
||||
SET name = $name,
|
||||
description = $description,
|
||||
updated_at = $updated_at,
|
||||
entity_type = $entity_type,
|
||||
embedding = $embedding
|
||||
RETURN AFTER",
|
||||
)
|
||||
@@ -108,6 +111,7 @@ impl KnowledgeEntity {
|
||||
.bind(("id", id.to_string()))
|
||||
.bind(("name", name.to_string()))
|
||||
.bind(("updated_at", Utc::now()))
|
||||
.bind(("entity_type", entity_type.to_owned()))
|
||||
.bind(("embedding", embedding))
|
||||
.bind(("description", description.to_string()))
|
||||
.await?;
|
||||
|
||||
@@ -16,11 +16,13 @@ hx-swap="outerHTML"
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="floating-label">
|
||||
<span class="label-text">Type</span>
|
||||
<input type="text" name="name" value="{{ entity.entity_type}}" class="input input-bordered w-full">
|
||||
</label>
|
||||
<div class="form-control relative" style="margin-top: -1.5rem;">
|
||||
<span class="absolute left-2.5 top-2.5 z-[100] p-0.5 bg-white text-xs text-light">Type</span>
|
||||
<select name="entity_type" class="select select-bordered w-full">
|
||||
{% for et in entity_types %}
|
||||
<option value="{{ et }}" {% if entity.entity_type==et %}selected{% endif %}>{{ et }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<input type="text" name="id" value="{{ entity.id }}" class="hidden">
|
||||
|
||||
Reference in New Issue
Block a user