Skip to content

Commit

Permalink
Merge pull request #27 from RSS3-Network/feat/refactor
Browse files Browse the repository at this point in the history
Refactor configuration file
  • Loading branch information
birdringxD authored Jul 29, 2024
2 parents 9e2aa46 + a24c4e5 commit 6a64508
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ LLM_API_BASE=http://ollama:11434

## A database is required for vector and user management.
## Database connection string
DB_CONNECTION=postgresql+psycopg://postgres:password@vector_db:5434/vec
DB_CONNECTION=postgresql+psycopg://postgres:password@vector_db:5432/openagent

# End of basic configuration
############################
Expand Down
2 changes: 1 addition & 1 deletion src/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: vec
POSTGRES_DB: openagent
ports:
- "15432:5432"
volumes:
Expand Down
2 changes: 1 addition & 1 deletion src/openagent/agent/function_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def create_tool_call_agent(session_id: str):
async def main():
# Create a tool call agent and use it to handle some inputs
agent = get_agent("123")
await agent.ainvoke({"input": "Swap 1 eth to usdt, from ethereumn to arb"})
await agent.ainvoke({"input": "Swap 1 eth to usdt, from ethereum to arb"})
await agent.ainvoke({"input": "What is the price of ETH?"})
await agent.ainvoke({"input": "What did vitalik.eth do recently?"})

Expand Down
3 changes: 2 additions & 1 deletion src/openagent/experts/article_expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from langchain.tools import BaseTool
from pydantic import BaseModel, Field

from openagent.index.pgvector_store import store
from openagent.index.pgvector_store import build_vector_store


class ARGS(BaseModel):
Expand Down Expand Up @@ -45,6 +45,7 @@ async def _arun(

@staticmethod
def search_articles(keyword: str) -> str:
store = build_vector_store()
retriever = store.as_retriever(
search_type="similarity_score_threshold",
search_kwargs={"score_threshold": 0.8, "k": 3},
Expand Down
9 changes: 7 additions & 2 deletions src/openagent/experts/swap_expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ class ParamSchema(BaseModel):

from_token: str = Field(description="Symbol of the token to swap from, e.g., 'BTC', 'ETH', 'RSS3', 'USDT', 'USDC'. Default: 'ETH'.")
to_token: str = Field(description="Symbol of the token to swap to, e.g., 'BTC', 'ETH', 'RSS3', 'USDT', 'USDC'. Default: 'ETH'.")
from_chain: ChainLiteral = Field(default="ETH", description="Blockchain network to swap from. Default: 'ETH'.")
to_chain: ChainLiteral = Field(default="ETH", description="Blockchain network to swap to. Default: 'ETH'.")
from_chain: ChainLiteral = Field(
default="ETH",
description="Blockchain network to swap from, support networks: 'ETH', 'BSC', 'ARBITRUM', 'OPTIMISM', 'POLYGON'. Default: 'ETH'.",
)
to_chain: ChainLiteral = Field(
default="ETH", description="Blockchain network to swap to, support networks: 'ETH', 'BSC', 'ARBITRUM', 'OPTIMISM', 'POLYGON'. Default: 'ETH'."
)
amount: str = Field(description="Amount of the from-side token to swap, e.g., '0.1', '1', '10'. Default: '1'.")


Expand Down
6 changes: 3 additions & 3 deletions src/openagent/index/feed_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from openagent.conf.env import settings
from openagent.index.feed_scrape import fetch_iqwiki_feeds, fetch_mirror_feeds
from openagent.index.pgvector_store import store
from openagent.index.pgvector_store import build_vector_store

load_dotenv()

Expand All @@ -18,7 +18,7 @@


def _clear():
index([], record_manager, store, cleanup="incremental", source_id_key="id")
index([], record_manager, build_vector_store(), cleanup="incremental", source_id_key="id")


def build_index():
Expand Down Expand Up @@ -66,7 +66,7 @@ def save_records(records):
indexing_result = index(
final_docs,
record_manager,
store,
build_vector_store(),
cleanup="incremental",
source_id_key="id",
)
Expand Down
5 changes: 2 additions & 3 deletions src/openagent/index/pgvector_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
from langchain_google_vertexai import VertexAIEmbeddings
from langchain_openai import OpenAIEmbeddings
from langchain_postgres.vectorstores import PGVector
from toolz import memoize

from openagent.conf.env import settings

load_dotenv()


@memoize
def build_vector_store() -> PGVector:
collection_name = "backend"
if settings.MODEL_NAME.startswith("gemini"):
Expand All @@ -24,6 +26,3 @@ def build_vector_store() -> PGVector:
connection=settings.DB_CONNECTION,
use_jsonb=True,
)


store = build_vector_store()

0 comments on commit 6a64508

Please sign in to comment.