Skip to content

Commit

Permalink
feat: app icon generated through stable diffusion XL
Browse files Browse the repository at this point in the history
fix: error when showing match description
refactor: avoid panicking when running a cognitive query & return the proper error if the user's doc is missing info
  • Loading branch information
Carbonhell committed Nov 30, 2023
1 parent b355ccc commit 7ff84ee
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 19 deletions.
7 changes: 5 additions & 2 deletions Auth/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ async fn handle_auth(State(state): State<Arc<AppState>>, Json(payload): Json<Aut
}
};

let x = state.user_collection_client.create_document(user_document.clone()).is_upsert(true).await;
state
.user_collection_client
.create_document(user_document.clone())
.is_upsert(true)
.await?;
println!("User {} saved.", user_document.id);
Ok(user_document)
}
Expand All @@ -105,7 +109,6 @@ async fn main() -> azure_core::Result<()> {

let shared_state = Arc::new(AppState { user_collection_client: collection_client });


// build our application with a single route
let app = Router::new()
.route("/api/auth", post(handle_auth))
Expand Down
5 changes: 3 additions & 2 deletions localink_client/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:label="localink_client"
android:label="Localink"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/launcher_icon">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added localink_client/assets/app-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion localink_client/lib/src/widgets/homepage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class HomepageState extends State<Homepage> {
authResponse: authResponse, match: item)),
);
}
: showDescription(item),
: () => showDescription(item),
updateItem: (newStatus) {
setState(() {
item.matchStatus = newStatus;
Expand Down
56 changes: 56 additions & 0 deletions localink_client/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.13.0"
archive:
dependency: transitive
description:
name: archive
sha256: "7b875fd4a20b165a3084bd2d210439b22ebc653f21cea4842729c0c30c82596b"
url: "https://pub.dev"
source: hosted
version: "3.4.9"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -49,6 +57,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.0"
checked_yaml:
dependency: transitive
description:
name: checked_yaml
sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff
url: "https://pub.dev"
source: hosted
version: "2.0.3"
cli_util:
dependency: transitive
description:
name: cli_util
sha256: b8db3080e59b2503ca9e7922c3df2072cf13992354d5e944074ffa836fba43b7
url: "https://pub.dev"
source: hosted
version: "0.4.0"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -134,6 +158,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.1.0"
flutter_launcher_icons:
dependency: "direct main"
description:
name: flutter_launcher_icons
sha256: "526faf84284b86a4cb36d20a5e45147747b7563d921373d4ee0559c54fcdbcea"
url: "https://pub.dev"
source: hosted
version: "0.13.1"
flutter_lints:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -376,6 +408,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.2"
image:
dependency: transitive
description:
name: image
sha256: "028f61960d56f26414eb616b48b04eb37d700cbe477b7fb09bf1d7ce57fd9271"
url: "https://pub.dev"
source: hosted
version: "4.1.3"
intl:
dependency: transitive
description:
Expand All @@ -400,6 +440,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.4"
json_annotation:
dependency: transitive
description:
name: json_annotation
sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467
url: "https://pub.dev"
source: hosted
version: "4.8.1"
latlong2:
dependency: transitive
description:
Expand Down Expand Up @@ -520,6 +568,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.6"
pointycastle:
dependency: transitive
description:
name: pointycastle
sha256: "7c1e5f0d23c9016c5bbd8b1473d0d3fb3fc851b876046039509e18e0c7485f2c"
url: "https://pub.dev"
source: hosted
version: "3.7.3"
polylabel:
dependency: transitive
description:
Expand Down
6 changes: 6 additions & 0 deletions localink_client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies:
geolocator: ^10.1.0
google_maps_flutter: ^2.5.0
flutter_map_location_marker: ^8.0.2
flutter_launcher_icons: ^0.13.1

dev_dependencies:
flutter_test:
Expand Down Expand Up @@ -74,6 +75,11 @@ flutter:
- assets/svg/login-banner.svg
- .env

flutter_launcher_icons:
android: "launcher_icon"
image_path: "assets/app-icon.png"
min_sdk_android: 21 # android min sdk min:16, default 21

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware

Expand Down
44 changes: 30 additions & 14 deletions shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use axum::{
Json,
};
use azure_data_cosmos::prelude::{
AuthorizationToken, CloudLocation, CollectionClient, CosmosClient, Param, Query, GetDocumentResponse
AuthorizationToken, CloudLocation, CollectionClient, CosmosClient, Param, Query, GetDocumentResponse,
};
use base64::engine::general_purpose::STANDARD_NO_PAD;
use base64::Engine;
Expand All @@ -30,15 +30,15 @@ pub enum MatchStatus {
/// Allows visualizing location data to allow users to meet.
Accepted = 3,
/// Discarded match, could be useful in future to prevent matching the same user again.
Denied = 4
Denied = 4,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Match {
pub id: String,
pub name: String,
pub description: String,
pub match_status: MatchStatus
pub match_status: MatchStatus,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand All @@ -50,7 +50,8 @@ pub struct UserDocument {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description_embeddings: Option<Vec<f64>>, // todo vec length is constant, we can optimize this
pub description_embeddings: Option<Vec<f64>>,
// todo vec length is constant, we can optimize this
#[serde(skip_serializing_if = "Option::is_none")]
pub location: Option<Point>,
/// Denotes matches related to this user.
Expand All @@ -72,7 +73,8 @@ pub struct UserSearchData {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description_embeddings: Option<Vec<f64>>, // todo vec length is constant, we can optimize this
pub description_embeddings: Option<Vec<f64>>,
// todo vec length is constant, we can optimize this
#[serde(skip_serializing_if = "Option::is_none")]
pub location: Option<Point>,
}
Expand Down Expand Up @@ -180,12 +182,12 @@ pub async fn get_user_document_by_id(

let result = doc_client.map_err(|_| AuthError).map(|doc| {
if let GetDocumentResponse::Found(document) = doc {
return Ok(document.document.document)
} else {
return Err(NotFoundError)
};
return Ok(document.document.document);
} else {
return Err(NotFoundError);
};
})?;
println!("Result: {:?}",result);
println!("Result: {:?}", result);
result
}

Expand Down Expand Up @@ -302,6 +304,7 @@ pub async fn index_documents(

Ok(())
}

#[derive(Serialize, Deserialize)]
struct VectorQuery {
kind: String,
Expand Down Expand Up @@ -339,14 +342,27 @@ pub async fn cognitive_query(
index_name: &str,
admin_key: &str,
user_document: &UserSearchData,
) -> Result<CognitiveResponse, reqwest::Error> {
) -> Result<CognitiveResponse, AppError> {
let user_location = user_document
.location
.as_ref()
.ok_or(AppError::MissingLocationData)?;
let user_description_embeddings = user_document
.description_embeddings
.as_ref()
.ok_or(AppError::NotFoundError)?;

let cognitive_query_body = CognitiveQueryBody {
select: "id, name, description".to_owned(),
filter: format!("id ne '{}'", user_document.id),
filter: format!("id ne '{}' and geo.distance(location, geography'POINT({} {})') le 5",
user_document.id,
user_location.coordinates[0],
user_location.coordinates[1]
),
vectorFilterMode: "preFilter".to_owned(),
vectorQueries: vec![VectorQuery {
kind: "vector".to_owned(),
vector: user_document.description_embeddings.clone().unwrap(),
vector: user_description_embeddings.to_vec(),
fields: "description_embeddings".to_owned(),
k: 3,
}],
Expand All @@ -365,7 +381,7 @@ pub async fn cognitive_query(

match response.status() {
StatusCode::OK => Ok(response.json::<CognitiveResponse>().await?),
_ => panic!("Error with cognitive query request"),
_ => Err(AppError::GenericError),
}
}

Expand Down

0 comments on commit 7ff84ee

Please sign in to comment.