Skip to content

Commit

Permalink
Merge branch 'main' into fix-pg-textgen-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jjmaturino authored Dec 26, 2024
2 parents 6b79f0a + 8d6b4b0 commit eb7aaef
Show file tree
Hide file tree
Showing 97 changed files with 3,030 additions and 3,296 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/docker/compose/dataprep-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ services:
build:
dockerfile: comps/dataprep/elasticsearch/langchain/Dockerfile
image: ${REGISTRY:-opea}/dataprep-elasticsearch:${TAG:-latest}
dataprep-opensearch:
build:
dockerfile: comps/dataprep/opensearch/langchain/Dockerfile
image: ${REGISTRY:-opea}/dataprep-opensearch:${TAG:-latest}
8 changes: 4 additions & 4 deletions .github/workflows/docker/compose/retrievers-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ services:
build:
dockerfile: comps/retrievers/vdms/langchain/Dockerfile
image: ${REGISTRY:-opea}/retriever-vdms:${TAG:-latest}
retriever-multimodal-redis:
build:
dockerfile: comps/retrievers/multimodal/redis/langchain/Dockerfile
image: ${REGISTRY:-opea}/retriever-multimodal-redis:${TAG:-latest}
retriever-pgvector:
build:
dockerfile: comps/retrievers/pgvector/langchain/Dockerfile
Expand Down Expand Up @@ -51,3 +47,7 @@ services:
build:
dockerfile: comps/retrievers/elasticsearch/langchain/Dockerfile
image: ${REGISTRY:-opea}/retriever-elasticsearch:${TAG:-latest}
retriever-opensearch:
build:
dockerfile: comps/retrievers/opensearch/langchain/Dockerfile
image: ${REGISTRY:-opea}/retriever-opensearch:${TAG:-latest}
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,6 @@ class ExampleService:
self.megaservice.flow_to(embedding, llm)
```

## Gateway

The `Gateway` serves as the interface for users to access the `Megaservice`, providing customized access based on user requirements. It acts as the entry point for incoming requests, routing them to the appropriate `Microservices` within the `Megaservice` architecture.

`Gateways` support API definition, API versioning, rate limiting, and request transformation, allowing for fine-grained control over how users interact with the underlying `Microservices`. By abstracting the complexity of the underlying infrastructure, `Gateways` provide a seamless and user-friendly experience for interacting with the `Megaservice`.

For example, the `Gateway` for `ChatQnA` can be built like this:

```python
from comps import ChatQnAGateway

