Skip to content

Commit

Permalink
Merge pull request #20 from RSS3-Network/feat/deploy-enhance
Browse files Browse the repository at this point in the history
feat: deployment enhancement
  • Loading branch information
naaive authored Jul 15, 2024
2 parents 549924e + 7d623d3 commit 9080aef
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 66 deletions.
4 changes: 2 additions & 2 deletions src/.chainlit/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ auto_tag_thread = true

[UI]
# Name of the assistant.
name = "Assistant"
name = "OpenAgent"

# Description of the assistant. This is used for HTML tags.
# description = ""
description = "OpenAgent is a conversational AI assistant that can help you with your web3 queries."

# Large size content are by default collapsed for a cleaner ui
default_collapse_content = true
Expand Down
3 changes: 0 additions & 3 deletions src/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,3 @@ OAUTH_AUTH0_CLIENT_SECRET=...
OAUTH_AUTH0_DOMAIN=...
# Chainlit configuration
CHAINLIT_AUTH_SECRET=...

# Widet url, like swap widget
WIDGET_URL=http://localhost:8001
1 change: 0 additions & 1 deletion src/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ services:
dockerfile: Dockerfile
ports:
- "8000:8000"
- "8001:8001"
depends_on:
- vec_db
vec_db:
Expand Down
21 changes: 2 additions & 19 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
import multiprocessing
import os

import uvicorn
from dotenv import load_dotenv
from loguru import logger

if __name__ == "__main__":
load_dotenv()
env = os.getenv("ENV", "dev")

if env == "prod":
logger.info("Starting UI")
from openagent.ui.app import start_ui

ui_process = multiprocessing.Process(target=start_ui)
ui_process.start()
else:
ui_process = None

logger.info("Starting API")
uvicorn.run("openagent.app:app", host="0.0.0.0", reload=False, port=8001)

if ui_process:
ui_process.join()
logger.info("Starting OpenAgent")
uvicorn.run("openagent.app:app", host="0.0.0.0", reload=False, port=8000)
21 changes: 6 additions & 15 deletions src/openagent/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os

from chainlit.utils import mount_chainlit
from dotenv import load_dotenv
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
Expand Down Expand Up @@ -27,27 +28,17 @@
app.include_router(session_router)


@app.get("/swap")
async def swap():
@app.get("/widget/swap")
async def swap_root():
print("swap_root")
return FileResponse(os.path.join("dist", "index.html"))


@app.get("/swap/select-wallet")
async def swap_select_wallet():
print("swap_select_wallet")
return FileResponse(os.path.join("dist", "index.html"))


@app.get("/swap/settings")
async def swap_setting():
print("swap_setting")
app.mount("/assets", StaticFiles(directory="dist/assets"), name="widget")

return FileResponse(os.path.join("dist", "index.html"))
mount_chainlit(app=app, target="openagent/ui/app.py", path="/ui")


@app.get("/health", status_code=status.HTTP_200_OK)
async def health_check():
return JSONResponse(content={"status": "ok"})


app.mount("/", StaticFiles(directory="dist", html=True), name="static")
1 change: 0 additions & 1 deletion src/openagent/conf/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class Settings(BaseSettings):
DB_CONNECTION: str = Field(..., env="DB_CONNECTION")
RSS3_DATA_API: str = Field(default="https://testnet.rss3.io/data", env="RSS3_DATA_API")
RSS3_SEARCH_API: str = Field(default="https://devnet.rss3.io/search", env="RSS3_SEARCH_API")
WIDGET_URL: str = Field(default="http://localhost:8001", env="WIDGET_URL")


settings = Settings()
2 changes: 1 addition & 1 deletion src/openagent/ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def handle_function_message(message: FunctionMessage, msg: cl.Message):
from_amount = swap_dict["amount"]

widget = (
f"""<iframe src="{settings.WIDGET_URL}/swap?fromAmount={from_amount}&"""
f"""<iframe src="/widget/swap?fromAmount={from_amount}&"""
f"""fromChain={from_chain}&fromToken={from_token_}&toChain={to_chain}&"""
f"""toToken={to_token}" width="400" height="700"></iframe>"""
)
Expand Down
2 changes: 1 addition & 1 deletion src/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed src/public/logo_light.png
Binary file not shown.
1 change: 1 addition & 0 deletions src/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ langchain-google-vertexai = "^1.0.6"
langchain-community = "^0.2.6"
langchain-openai = "^0.1.13"
chainlit = "^1.1.305"
greenlet = "^3.0.3"

[tool.poetry.group.dev.dependencies]
ruff = "^0.4.1"
Expand Down
46 changes: 23 additions & 23 deletions src/widget/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
import React from 'react';
import ReactDOM from 'react-dom/client';
import { WagmiProvider, createConfig, http } from 'wagmi';
import { base, mainnet } from 'wagmi/chains';
import { injected, safe, walletConnect } from 'wagmi/connectors';
import { App } from './App';
import {WagmiProvider, createConfig, http} from 'wagmi';
import {base, mainnet} from 'wagmi/chains';
import {injected, safe, walletConnect} from 'wagmi/connectors';
import {App} from './App';
import {Route, BrowserRouter as Router, Routes} from "react-router-dom";
import {Swap} from "./components/Swap";

Expand All @@ -13,28 +13,28 @@ const queryClient = new QueryClient();
const projectId = import.meta.env.VITE_WALLET_CONNECT_PROJECT_ID;
console.log(projectId)
const config = createConfig({
chains: [mainnet],
connectors: [injected(), walletConnect({ projectId }), safe()],
transports: {
[mainnet.id]: http(),
[base.id]: http(),
},
chains: [mainnet],
connectors: [injected(), walletConnect({projectId}), safe()],
transports: {
[mainnet.id]: http(),
[base.id]: http(),
},
});

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<WagmiProvider config={config}>
<Router>
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<WagmiProvider config={config}>
<Router basename={"/widget"}>

<Routes>
<Route path="/" element={<App />} />
<Route path="/swap/*" element={<Swap />} />
</Routes>
</Router>
<Routes>
<Route path="/" element={<App/>}/>
<Route path="/swap/*" element={<Swap/>}/>
</Routes>
</Router>


</WagmiProvider>
</QueryClientProvider>
</React.StrictMode>,
</WagmiProvider>
</QueryClientProvider>
</React.StrictMode>,
);

0 comments on commit 9080aef

Please sign in to comment.