Skip to content

Commit

Permalink
Add stream to HttpConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
TamiTakamiya committed Jan 30, 2025
1 parent d60df5b commit aadf74e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ def __init__(
timeout: Optional[int],
enable_health_check: Optional[bool],
verify_ssl: bool,
stream: bool = False,
):
super().__init__(inference_url, model_id, timeout, enable_health_check)
self.verify_ssl = verify_ssl
self.stream = stream

verify_ssl: bool
stream: bool


@Register(api_type="http")
Expand All @@ -60,10 +63,12 @@ def __init__(self, **kwargs):
timeout=kwargs["timeout"],
enable_health_check=kwargs["enable_health_check"],
verify_ssl=kwargs["verify_ssl"],
stream=kwargs["stream"],
),
)


@Register(api_type="http")
class HttpConfigurationSerializer(BaseConfigSerializer):
verify_ssl = serializers.BooleanField(required=False, default=True)
stream = serializers.BooleanField(required=False, default=False)
1 change: 0 additions & 1 deletion ansible_ai_connect/main/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,6 @@ def is_ssl_enabled(value: str) -> bool:
# ------------------------------------------
CHATBOT_DEFAULT_PROVIDER = os.getenv("CHATBOT_DEFAULT_PROVIDER")
CHATBOT_DEBUG_UI = os.getenv("CHATBOT_DEBUG_UI", "False").lower() == "true"
CHATBOT_STREAM = os.getenv("CHATBOT_STREAM", "False").lower() == "true"
# ==========================================

# ==========================================
Expand Down
1 change: 1 addition & 0 deletions ansible_ai_connect/main/settings/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def load_from_env_vars():
"inference_url": chatbot_service_url or "http://localhost:8000",
"model_id": chatbot_service_model_id or "granite3-8b",
"verify_ssl": model_service_verify_ssl,
"stream": False,
},
}

Expand Down
7 changes: 6 additions & 1 deletion ansible_ai_connect/main/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
from http import HTTPStatus
from textwrap import dedent

from django.apps import apps
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser, Group
from django.http import HttpResponseRedirect
from django.test import RequestFactory, TestCase, modify_settings, override_settings
from django.urls import reverse
from rest_framework.test import APITransactionTestCase

from ansible_ai_connect.ai.api.model_pipelines.pipelines import ModelPipelineChatBot
from ansible_ai_connect.main.settings.base import SOCIAL_AUTH_OIDC_KEY
from ansible_ai_connect.main.views import LoginView
from ansible_ai_connect.test_utils import (
Expand Down Expand Up @@ -348,8 +350,11 @@ def test_chatbot_view_with_debug_ui(self):
self.assertEqual(r.status_code, HTTPStatus.OK)
self.assertContains(r, '<div id="debug" hidden>true</div>')

@override_settings(CHATBOT_STREAM=True)
def test_chatbot_view_with_streaming_enabled(self):
llm: ModelPipelineChatBot = apps.get_app_config("ai").get_model_pipeline(
ModelPipelineChatBot
)
llm.config.stream = True
self.client.force_login(user=self.rh_user)
r = self.client.get(reverse("chatbot"), {"stream": "true"})
self.assertEqual(r.status_code, HTTPStatus.OK)
Expand Down
6 changes: 5 additions & 1 deletion ansible_ai_connect/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ def get_context_data(self, **kwargs):
if user and user.is_authenticated:
context["user_name"] = user.username
context["debug"] = "true" if settings.CHATBOT_DEBUG_UI else "false"
context["stream"] = "true" if settings.CHATBOT_STREAM else "false"

llm: ModelPipelineChatBot = apps.get_app_config("ai").get_model_pipeline(
ModelPipelineChatBot
)
context["stream"] = "true" if llm.config.stream else "false"

return context

Expand Down

0 comments on commit aadf74e

Please sign in to comment.