self.gateway = ChatQnAGateway(megaservice=self.megaservice, host="0.0.0.0", port=self.port)
```

## Contributing to OPEA

Welcome to the OPEA open-source community! We are thrilled to have you here and excited about the potential contributions you can bring to the OPEA platform. Whether you are fixing bugs, adding new GenAI components, improving documentation, or sharing your unique use cases, your contributions are invaluable.
Expand Down
18 changes: 1 addition & 17 deletions comps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
PIIResponseDoc,
Audio2text,
DocSumDoc,
DocSumLLMParams,
)

# Constants
Expand All @@ -47,23 +48,6 @@
from comps.cores.mega.orchestrator import ServiceOrchestrator
from comps.cores.mega.orchestrator_with_yaml import ServiceOrchestratorWithYaml
from comps.cores.mega.micro_service import MicroService, register_microservice, opea_microservices
from comps.cores.mega.gateway import (
Gateway,
ChatQnAGateway,
CodeGenGateway,
CodeTransGateway,
DocSumGateway,
TranslationGateway,
SearchQnAGateway,
AudioQnAGateway,
RetrievalToolGateway,
FaqGenGateway,
VideoQnAGateway,
VisualQnAGateway,
MultimodalQnAGateway,
GraphragGateway,
AvatarChatbotGateway,
)

# Telemetry
from comps.cores.telemetry.opea_telemetry import opea_telemetry
Expand Down
59 changes: 26 additions & 33 deletions comps/agent/langchain/README.md

Large diffs are not rendered by default.

46 changes: 0 additions & 46 deletions comps/agent/langchain/log

This file was deleted.

8 changes: 4 additions & 4 deletions comps/agent/langchain/src/strategy/sqlagent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The agent node takes user question, hints (optional) and history (when available

### Database schema:

We use langchain's [SQLDatabase](https://python.langchain.com/api_reference/community/utilities/langchain_community.utilities.sql_database.SQLDatabase.html#langchain_community.utilities.sql_database.SQLDatabase) API to get table names and schemas from the SQL database. User just need to specify `db_path` and `db_name`. The table schemas are incorporated into the prompts for the agent.
We use langchain's [SQLDatabase](https://python.langchain.com/docs/integrations/tools/sql_database/) API to get table names and schemas from the SQL database. User just need to specify `db_path` and `db_name`. The table schemas are incorporated into the prompts for the agent.

### Hints module:

Expand All @@ -37,8 +37,8 @@ The agent node takes user question, hints (optional) and history (when available

## Limitations

1. Agent connects to local SQLite databases with uri.
2. Agent is only allowed to issue "SELECT" commands to databases, i.e., agent can only query databases but cannot update databases.
3. We currently does not support "streaming" agent outputs on the fly for `sql_agent_llama`.
1. Agent is only allowed to issue "SELECT" commands to databases, i.e., agent can only query databases but cannot update databases.
2. We currently does not support "streaming" agent outputs on the fly for `sql_agent_llama`.
3. Users need to pass the SQL database URI to the agent with the `db_path` environment variable. We have only validated SQLite database connected in such way.

Please submit issues if you want new features to be added. We also welcome community contributions!
12 changes: 7 additions & 5 deletions comps/agent/langchain/src/strategy/sqlagent/hint.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ def get_topk_cols(topk, cols_descriptions, similarities):


def pick_hints(query, model, column_embeddings, complete_descriptions, topk=5):
# use similarity to get the topk columns
query_embedding = model.encode(query, convert_to_tensor=True)
similarities = model.similarity(query_embedding, column_embeddings).flatten()

topk_cols_descriptions = get_topk_cols(topk, complete_descriptions, similarities)
if len(complete_descriptions) < topk:
topk_cols_descriptions = complete_descriptions
else:
# use similarity to get the topk columns
query_embedding = model.encode(query, convert_to_tensor=True)
similarities = model.similarity(query_embedding, column_embeddings).flatten()
topk_cols_descriptions = get_topk_cols(topk, complete_descriptions, similarities)

hint = ""
for col in topk_cols_descriptions:
Expand Down
2 changes: 2 additions & 0 deletions comps/agent/langchain/src/strategy/sqlagent/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ def __init__(self, args, tools):
self.cols_descriptions, self.values_descriptions = read_hints(args.hints_file)
self.embed_model = SentenceTransformer("BAAI/bge-large-en-v1.5")
self.column_embeddings = self.embed_model.encode(self.values_descriptions)
print("Done embedding column descriptions")

def __call__(self, state):
print("----------Call Agent Node----------")
question = state["messages"][0].content
table_schema, num_tables = get_table_schema(self.args.db_path)
print("@@@@ Table Schema: ", table_schema)
if self.args.use_hints:
if not state["hint"]:
hints = pick_hints(question, self.embed_model, self.column_embeddings, self.cols_descriptions)
Expand Down
3 changes: 1 addition & 2 deletions comps/agent/langchain/src/strategy/sqlagent/sql_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@


def connect_to_db(db_path):
uri = "sqlite:///{path}".format(path=db_path)
db = SQLDatabase.from_uri(uri)
db = SQLDatabase.from_uri(db_path)
return db


Expand Down
27 changes: 14 additions & 13 deletions comps/agent/langchain/src/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,19 @@ def load_python_tools(file_dir_path: str):

def get_tools_descriptions(file_dir_path: str):
tools = []
file_path_list = []
if os.path.isdir(file_dir_path):
file_path_list += glob.glob(file_dir_path + "/*")
else:
file_path_list.append(file_dir_path)
for file in file_path_list:
if os.path.basename(file).endswith(".yaml"):
tools += load_yaml_tools(file)
elif os.path.basename(file).endswith(".yml"):
tools += load_yaml_tools(file)
elif os.path.basename(file).endswith(".py"):
tools += load_python_tools(file)
if file_dir_path:
file_path_list = []
if os.path.isdir(file_dir_path):
file_path_list += glob.glob(file_dir_path + "/*")
else:
pass
file_path_list.append(file_dir_path)
for file in file_path_list:
if os.path.basename(file).endswith(".yaml"):
tools += load_yaml_tools(file)
elif os.path.basename(file).endswith(".yml"):
tools += load_yaml_tools(file)
elif os.path.basename(file).endswith(".py"):
tools += load_python_tools(file)
else:
pass
return tools
2 changes: 1 addition & 1 deletion comps/agent/langchain/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def get_args():
parser.add_argument("--agent_name", type=str, default="OPEA_Default_Agent")
parser.add_argument("--strategy", type=str, default="react_langchain")
parser.add_argument("--role_description", type=str, default="LLM enhanced agent")
parser.add_argument("--tools", type=str, default="tools/custom_tools.yaml")
parser.add_argument("--tools", type=str, default=None, help="path to the tools file")
parser.add_argument("--recursion_limit", type=int, default=5)
parser.add_argument("--require_human_feedback", action="store_true", help="If this agent requires human feedback")
parser.add_argument("--debug", action="store_true", help="Test with endpoint mode")
Expand Down
Loading

0 comments on commit eb7aaef

Please sign in to comment.