Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unittests #77

Merged
merged 10 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,27 @@ jobs:
name: docker-executor
python_version: "<<parameters.python_version>>"
parallelism: 4
working_directory: ~/project/api
steps:
- checkout
- checkout:
path: ~/project
- run:
name: Install Dependencies
command: cd api && poetry install --no-root && rm -rf $POETRY_CACHE_DIR
command: poetry install --no-root
- run:
name: Set PYTHONPATH
command: echo 'export PYTHONPATH=$PYTHONPATH:.' >> $BASH_ENV
- run:
name: Run tests
command: cd api && poetry run pytest ../tests
command: |
poetry run pytest ../tests || poetry run pytest --last-failed ../tests
sunank200 marked this conversation as resolved.
Show resolved Hide resolved

precommit:
executor: docker-executor
working_directory: ~/project/api
steps:
- checkout
- checkout:
path: ~/project
- run:
name: Install Pre-commit
command: pip install pre-commit
Expand Down
Empty file added api/ask_astro/__init__.py
Empty file.
3 changes: 2 additions & 1 deletion api/ask_astro/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import os
from logging import getLogger

from sanic import Request, Sanic

from ask_astro.rest.controllers import register_routes
from ask_astro.slack.app import app_handler, slack_app
from ask_astro.slack.controllers import register_controllers
from sanic import Request, Sanic

# set the logging level based on an env var
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
Expand Down
Empty file.
21 changes: 11 additions & 10 deletions api/ask_astro/chains/answer_question.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
from __future__ import annotations

from ask_astro.clients.weaviate_ import docsearch
from ask_astro.config import AzureOpenAIParams
from ask_astro.settings import (
CONVERSATIONAL_RETRIEVAL_LLM_CHAIN_DEPLOYMENT_NAME,
CONVERSATIONAL_RETRIEVAL_LLM_CHAIN_TEMPERATURE,
CONVERSATIONAL_RETRIEVAL_LOAD_QA_CHAIN_DEPLOYMENT_NAME,
CONVERSATIONAL_RETRIEVAL_LOAD_QA_CHAIN_TEMPERATURE,
MULTI_QUERY_RETRIEVER_DEPLOYMENT_NAME,
MULTI_QUERY_RETRIEVER_TEMPERATURE,
)
from langchain import LLMChain
from langchain.chains import ConversationalRetrievalChain
from langchain.chains.conversational_retrieval.prompts import CONDENSE_QUESTION_PROMPT
Expand All @@ -23,6 +13,17 @@
)
from langchain.retrievers import MultiQueryRetriever

from ask_astro.clients.weaviate_ import docsearch
from ask_astro.config import AzureOpenAIParams
from ask_astro.settings import (
CONVERSATIONAL_RETRIEVAL_LLM_CHAIN_DEPLOYMENT_NAME,
CONVERSATIONAL_RETRIEVAL_LLM_CHAIN_TEMPERATURE,
CONVERSATIONAL_RETRIEVAL_LOAD_QA_CHAIN_DEPLOYMENT_NAME,
CONVERSATIONAL_RETRIEVAL_LOAD_QA_CHAIN_TEMPERATURE,
MULTI_QUERY_RETRIEVER_DEPLOYMENT_NAME,
MULTI_QUERY_RETRIEVER_TEMPERATURE,
)

