Skip to content

Commit

Permalink
Import AI agent within view post code (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbertrand authored Jan 2, 2025
1 parent 36ebf4f commit cc0be65
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ai_chat/apps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""learning_resources app config"""
"""ai_chat app config"""

from django.apps import AppConfig

Expand Down
3 changes: 2 additions & 1 deletion ai_chat/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from rest_framework.request import Request

from ai_chat import serializers
from ai_chat.agents import SearchAgent
from ai_chat.permissions import SearchAgentPermissions

log = logging.getLogger(__name__)
Expand All @@ -34,6 +33,8 @@ class SearchAgentView(views.APIView):
)
def post(self, request: Request) -> StreamingHttpResponse:
"""Handle a POST request to the chatbot agent."""
from ai_chat.agents import SearchAgent

serializer = serializers.ChatRequestSerializer(
data=request.data, context={"request": request}
)
Expand Down
2 changes: 1 addition & 1 deletion ai_chat/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_post_search_agent_endpoint(
user_message = "Do you have any good physics courses?"
temperature = 0.1
system_prompt = "Answer this question as best you can"
mock_agent = mocker.patch("ai_chat.views.SearchAgent", autospec=True)
mock_agent = mocker.patch("ai_chat.agents.SearchAgent", autospec=True)
mock_agent.return_value.get_completion = mocker.Mock(
return_value=iter(expected_answer)
)
Expand Down
2 changes: 1 addition & 1 deletion main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
"drf_spectacular",
# Put our apps after this point
"main",
"ai_chat",
"authentication",
"channels",
"profiles",
Expand All @@ -119,6 +118,7 @@
"testimonials",
"data_fixtures",
"vector_search",
"ai_chat",
)

if not get_bool("RUN_DATA_MIGRATIONS", default=False):
Expand Down
2 changes: 1 addition & 1 deletion main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
re_path(r"^o/", include("oauth2_provider.urls", namespace="oauth2_provider")),
re_path(r"^admin/", admin.site.urls),
re_path(r"", include("authentication.urls")),
re_path(r"", include("ai_chat.urls")),
re_path(r"", include("channels.urls")),
re_path(r"", include("profiles.urls")),
re_path(r"", include("embedly.urls")),
Expand All @@ -58,7 +59,6 @@
re_path(r"", include("testimonials.urls")),
re_path(r"", include("news_events.urls")),
re_path(r"", include(features_router.urls)),
re_path(r"", include("ai_chat.urls")),
re_path(r"^app", RedirectView.as_view(url=settings.APP_BASE_URL)),
# Hijack
re_path(r"^hijack/", include("hijack.urls", namespace="hijack")),
Expand Down

0 comments on commit cc0be65

Please sign in to comment.