diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml index 11b68f13453..2ad1b9d778a 100644 --- a/.github/workflows/linter.yaml +++ b/.github/workflows/linter.yaml @@ -52,7 +52,7 @@ jobs: env: DEFAULT_BRANCH: main GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - FILTER_REGEX_EXCLUDE: 'gemini/sample-apps/finance-advisor-spanner/.*\.sql' + FILTER_REGEX_EXCLUDE: 'gemini/sample-apps/finance-advisor-spanner/.*\.sql|gemini/sample-apps/conversational-genai-app-template/.*' JAVASCRIPT_DEFAULT_STYLE: prettier LOG_LEVEL: WARN SHELLCHECK_OPTS: -e SC1091 -e 2086 diff --git a/gemini/sample-apps/conversational-genai-app-template/app/chain.py b/gemini/sample-apps/conversational-genai-app-template/app/chain.py index 497ec5c88d5..94cfbfdb7c9 100644 --- a/gemini/sample-apps/conversational-genai-app-template/app/chain.py +++ b/gemini/sample-apps/conversational-genai-app-template/app/chain.py @@ -13,8 +13,7 @@ # limitations under the License. from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder -from langchain_google_vertexai import ChatVertexAI, HarmBlockThreshold, HarmCategory - +from langchain_google_vertexai import ChatVertexAI llm = ChatVertexAI( model_name="gemini-1.5-flash-001", diff --git a/gemini/sample-apps/conversational-genai-app-template/app/eval/utils.py b/gemini/sample-apps/conversational-genai-app-template/app/eval/utils.py index df070cc65ec..37a1309c950 100644 --- a/gemini/sample-apps/conversational-genai-app-template/app/eval/utils.py +++ b/gemini/sample-apps/conversational-genai-app-template/app/eval/utils.py @@ -12,17 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -from concurrent.futures import ThreadPoolExecutor -from functools import partial import glob import logging import os +from concurrent.futures import ThreadPoolExecutor +from functools import partial from typing import Any, Callable, Dict, Iterator, List import nest_asyncio import pandas as pd -from tqdm import tqdm import yaml +from tqdm import tqdm nest_asyncio.apply() diff --git a/gemini/sample-apps/conversational-genai-app-template/app/patterns/custom_rag_qa/chain.py b/gemini/sample-apps/conversational-genai-app-template/app/patterns/custom_rag_qa/chain.py index 4ee8d39ea50..2591f978198 100644 --- a/gemini/sample-apps/conversational-genai-app-template/app/patterns/custom_rag_qa/chain.py +++ b/gemini/sample-apps/conversational-genai-app-template/app/patterns/custom_rag_qa/chain.py @@ -16,13 +16,14 @@ import logging from typing import Any, Dict, Iterator -from app.patterns.custom_rag_qa.templates import query_rewrite_template, rag_template -from app.patterns.custom_rag_qa.vector_store import get_vector_store -from app.utils.output_types import OnChatModelStreamEvent, OnToolEndEvent, custom_chain import google +import vertexai from langchain_google_community.vertex_rank import VertexAIRank from langchain_google_vertexai import ChatVertexAI, VertexAIEmbeddings -import vertexai + +from app.patterns.custom_rag_qa.templates import query_rewrite_template, rag_template +from app.patterns.custom_rag_qa.vector_store import get_vector_store +from app.utils.output_types import OnChatModelStreamEvent, OnToolEndEvent, custom_chain # Configuration EMBEDDING_MODEL = "text-embedding-004" diff --git a/gemini/sample-apps/conversational-genai-app-template/app/utils/output_types.py b/gemini/sample-apps/conversational-genai-app-template/app/utils/output_types.py index 1d3bf6066a7..0f3a7209845 100644 --- a/gemini/sample-apps/conversational-genai-app-template/app/utils/output_types.py +++ b/gemini/sample-apps/conversational-genai-app-template/app/utils/output_types.py @@ -12,10 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import uuid from functools import wraps from types import GeneratorType from typing import Any, AsyncGenerator, Callable, Dict, List, Literal, Union -import uuid from langchain_core.documents import Document from langchain_core.messages import AIMessage, AIMessageChunk diff --git a/gemini/sample-apps/conversational-genai-app-template/streamlit/streamlit_app.py b/gemini/sample-apps/conversational-genai-app-template/streamlit/streamlit_app.py index 12947fac963..cfca88427e5 100644 --- a/gemini/sample-apps/conversational-genai-app-template/streamlit/streamlit_app.py +++ b/gemini/sample-apps/conversational-genai-app-template/streamlit/streamlit_app.py @@ -12,13 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from functools import partial import json import uuid +from functools import partial from langchain_core.messages import HumanMessage from side_bar import SideBar -import streamlit as st from streamlit_feedback import streamlit_feedback from style.app_markdown import markdown_str from utils.local_chat_history import LocalChatMessageHistory @@ -26,6 +25,8 @@ from utils.multimodal_utils import format_content, get_parts_from_files from utils.stream_handler import Client, StreamHandler, get_chain_response +import streamlit as st + USER = "my_user" EMPTY_CHAT_NAME = "Empty chat" diff --git a/gemini/sample-apps/conversational-genai-app-template/streamlit/utils/local_chat_history.py b/gemini/sample-apps/conversational-genai-app-template/streamlit/utils/local_chat_history.py index ebbe0110ed7..538e22cd2f9 100644 --- a/gemini/sample-apps/conversational-genai-app-template/streamlit/utils/local_chat_history.py +++ b/gemini/sample-apps/conversational-genai-app-template/streamlit/utils/local_chat_history.py @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -from datetime import datetime import os +from datetime import datetime +import yaml from langchain_core.chat_history import BaseChatMessageHistory from langchain_core.messages import HumanMessage from utils.title_summary import chain_title -import yaml class LocalChatMessageHistory(BaseChatMessageHistory): diff --git a/gemini/sample-apps/conversational-genai-app-template/streamlit/utils/stream_handler.py b/gemini/sample-apps/conversational-genai-app-template/streamlit/utils/stream_handler.py index bfe0e07c12d..40afe33201b 100644 --- a/gemini/sample-apps/conversational-genai-app-template/streamlit/utils/stream_handler.py +++ b/gemini/sample-apps/conversational-genai-app-template/streamlit/utils/stream_handler.py @@ -17,11 +17,12 @@ from urllib.parse import urljoin import google.auth -from google.auth.exceptions import DefaultCredentialsError import google.auth.transport.requests import google.oauth2.id_token -from langchain_core.messages import AIMessage import requests +from google.auth.exceptions import DefaultCredentialsError +from langchain_core.messages import AIMessage + import streamlit as st diff --git a/gemini/sample-apps/conversational-genai-app-template/tests/integration/patterns/test_langgraph_dummy_agent.py b/gemini/sample-apps/conversational-genai-app-template/tests/integration/patterns/test_langgraph_dummy_agent.py index be6db4f555d..01706f9d9cb 100644 --- a/gemini/sample-apps/conversational-genai-app-template/tests/integration/patterns/test_langgraph_dummy_agent.py +++ b/gemini/sample-apps/conversational-genai-app-template/tests/integration/patterns/test_langgraph_dummy_agent.py @@ -14,9 +14,10 @@ import logging -from app.patterns.langgraph_dummy_agent.chain import chain -from langchain_core.messages import AIMessageChunk import pytest +from langchain_core.messages import AIMessageChunk + +from app.patterns.langgraph_dummy_agent.chain import chain CHAIN_NAME = "LangGraph agent" diff --git a/gemini/sample-apps/conversational-genai-app-template/tests/integration/patterns/test_rag_qa.py b/gemini/sample-apps/conversational-genai-app-template/tests/integration/patterns/test_rag_qa.py index 36ace08010b..81e9b1ddf3c 100644 --- a/gemini/sample-apps/conversational-genai-app-template/tests/integration/patterns/test_rag_qa.py +++ b/gemini/sample-apps/conversational-genai-app-template/tests/integration/patterns/test_rag_qa.py @@ -14,9 +14,10 @@ import logging -from app.patterns.custom_rag_qa.chain import chain -from langchain_core.messages import AIMessageChunk import pytest +from langchain_core.messages import AIMessageChunk + +from app.patterns.custom_rag_qa.chain import chain CHAIN_NAME = "Rag QA" diff --git a/gemini/sample-apps/conversational-genai-app-template/tests/integration/test_chain.py b/gemini/sample-apps/conversational-genai-app-template/tests/integration/test_chain.py index 73c27f93105..04797c42927 100644 --- a/gemini/sample-apps/conversational-genai-app-template/tests/integration/test_chain.py +++ b/gemini/sample-apps/conversational-genai-app-template/tests/integration/test_chain.py @@ -14,9 +14,10 @@ import logging -from app.chain import chain -from langchain_core.messages import AIMessageChunk import pytest +from langchain_core.messages import AIMessageChunk + +from app.chain import chain CHAIN_NAME = "Default" diff --git a/gemini/sample-apps/conversational-genai-app-template/tests/integration/test_server_e2e.py b/gemini/sample-apps/conversational-genai-app-template/tests/integration/test_server_e2e.py index 1c76307086f..e3dda0cc468 100644 --- a/gemini/sample-apps/conversational-genai-app-template/tests/integration/test_server_e2e.py +++ b/gemini/sample-apps/conversational-genai-app-template/tests/integration/test_server_e2e.py @@ -18,8 +18,8 @@ import sys import threading import time -from typing import Any, Iterator import uuid +from typing import Any, Iterator import pytest import requests diff --git a/gemini/sample-apps/conversational-genai-app-template/tests/unit/test_server.py b/gemini/sample-apps/conversational-genai-app-template/tests/unit/test_server.py index 51565628faf..b65e73a0c89 100644 --- a/gemini/sample-apps/conversational-genai-app-template/tests/unit/test_server.py +++ b/gemini/sample-apps/conversational-genai-app-template/tests/unit/test_server.py @@ -17,12 +17,13 @@ from typing import Any from unittest.mock import patch -from app.server import app -from app.utils.input_types import InputChat +import pytest from fastapi.testclient import TestClient from httpx import AsyncClient from langchain_core.messages import HumanMessage -import pytest + +from app.server import app +from app.utils.input_types import InputChat # Set up logging logging.basicConfig(level=logging.INFO) diff --git a/gemini/sample-apps/conversational-genai-app-template/tests/unit/test_utils/test_tracing_exporter.py b/gemini/sample-apps/conversational-genai-app-template/tests/unit/test_utils/test_tracing_exporter.py index e584ee0b704..f3110f74ad4 100644 --- a/gemini/sample-apps/conversational-genai-app-template/tests/unit/test_utils/test_tracing_exporter.py +++ b/gemini/sample-apps/conversational-genai-app-template/tests/unit/test_utils/test_tracing_exporter.py @@ -14,11 +14,12 @@ from unittest.mock import Mock, patch -from app.utils.tracing import CloudTraceLoggingSpanExporter +import pytest from google.cloud import logging as gcp_logging from google.cloud import storage from opentelemetry.sdk.trace import ReadableSpan -import pytest + +from app.utils.tracing import CloudTraceLoggingSpanExporter @pytest.fixture