Skip to content

Commit

Permalink
Refactor based on a review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
TamiTakamiya committed Feb 2, 2025
1 parent aadf74e commit fc677e6
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions ansible_ai_connect/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,21 @@ class ChatbotView(ProtectedTemplateView):
IsRHInternalUser | IsTestUser,
]

llm: ModelPipelineChatBot
chatbot_enabled: bool

def __init__(self):
super().__init__()
self.llm = apps.get_app_config("ai").get_model_pipeline(ModelPipelineChatBot)
self.chatbot_enabled = (
self.llm.config.inference_url
and self.llm.config.model_id
and settings.CHATBOT_DEFAULT_PROVIDER
)

def get(self, request):
# Open the chatbot page when the chatbot service is configured.
llm: ModelPipelineChatBot = apps.get_app_config("ai").get_model_pipeline(
ModelPipelineChatBot
)
if llm.config.inference_url and llm.config.model_id and settings.CHATBOT_DEFAULT_PROVIDER:
if self.chatbot_enabled:
return super().get(request)

# Otherwise, redirect to the home page.
Expand All @@ -139,11 +148,7 @@ 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"

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

return context

Expand Down

0 comments on commit fc677e6

Please sign in to comment.