mirror of
https://github.com/perstarkse/minne.git
synced 2026-03-27 20:01:31 +01:00
error handling, and setting result as return
This commit is contained in:
@@ -1,41 +1,25 @@
|
||||
use crate::{
|
||||
error::ApiError,
|
||||
ingress::types::ingress_input::{create_ingress_objects, IngressInput},
|
||||
rabbitmq::publisher::RabbitMQProducer,
|
||||
storage::db::SurrealDbClient,
|
||||
};
|
||||
use axum::{http::StatusCode, response::IntoResponse, Extension, Json};
|
||||
use std::sync::Arc;
|
||||
use tracing::{error, info};
|
||||
use tracing::info;
|
||||
|
||||
pub async fn ingress_handler(
|
||||
Extension(producer): Extension<Arc<RabbitMQProducer>>,
|
||||
Extension(db_client): Extension<Arc<SurrealDbClient>>,
|
||||
Json(input): Json<IngressInput>,
|
||||
) -> impl IntoResponse {
|
||||
) -> Result<impl IntoResponse, ApiError> {
|
||||
info!("Received input: {:?}", input);
|
||||
|
||||
match create_ingress_objects(input, &db_client).await {
|
||||
Ok(objects) => {
|
||||
for object in objects {
|
||||
match producer.publish(&object).await {
|
||||
Ok(_) => {
|
||||
info!("Message published successfully");
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to publish message: {:?}", e);
|
||||
return (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"Failed to publish message",
|
||||
)
|
||||
.into_response();
|
||||
}
|
||||
}
|
||||
}
|
||||
StatusCode::OK.into_response()
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to process input: {:?}", e);
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, "Failed to process input").into_response()
|
||||
}
|
||||
let ingress_objects = create_ingress_objects(input, &db_client).await?;
|
||||
|
||||
for object in ingress_objects {
|
||||
producer.publish(&object).await?;
|
||||
}
|
||||
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
use crate::storage::db::SurrealDbClient;
|
||||
use axum::{http::StatusCode, response::IntoResponse, Extension, Json};
|
||||
use crate::{
|
||||
error::ApiError,
|
||||
retrieval::vector::find_items_by_vector_similarity,
|
||||
storage::{db::SurrealDbClient, types::knowledge_entity::KnowledgeEntity},
|
||||
};
|
||||
use axum::{response::IntoResponse, Extension, Json};
|
||||
use serde::Deserialize;
|
||||
use std::sync::Arc;
|
||||
use tracing::{error, info};
|
||||
use tracing::info;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct QueryInput {
|
||||
@@ -12,6 +16,18 @@ pub struct QueryInput {
|
||||
pub async fn query_handler(
|
||||
Extension(db_client): Extension<Arc<SurrealDbClient>>,
|
||||
Json(query): Json<QueryInput>,
|
||||
) -> impl IntoResponse {
|
||||
) -> Result<impl IntoResponse, ApiError> {
|
||||
info!("Received input: {:?}", query);
|
||||
let openai_client = async_openai::Client::new();
|
||||
|
||||
let closest_items: Vec<KnowledgeEntity> = find_items_by_vector_similarity(
|
||||
10,
|
||||
query.query,
|
||||
&db_client,
|
||||
"knowledge_entity".to_string(),
|
||||
&openai_client,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(format!("{:?}", closest_items))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user