refactor: renamed instructions to context

This commit is contained in:
Per Stark
2025-05-09 16:00:52 +02:00
parent 463c562ba7
commit 6ed49f7155
22 changed files with 111 additions and 123 deletions

File diff suppressed because one or more lines are too long

View File

@@ -94,7 +94,7 @@ pub async fn show_text_content_edit_form(
#[derive(Deserialize)]
pub struct PatchTextContentParams {
instructions: String,
context: String,
category: String,
text: String,
}
@@ -106,14 +106,7 @@ pub async fn patch_text_content(
) -> Result<impl IntoResponse, HtmlError> {
User::get_and_validate_text_content(&id, &user.id, &state.db).await?;
TextContent::patch(
&id,
&form.instructions,
&form.category,
&form.text,
&state.db,
)
.await?;
TextContent::patch(&id, &form.context, &form.category, &form.text, &state.db).await?;
let text_contents = User::get_text_contents(&user.id, &state.db).await?;
let categories = User::get_user_categories(&user.id, &state.db).await?;

View File

@@ -29,7 +29,7 @@ use crate::html_state::HtmlState;
#[derive(Serialize)]
pub struct IndexPageData {
user: Option<User>,
latest_text_contents: Vec<TextContent>,
text_contents: Vec<TextContent>,
active_jobs: Vec<IngestionTask>,
conversation_archive: Vec<Conversation>,
}
@@ -39,20 +39,12 @@ pub async fn index_handler(
auth: AuthSessionType,
) -> Result<impl IntoResponse, HtmlError> {
let Some(user) = auth.current_user else {
return Ok(TemplateResponse::new_template(
"index/index.html",
IndexPageData {
user: None,
latest_text_contents: vec![],
active_jobs: vec![],
conversation_archive: vec![],
},
));
return Ok(TemplateResponse::redirect("/"));
};
let active_jobs = User::get_unfinished_ingestion_tasks(&user.id, &state.db).await?;
let latest_text_contents = User::get_latest_text_contents(&user.id, &state.db).await?;
let text_contents = User::get_latest_text_contents(&user.id, &state.db).await?;
let conversation_archive = User::get_user_conversations(&user.id, &state.db).await?;
@@ -60,7 +52,7 @@ pub async fn index_handler(
"index/index.html",
IndexPageData {
user: Some(user),
latest_text_contents,
text_contents,
active_jobs,
conversation_archive,
},

View File

@@ -54,7 +54,7 @@ pub async fn hide_ingress_form(
#[derive(Debug, TryFromMultipart)]
pub struct IngressParams {
pub content: Option<String>,
pub instructions: String,
pub context: String,
pub category: String,
#[form_data(limit = "10000000")] // Adjust limit as needed
#[form_data(default)]
@@ -68,7 +68,7 @@ pub async fn process_ingress_form(
) -> Result<impl IntoResponse, HtmlError> {
#[derive(Serialize)]
pub struct IngressFormData {
instructions: String,
context: String,
content: String,
category: String,
error: String,
@@ -78,7 +78,7 @@ pub async fn process_ingress_form(
return Ok(TemplateResponse::new_template(
"index/signed_in/ingress_form.html",
IngressFormData {
instructions: input.instructions.clone(),
context: input.context.clone(),
content: input.content.clone().unwrap_or_default(),
category: input.category.clone(),
error: "You need to either add files or content".to_string(),
@@ -98,7 +98,7 @@ pub async fn process_ingress_form(
let payloads = IngestionPayload::create_ingestion_payload(
input.content,
input.instructions,
input.context,
input.category,
file_infos,
user.id.as_str(),

View File

@@ -1,7 +1,7 @@
<div class="grid sm:grid-cols-2 lg:grid-cols-3 gap-4" id="text_content_cards">
<div class="columns-1 lg:columns-2 2xl:columns-3 gap-4" id="text_content_cards">
{% for text_content in text_contents %}
<div class="card min-w-72 bg-base-100 shadow" hx-get="/content/{{ text_content.id }}/read" hx-target="#modal"
hx-swap="innerHTML">
<div class="card cursor-pointer min-w-72 mb-4 bg-base-100 shadow break-inside-avoid-column"
hx-get="/content/{{ text_content.id }}/read" hx-target="#modal" hx-swap="innerHTML">
{% if text_content.url_info %}
<figure>
<img src="/file/{{text_content.url_info.image_id}}" alt="website screenshot" />
@@ -24,10 +24,10 @@
{{ text_content.created_at | datetimeformat(format="short", tz=user.timezone) }}
</p>
<div class="badge badge-soft badge-secondary mr-2">{{ text_content.category }}</div>
<div class="flex gap-2">
<div class="flex gap-2" hx-on:click="event.stopPropagation()">
{% if text_content.url_info %}
<button class="btn-btn-square btn-ghost btn-sm">
<a href="{{text_content.url_info.url}}">
<a href="{{text_content.url_info.url}}" target="_blank" rel="noopener noreferrer">
{% include "icons/globe_icon.html" %}
</a>
</button>

View File

@@ -15,8 +15,8 @@ class="flex flex-col flex-1 h-full"
<h3 class="text-lg font-bold">Edit Content</h3>
<div class="form-control">
<label class="floating-label">
<span class="label-text">Instructions</span>
<input type="text" name="instructions" value="{{ text_content.instructions }}" class="w-full input input-bordered">
<span class="label-text">Context</span>
<input type="text" name="context" value="{{ text_content.context }}" class="w-full input input-bordered">
</label>
</div>
<div class="form-control">

View File

@@ -1,8 +1,4 @@
{% extends "body_base.html" %}
{% block main %}
{% if user %}
{% include 'index/signed_in/base.html' %}
{% else %}
{% include 'auth/signin_form.html' %}
{% endif %}
{% endblock %}

View File

@@ -1,7 +1,12 @@
<div class="flex grow mt-2 sm:mt-4">
<div class="flex justify-center grow mt-2 sm:mt-4">
<div class="container">
{% include 'index/signed_in/searchbar.html' %}
<div>
<h2 class="font-extrabold">Recent content</h2>
{% include "content/content_list.html" %}
</div>
<div class="grid grid-cols-1 md:grid-cols-2 shadow my-10">
{% include "index/signed_in/active_jobs.html" %}

View File

@@ -7,18 +7,17 @@ enctype="multipart/form-data"
<h3 class="text-lg font-bold">Add new content</h3>
<div class="form-control">
<label class="floating-label">
<span>Instructions</span>
<textarea name="instructions" class="textarea w-full validator"
placeholder="Enter instructions for the AI here, help it understand what its seeing or how it should relate to the database"
required>{{ instructions }}</textarea>
<div class="validator-hint hidden">Instructions are required</div>
<span>Content</span>
<textarea name="content" class="textarea input-bordered w-full"
placeholder="Enter the content you want to ingest, it can be an URL or a text snippet">{{ content }}</textarea>
</label>
</div>
<div class="form-control">
<label class="floating-label">
<span>Content</span>
<textarea name="content" class="textarea input-bordered w-full"
placeholder="Enter the content you want to ingress, it can be an URL or a text snippet">{{ content }}</textarea>
<span>Context</span>
<textarea name="context" class="textarea w-full"
placeholder="Enter context for the AI here, help it understand what its seeing or how it should relate to the database">{{
context }}</textarea>
</label>
</div>
<div class="form-control">

View File

@@ -1,7 +1,7 @@
{% block latest_content_section %}
<ul id="latest_content_section" class="list">
<li class="py-4 text-center font-bold tracking-wide">Recently added content</li>
{% for item in latest_text_contents %}
{% for item in text_contents %}
<li class="list-row">
<div class="bg-accent rounded-box size-10 flex justify-center items-center text-accent-content">
{% if item.url_info %}
@@ -27,8 +27,8 @@
<span class="badge badge-xs badge-accent ml-1">{{item.category}}</span>
</div>
</div>
<p class="list-col-wrap text-xs [&:before]:content-['Instructions:_'] [&:before]:opacity-60">
{{item.instructions}}
<p class="list-col-wrap text-xs [&:before]:content-['Context:_'] [&:before]:opacity-60">
{{item.context}}
</p>
<button class="btn btn-disabled btn-square btn-ghost btn-sm">
{% include "icons/edit_icon.html" %}