with open("ask_astro/templates/combine_docs_chat_prompt.txt") as system_prompt_fd:
"""Load system prompt template from a file and structure it."""
messages = [
Expand Down
Empty file.
5 changes: 3 additions & 2 deletions api/ask_astro/clients/weaviate_.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
as well as text embeddings using the OpenAIEmbeddings from the LangChain library.
"""
import weaviate
from ask_astro.config import AzureOpenAIParams, WeaviateConfig
from ask_astro.settings import WEAVIATE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME, WEAVIATE_OPENAI_EMBEDDINGS_MODEL
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import Weaviate
from weaviate import Client as WeaviateClient

from ask_astro.config import AzureOpenAIParams, WeaviateConfig
from ask_astro.settings import WEAVIATE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME, WEAVIATE_OPENAI_EMBEDDINGS_MODEL

# Initialize OpenAI embeddings using the specified parameters.
embeddings = OpenAIEmbeddings(
**AzureOpenAIParams.us_east,
Expand Down
Empty file.
Empty file.
3 changes: 2 additions & 1 deletion api/ask_astro/rest/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
from logging import getLogger
from typing import Callable

from sanic import Sanic, response

from ask_astro.rest.controllers.get_request import on_get_request
from ask_astro.rest.controllers.list_recent_requests import on_list_recent_requests
from ask_astro.rest.controllers.post_request import on_post_request
from ask_astro.rest.controllers.submit_feedback import on_submit_feedback
from sanic import Sanic, response

logger = getLogger(__name__)

Expand Down
5 changes: 3 additions & 2 deletions api/ask_astro/rest/controllers/get_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from logging import getLogger
from uuid import UUID

from sanic import Request, json
from sanic_ext import openapi

from ask_astro.clients.firestore import firestore_client
from ask_astro.config import FirestoreCollections
from ask_astro.models.request import AskAstroRequest
from sanic import Request, json
from sanic_ext import openapi

logger = getLogger(__name__)

Expand Down
7 changes: 4 additions & 3 deletions api/ask_astro/rest/controllers/list_recent_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

from logging import getLogger

from ask_astro.clients.firestore import firestore_client
from ask_astro.config import FirestoreCollections
from ask_astro.models.request import AskAstroRequest
from pydantic.v1 import BaseModel, Field
from sanic import Request, json
from sanic_ext import openapi

from ask_astro.clients.firestore import firestore_client
from ask_astro.config import FirestoreCollections
from ask_astro.models.request import AskAstroRequest

logger = getLogger(__name__)


Expand Down
10 changes: 6 additions & 4 deletions api/ask_astro/rest/controllers/post_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import uuid
from logging import getLogger

from ask_astro.clients.firestore import firestore_client
from ask_astro.config import FirestoreCollections
from ask_astro.models.request import AskAstroRequest
from ask_astro.services.questions import answer_question
from langchain.schema import AIMessage, HumanMessage
from pydantic.v1 import BaseModel, Field
from sanic import Request, json
from sanic_ext import openapi

from ask_astro.clients.firestore import firestore_client
from ask_astro.config import FirestoreCollections
from ask_astro.models.request import AskAstroRequest

logger = getLogger(__name__)


Expand Down Expand Up @@ -45,6 +45,8 @@ async def on_post_request(request: Request) -> json:
:param request: The Sanic request object.
"""
try:
from ask_astro.services.questions import answer_question

if "prompt" not in request.json:
return json({"error": "prompt is required"}, status=400)

Expand Down
3 changes: 2 additions & 1 deletion api/ask_astro/rest/controllers/submit_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from logging import getLogger
from uuid import UUID

from ask_astro.services.feedback import submit_feedback
from pydantic.v1 import BaseModel, Field
from sanic import HTTPResponse, Request
from sanic_ext import openapi

from ask_astro.services.feedback import submit_feedback

logger = getLogger(__name__)


Expand Down
Empty file.
6 changes: 4 additions & 2 deletions api/ask_astro/services/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import time
from logging import getLogger

from ask_astro.chains.answer_question import answer_question_chain
from ask_astro.clients.firestore import firestore_client
from ask_astro.config import FirestoreCollections
from ask_astro.models.request import AskAstroRequest, Source
from langchain import callbacks

logger = getLogger(__name__)

Expand All @@ -32,6 +30,10 @@ async def answer_question(request: AskAstroRequest) -> None:
:param request: The request to answer the question.
"""
try:
from langchain import callbacks

from ask_astro.chains.answer_question import answer_question_chain

# First, mark the request as in_progress and add it to the database
request.status = "in_progress"
await _update_firestore_request(request)
Expand Down
Empty file.
7 changes: 4 additions & 3 deletions api/ask_astro/slack/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
- `files:read`: View files shared in channels and conversations the app has access to.
"""

from ask_astro.config import FirestoreCollections, SlackAppConfig
from ask_astro.stores.installation_store import AsyncFirestoreInstallationStore
from ask_astro.stores.oauth_state_store import AsyncFirestoreOAuthStateStore
from slack_bolt.adapter.sanic import AsyncSlackRequestHandler
from slack_bolt.app.async_app import AsyncApp
from slack_bolt.oauth.async_oauth_settings import AsyncOAuthSettings

from ask_astro.config import FirestoreCollections, SlackAppConfig
from ask_astro.stores.installation_store import AsyncFirestoreInstallationStore
from ask_astro.stores.oauth_state_store import AsyncFirestoreOAuthStateStore

oauth_settings = AsyncOAuthSettings(
client_id=SlackAppConfig.client_id,
client_secret=SlackAppConfig.client_secret,
Expand Down
3 changes: 2 additions & 1 deletion api/ask_astro/slack/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

from logging import getLogger

from slack_bolt.async_app import AsyncApp

from ask_astro.slack.controllers.feedback.bad import handle_feedback_bad
from ask_astro.slack.controllers.feedback.good import handle_feedback_good
from ask_astro.slack.controllers.mention import on_mention
from slack_bolt.async_app import AsyncApp

logger = getLogger(__name__)

Expand Down
Empty file.
3 changes: 2 additions & 1 deletion api/ask_astro/slack/controllers/feedback/bad.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from logging import getLogger
from typing import Any

from ask_astro.services.feedback import submit_feedback
from slack_bolt.async_app import AsyncAck, AsyncRespond
from slack_sdk.errors import SlackApiError
from slack_sdk.web.async_client import AsyncWebClient

from ask_astro.services.feedback import submit_feedback

logger = getLogger(__name__)


Expand Down
3 changes: 2 additions & 1 deletion api/ask_astro/slack/controllers/feedback/good.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from logging import getLogger
from typing import Any

from ask_astro.services.feedback import submit_feedback
from slack_bolt.async_app import AsyncAck, AsyncRespond
from slack_sdk.errors import SlackApiError
from slack_sdk.web.async_client import AsyncWebClient

from ask_astro.services.feedback import submit_feedback

logger = getLogger(__name__)


Expand Down
7 changes: 4 additions & 3 deletions api/ask_astro/slack/controllers/mention.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
from logging import getLogger
from typing import Any

from ask_astro.models.request import AskAstroRequest
from ask_astro.services.questions import answer_question
from ask_astro.slack.utils import get_blocks, markdown_to_slack
from langchain.schema import AIMessage, HumanMessage
from slack_bolt.async_app import AsyncAck, AsyncSay
from slack_sdk.errors import SlackApiError
from slack_sdk.web.async_client import AsyncWebClient

from ask_astro.models.request import AskAstroRequest
from ask_astro.services.questions import answer_question
from ask_astro.slack.utils import get_blocks, markdown_to_slack

logger = getLogger(__name__)

THOUGHT_BALLOON_REACTION = "thought_balloon"
Expand Down
Loading