Skip to content

Commit e163abe

Browse files
committed
pre-commit and new branch
1 parent 1ba0e74 commit e163abe

File tree

21 files changed

+347
-176
lines changed

21 files changed

+347
-176
lines changed

apps/django_langchain_voyageai/embedded_guinness_wine_dublin_cleaned2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21241,4 +21241,4 @@
2124121241
]
2124221242
}
2124321243
]
21244-
}
21244+
}

apps/django_langchain_voyageai/finder/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Django MongoDB Backend - Project Template
22

33
This is a Django project starter template for the Django MongoDB Backend.
4-
In order to use it with your version of Django:
4+
In order to use it with your version of Django:
55

66
- Find your Django version. To do so from the command line, make sure you
77
have Django installed and run:
@@ -14,7 +14,7 @@ django-admin --version
1414
## Create the Django project
1515

1616
From your shell, run the following command to create a new Django project
17-
replacing the `{{ project_name }}` and `{{ version }}` sections.
17+
replacing the `{{ project_name }}` and `{{ version }}` sections.
1818

1919
```bash
2020
django-admin startproject {{ project_name }} --template https://github.com/mongodb-labs/django-mongodb-project/archive/refs/heads/{{ version }}.x.zip
@@ -25,4 +25,4 @@ the command would look like this:
2525

2626
```bash
2727
django-admin startproject 5_0_example --template https://github.com/mongodb-labs/django-mongodb-project/archive/refs/heads/5.0.x.zip
28-
```
28+
```
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
from django.contrib import admin
2-
3-
# Register your models here.

apps/django_langchain_voyageai/finder/dublinfinder/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class DublinfinderConfig(AppConfig):
5-
default_auto_field = 'django_mongodb_backend.fields.ObjectIdAutoField'
6-
name = 'dublinfinder'
5+
default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
6+
name = "dublinfinder"

apps/django_langchain_voyageai/finder/dublinfinder/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from django.db import models
22
from django_mongodb_backend.fields import ArrayField, EmbeddedModelField
3-
from django_mongodb_backend.models import EmbeddedModel
43
from django_mongodb_backend.managers import MongoManager
4+
from django_mongodb_backend.models import EmbeddedModel
5+
56

67
# Embedded, so it doesn't have it's own collection.
78
class DisplayName(EmbeddedModel):
@@ -25,4 +26,4 @@ class Meta:
2526
managed = False
2627

2728
def __str__(self):
28-
return self.displayName.text
29+
return self.displayName.text

apps/django_langchain_voyageai/finder/dublinfinder/templates/search_results.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,3 @@ <h2>Results for "{{ query }}"</h2>
106106

107107
</body>
108108
</html>
109-
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
from django.test import TestCase
2-
3-
# Create your tests here.
Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
1+
import os
2+
13
from django.shortcuts import render
2-
import os
34
from dotenv import load_dotenv
4-
from langchain_voyageai.embeddings import VoyageAIEmbeddings
55
from langchain_mongodb.vectorstores import MongoDBAtlasVectorSearch
6+
from langchain_voyageai.embeddings import VoyageAIEmbeddings
67

78
load_dotenv()
89

10+
911
def search_places(request):
1012
# Get query from the user.
1113
query = request.GET.get("query", "")
1214
results = []
13-
15+
1416
# Same from our langchain_integration.py file.
1517
if query:
1618
# Use our API keys.
1719
voyage_api_key = os.getenv("VOYAGE_API_KEY")
1820
connection_string = os.getenv("MONGO_URI")
19-
20-
# This is our embeddings object.
21+
22+
# This is our embeddings object.
2123
embeddings = VoyageAIEmbeddings(
22-
voyage_api_key=voyage_api_key,
23-
model="voyage-3-lite"
24+
voyage_api_key=voyage_api_key, model="voyage-3-lite"
2425
)
25-
26+
2627
# This is your `database.collection`.
2728
namespace = "dublinfinder.placesinfo"
28-
29-
# Vector store with our embeddings model.
29+
30+
# Vector store with our embeddings model.
3031
vector_store = MongoDBAtlasVectorSearch.from_connection_string(
3132
connection_string=connection_string,
3233
namespace=namespace,
3334
embedding_key="embedding",
3435
index_name="vector_index",
3536
text_key="reviews",
36-
embedding=embeddings
37+
embedding=embeddings,
3738
)
3839

3940
# Similarity search, LangChain handles embedding the query.
4041
results_with_scores = vector_store.similarity_search_with_score(query, k=3)
41-
42+
4243
# Post-process and make it look pretty.
4344
processed_results = []
4445
maximum_char = 800
@@ -47,22 +48,19 @@ def search_places(request):
4748
name = doc.metadata.get("displayName", {}).get("text", "Unknown")
4849
address = doc.metadata.get("formattedAddress", "Unknown")
4950
review_text = doc.page_content if doc.page_content else ""
50-
51+
5152
# Refining it so we don't end in the middle of a sentence.
5253
if len(review_text) > maximum_char:
5354
shortened = review_text[:maximum_char]
54-
last_period = shortened.rfind('.')
55+
last_period = shortened.rfind(".")
5556
if last_period != -1:
56-
review = shortened[:last_period+1]
57-
58-
processed_results.append({
59-
"name": name,
60-
"address": address,
61-
"review": review,
62-
"score": score
63-
})
64-
57+
review = shortened[: last_period + 1]
58+
59+
processed_results.append(
60+
{"name": name, "address": address, "review": review, "score": score}
61+
)
62+
6563
results = processed_results
66-
64+
6765
# Template.
6866
return render(request, "search_results.html", {"results": results, "query": query})

apps/django_langchain_voyageai/finder/finder/asgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
from django.core.asgi import get_asgi_application
1313

