Skip to content

Commit

Permalink
fix: API handler import so linter doesn't auto remove
Browse files Browse the repository at this point in the history
  • Loading branch information
janaka committed Sep 9, 2024
1 parent 8422981 commit 4a68844
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions web/api/index_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,18 @@ class name: route replace capitalise route segments remove `/` and `_`. Example:
token_handler, # noqa: F401 DO NOT REMOVE
)
from .integration.slack import index_handler # noqa: F401 DO NOT REMOVE

__all__ = [
"chat_completion_handler",
"hello_handler",
"rag_completion_handler",
"spaces_handler",
"threads_handler",
"token_handler",
"index_handler",
]


def setup() -> None:
"""Fake method to keep the linter happy."""
pass
9 changes: 9 additions & 0 deletions web/api/threads_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from datetime import datetime
from typing import Self

import docq.manage_spaces as ms
import docq.run_queries as rq
from docq.data_source.list import SpaceDataSources
from docq.domain import SpaceKey
from docq.model_selection.main import LlmUsageSettingsCollection, get_saved_model_settings_collection
from docq.support.llm import _get_service_context
Expand Down Expand Up @@ -85,6 +87,13 @@ def post(self: Self, feature_: FEATURE) -> None:
request = ThreadPostRequestModel.model_validate_json(self.request.body)
thread_id = rq.create_history_thread(request.topic, feature)
thread = rq.list_thread_history(feature, thread_id)
if not thread_id:
raise HTTPError(status_code=500, reason="Internal server error", log_message="Thread creation failed.")

space_thread = ms.create_thread_space(
self.selected_org_id, thread_id, request.topic, SpaceDataSources.MANUAL_UPLOAD.name
)
print("space_thread: ", space_thread)
self.set_status(201) # 201 Created
self.write(
ThreadResponseModel(response=ThreadModel(**_get_thread_object(thread[0]))).model_dump(by_alias=True)
Expand Down
5 changes: 5 additions & 0 deletions web/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
from utils.streamlit_application import st_app
from utils.streamlit_page_extension import StreamlitPageExtension as StPage

#### DO NOT REMOVE THIS IMPORT ####
import web.api.index_handler as h # noqa: F401

h.setup()
####

st_app.print_registered_routes()

Expand Down

0 comments on commit 4a68844

Please sign in to comment.