14-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'finder.settings')
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "finder.settings")
1515

1616
application = get_asgi_application()

apps/django_langchain_voyageai/finder/finder/settings.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
https://docs.djangoproject.com/en/4.2/ref/settings/
1111
"""
1212

13-
import django_mongodb_backend
1413
import os
14+
from pathlib import Path
15+
16+
import django_mongodb_backend
1517
from dotenv import load_dotenv
1618

1719
load_dotenv()
1820
connection_string = os.getenv("MONGO_URI")
1921

2022

21-
from pathlib import Path
22-
2323
# Build paths inside the project like this: BASE_DIR / 'subdir'.
2424
BASE_DIR = Path(__file__).resolve().parent.parent
2525

@@ -28,7 +28,7 @@
2828
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
2929

3030
# SECURITY WARNING: keep the secret key used in production secret!
31-
SECRET_KEY = 'django-insecure-sx&$+jrfc(d!%wmvdh==+(+=57)1mx)fef7)b_bb48jbxqj9!k'
31+
SECRET_KEY = "django-insecure-sx&$+jrfc(d!%wmvdh==+(+=57)1mx)fef7)b_bb48jbxqj9!k"
3232

3333
# SECURITY WARNING: don't run with debug turned on in production!
3434
DEBUG = True
@@ -39,44 +39,44 @@
3939
# Application definition
4040

4141
INSTALLED_APPS = [
42-
'dublinfinder.apps.DublinfinderConfig',
43-
'finder.apps.MongoAdminConfig',
44-
'finder.apps.MongoAuthConfig',
45-
'finder.apps.MongoContentTypesConfig',
46-
'django.contrib.sessions',
47-
'django.contrib.messages',
48-
'django.contrib.staticfiles',
42+
"dublinfinder.apps.DublinfinderConfig",
43+
"finder.apps.MongoAdminConfig",
44+
"finder.apps.MongoAuthConfig",
45+
"finder.apps.MongoContentTypesConfig",
46+
"django.contrib.sessions",
47+
"django.contrib.messages",
48+
"django.contrib.staticfiles",
4949
]
5050

5151
MIDDLEWARE = [
52-
'django.middleware.security.SecurityMiddleware',
53-
'django.contrib.sessions.middleware.SessionMiddleware',
54-
'django.middleware.common.CommonMiddleware',
55-
'django.middleware.csrf.CsrfViewMiddleware',
56-
'django.contrib.auth.middleware.AuthenticationMiddleware',
57-
'django.contrib.messages.middleware.MessageMiddleware',
58-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
52+
"django.middleware.security.SecurityMiddleware",
53+
"django.contrib.sessions.middleware.SessionMiddleware",
54+
"django.middleware.common.CommonMiddleware",
55+
"django.middleware.csrf.CsrfViewMiddleware",
56+
"django.contrib.auth.middleware.AuthenticationMiddleware",
57+
"django.contrib.messages.middleware.MessageMiddleware",
58+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
5959
]
6060

61-
ROOT_URLCONF = 'finder.urls'
61+
ROOT_URLCONF = "finder.urls"
6262

6363
TEMPLATES = [
6464
{
65-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
66-
'DIRS': [],
67-
'APP_DIRS': True,
68-
'OPTIONS': {
69-
'context_processors': [
70-
'django.template.context_processors.debug',
71-
'django.template.context_processors.request',
72-
'django.contrib.auth.context_processors.auth',
73-
'django.contrib.messages.context_processors.messages',
65+
"BACKEND": "django.template.backends.django.DjangoTemplates",
66+
"DIRS": [],
67+
"APP_DIRS": True,
68+
"OPTIONS": {
69+
"context_processors": [
70+
"django.template.context_processors.debug",
71+
"django.template.context_processors.request",
72+
"django.contrib.auth.context_processors.auth",
73+
"django.contrib.messages.context_processors.messages",
7474
],
7575
},
7676
},
7777
]
7878

79-
WSGI_APPLICATION = 'finder.wsgi.application'
79+
WSGI_APPLICATION = "finder.wsgi.application"
8080

8181

8282
# Database
@@ -91,26 +91,26 @@
9191

9292
AUTH_PASSWORD_VALIDATORS = [
9393
{
94-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
94+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
9595
},
9696
{
97-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
97+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
9898
},
9999
{
100-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
100+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
101101
},
102102
{
103-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
103+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
104104
},
105105
]
106106

107107

108108
# Internationalization
109109
# https://docs.djangoproject.com/en/4.2/topics/i18n/
110110

111-
LANGUAGE_CODE = 'en-us'
111+
LANGUAGE_CODE = "en-us"
112112

113-
TIME_ZONE = 'UTC'
113+
TIME_ZONE = "UTC"
114114

115115
USE_I18N = True
116116

@@ -120,15 +120,15 @@
120120
# Static files (CSS, JavaScript, Images)
121121
# https://docs.djangoproject.com/en/4.2/howto/static-files/
122122

123-
STATIC_URL = 'static/'
123+
STATIC_URL = "static/"
124124

125125
# Default primary key field type
126126
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
127127

128-
DEFAULT_AUTO_FIELD = 'django_mongodb_backend.fields.ObjectIdAutoField'
128+
DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField"
129129

130130
MIGRATION_MODULES = {
131-
'admin': 'mongo_migrations.admin',
132-
'auth': 'mongo_migrations.auth',
133-
'contenttypes': 'mongo_migrations.contenttypes',
131+
"admin": "mongo_migrations.admin",
132+
"auth": "mongo_migrations.auth",
133+
"contenttypes": "mongo_migrations.contenttypes",
134134
}

0 commit comments

Comments
 (0)