fixed merge conflicts for swap
Browse files- chatxbt-assistant.py +64 -48
- requirements.txt +21 -3
- src/config/portkey_config.py +108 -0
chatxbt-assistant.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
-
import os
|
| 2 |
from typing import Optional, Dict
|
| 3 |
from dotenv import load_dotenv
|
|
|
|
| 4 |
load_dotenv()
|
| 5 |
|
| 6 |
import chainlit as cl
|
|
@@ -9,13 +10,16 @@ from phi.llm.openai import OpenAIChat
|
|
| 9 |
from phi.tools.duckduckgo import DuckDuckGo
|
| 10 |
from phi.tools.yfinance import YFinanceTools
|
| 11 |
from src.databases.postgres import sqlalchemy_engine
|
|
|
|
| 12 |
from src.tools.crypto_swap_toolkit import CryptoSwapTools
|
| 13 |
from src.tools.crypto_data_toolkit import CryptoDataTools
|
| 14 |
-
from
|
| 15 |
-
from src.
|
| 16 |
from src.tools.user_profile_toolkit import UserProfileToolkit
|
| 17 |
from phi.storage.assistant.postgres import PgAssistantStorage
|
| 18 |
-
from src.
|
|
|
|
|
|
|
| 19 |
|
| 20 |
storage = PgAssistantStorage(
|
| 21 |
# stores runs in the ai.assistant_runs table
|
|
@@ -23,50 +27,6 @@ storage = PgAssistantStorage(
|
|
| 23 |
db_engine=sqlalchemy_engine
|
| 24 |
)
|
| 25 |
|
| 26 |
-
@cl.on_chat_start
|
| 27 |
-
async def start():
|
| 28 |
-
is_dev_mode = True if os.getenv("DEV_MODE") else False
|
| 29 |
-
|
| 30 |
-
# Initialize the assistant
|
| 31 |
-
cxbt_assistant = Assistant(
|
| 32 |
-
llm=OpenAIChat(model="gpt-4o"),
|
| 33 |
-
tools=[
|
| 34 |
-
UserProfileToolkit(),
|
| 35 |
-
DuckDuckGo(),
|
| 36 |
-
CryptoDataTools(),
|
| 37 |
-
CryptoSwapTools(),
|
| 38 |
-
CryptoEVMWalletTools(),
|
| 39 |
-
UserConfirmationPinToolkit(),
|
| 40 |
-
YFinanceTools(stock_price=True)
|
| 41 |
-
],
|
| 42 |
-
show_tool_calls=is_dev_mode,
|
| 43 |
-
markdown=True,
|
| 44 |
-
knowledge_base=knowledge_base,
|
| 45 |
-
storage=storage,
|
| 46 |
-
search_knowledge=True,
|
| 47 |
-
read_chat_history=True,
|
| 48 |
-
add_references_to_prompt=True,
|
| 49 |
-
add_chat_history_to_prompt=True
|
| 50 |
-
)
|
| 51 |
-
cxbt_assistant.knowledge_base.load(recreate=False)
|
| 52 |
-
|
| 53 |
-
# Set the assistant in the user session
|
| 54 |
-
cl.user_session.set("agent", cxbt_assistant)
|
| 55 |
-
|
| 56 |
-
@cl.on_message
|
| 57 |
-
async def main(message: cl.Message):
|
| 58 |
-
|
| 59 |
-
# Retrieve the assistant from the user session
|
| 60 |
-
agent = cl.user_session.get("agent")
|
| 61 |
-
|
| 62 |
-
# Process the user message using the assistant
|
| 63 |
-
response = ""
|
| 64 |
-
for delta in agent.run(message.content, stream=True):
|
| 65 |
-
response += delta
|
| 66 |
-
|
| 67 |
-
# Send the response back to the user
|
| 68 |
-
await cl.Message(content=response).send()
|
| 69 |
-
|
| 70 |
@cl.oauth_callback
|
| 71 |
def oauth_callback(
|
| 72 |
provider_id: str,
|
|
@@ -125,6 +85,62 @@ async def set_starters():
|
|
| 125 |
)
|
| 126 |
]
|
| 127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
# Run the Chainlit application
|
| 129 |
if __name__ == "__main__":
|
| 130 |
cl.run()
|
|
|
|
| 1 |
+
import os, json
|
| 2 |
from typing import Optional, Dict
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
+
|
| 5 |
load_dotenv()
|
| 6 |
|
| 7 |
import chainlit as cl
|
|
|
|
| 10 |
from phi.tools.duckduckgo import DuckDuckGo
|
| 11 |
from phi.tools.yfinance import YFinanceTools
|
| 12 |
from src.databases.postgres import sqlalchemy_engine
|
| 13 |
+
from src.knowledge_bases.combined import knowledge_base
|
| 14 |
from src.tools.crypto_swap_toolkit import CryptoSwapTools
|
| 15 |
from src.tools.crypto_data_toolkit import CryptoDataTools
|
| 16 |
+
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders
|
| 17 |
+
from src.config.portkey_config import generate_portkey_config
|
| 18 |
from src.tools.user_profile_toolkit import UserProfileToolkit
|
| 19 |
from phi.storage.assistant.postgres import PgAssistantStorage
|
| 20 |
+
from src.tools.crypto_evm_wallet_toolkit import CryptoEVMWalletTools
|
| 21 |
+
from src.tools.user_confirmation_pin_toolkit import UserConfirmationPinToolkit
|
| 22 |
+
|
| 23 |
|
| 24 |
storage = PgAssistantStorage(
|
| 25 |
# stores runs in the ai.assistant_runs table
|
|
|
|
| 27 |
db_engine=sqlalchemy_engine
|
| 28 |
)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
@cl.oauth_callback
|
| 31 |
def oauth_callback(
|
| 32 |
provider_id: str,
|
|
|
|
| 85 |
)
|
| 86 |
]
|
| 87 |
|
| 88 |
+
@cl.on_chat_start
|
| 89 |
+
async def start():
|
| 90 |
+
is_dev_mode = True if os.getenv("DEV_MODE") else False
|
| 91 |
+
|
| 92 |
+
portkey_local_gateway = True if os.getenv("PORTKEY_LOCAL_GATEWAY_URL") else False
|
| 93 |
+
portkey_config = generate_portkey_config(local=portkey_local_gateway)
|
| 94 |
+
|
| 95 |
+
# Initialize the assistant
|
| 96 |
+
cxbt_assistant = Assistant(
|
| 97 |
+
llm=OpenAIChat(
|
| 98 |
+
api_key=os.getenv("PORTKEY_API_KEY"),
|
| 99 |
+
base_url=os.getenv("PORTKEY_LOCAL_GATEWAY_URL") or PORTKEY_GATEWAY_URL,
|
| 100 |
+
default_headers=createHeaders(
|
| 101 |
+
api_key=os.getenv("PORTKEY_API_KEY") or None,
|
| 102 |
+
config=portkey_config
|
| 103 |
+
),
|
| 104 |
+
),
|
| 105 |
+
tools=[
|
| 106 |
+
DuckDuckGo(),
|
| 107 |
+
CryptoDataTools(),
|
| 108 |
+
CryptoSwapTools(),
|
| 109 |
+
UserProfileToolkit(),
|
| 110 |
+
CryptoEVMWalletTools(),
|
| 111 |
+
UserConfirmationPinToolkit(),
|
| 112 |
+
YFinanceTools(stock_price=True)
|
| 113 |
+
],
|
| 114 |
+
show_tool_calls=is_dev_mode,
|
| 115 |
+
markdown=True,
|
| 116 |
+
knowledge_base=knowledge_base,
|
| 117 |
+
storage=storage,
|
| 118 |
+
search_knowledge=True,
|
| 119 |
+
read_chat_history=True,
|
| 120 |
+
add_references_to_prompt=True,
|
| 121 |
+
add_chat_history_to_prompt=True,
|
| 122 |
+
prevent_hallucinations=True,
|
| 123 |
+
prevent_prompt_injection=True
|
| 124 |
+
)
|
| 125 |
+
cxbt_assistant.knowledge_base.load(recreate=False)
|
| 126 |
+
|
| 127 |
+
# Set the assistant in the user session
|
| 128 |
+
cl.user_session.set("agent", cxbt_assistant)
|
| 129 |
+
|
| 130 |
+
@cl.on_message
|
| 131 |
+
async def main(message: cl.Message):
|
| 132 |
+
|
| 133 |
+
# Retrieve the assistant from the user session
|
| 134 |
+
agent = cl.user_session.get("agent")
|
| 135 |
+
|
| 136 |
+
# Process the user message using the assistant
|
| 137 |
+
response = ""
|
| 138 |
+
for delta in agent.run(message.content, stream=True):
|
| 139 |
+
response += delta
|
| 140 |
+
|
| 141 |
+
# Send the response back to the user
|
| 142 |
+
await cl.Message(content=response).send()
|
| 143 |
+
|
| 144 |
# Run the Chainlit application
|
| 145 |
if __name__ == "__main__":
|
| 146 |
cl.run()
|
requirements.txt
CHANGED
|
@@ -8,12 +8,14 @@ anthropic==0.28.0
|
|
| 8 |
anyio==3.7.1
|
| 9 |
appdirs==1.4.4
|
| 10 |
appnope==0.1.4
|
|
|
|
| 11 |
asgiref==3.8.1
|
| 12 |
asttokens==2.4.1
|
| 13 |
async-timeout==4.0.3
|
| 14 |
asyncer==0.0.2
|
| 15 |
attrs==23.2.0
|
| 16 |
backcall==0.2.0
|
|
|
|
| 17 |
baize==0.20.8
|
| 18 |
beautifulsoup4==4.12.3
|
| 19 |
bidict==0.23.1
|
|
@@ -21,22 +23,26 @@ bitarray==2.9.2
|
|
| 21 |
bleach==6.1.0
|
| 22 |
boto3==1.34.106
|
| 23 |
botocore==1.34.106
|
|
|
|
| 24 |
certifi==2024.6.2
|
|
|
|
| 25 |
chainlit==1.1.300
|
| 26 |
charset-normalizer==3.3.2
|
| 27 |
-
psycopg2-binary==2.9.9
|
| 28 |
chevron==0.14.0
|
| 29 |
ckzg==1.0.2
|
| 30 |
click==8.1.7
|
| 31 |
coingecko==0.13
|
|
|
|
| 32 |
cytoolz==0.12.3
|
| 33 |
dataclasses-json==0.5.14
|
| 34 |
decorator==5.1.1
|
| 35 |
defusedxml==0.7.1
|
| 36 |
Deprecated==1.2.14
|
| 37 |
distro==1.9.0
|
|
|
|
| 38 |
docopt==0.6.2
|
| 39 |
duckduckgo_search==6.1.6
|
|
|
|
| 40 |
eth-account==0.11.2
|
| 41 |
eth-hash==0.7.0
|
| 42 |
eth-keyfile==0.8.1
|
|
@@ -47,7 +53,9 @@ eth-utils==4.1.1
|
|
| 47 |
eth_abi==5.1.0
|
| 48 |
exceptiongroup==1.2.1
|
| 49 |
executing==2.0.1
|
| 50 |
-
fastapi==0.
|
|
|
|
|
|
|
| 51 |
fastjsonschema==2.19.1
|
| 52 |
filelock==3.15.1
|
| 53 |
filetype==1.2.0
|
|
@@ -62,10 +70,12 @@ google_search_results==2.4.2
|
|
| 62 |
googleapis-common-protos==1.63.1
|
| 63 |
greenlet==3.0.3
|
| 64 |
grpcio==1.64.1
|
|
|
|
| 65 |
h11==0.14.0
|
| 66 |
hexbytes==0.3.1
|
| 67 |
html5lib==1.1
|
| 68 |
httpcore==1.0.5
|
|
|
|
| 69 |
httpx==0.27.0
|
| 70 |
huggingface-hub==0.23.3
|
| 71 |
idna==3.7
|
|
@@ -92,6 +102,7 @@ langchainhub==0.1.20
|
|
| 92 |
langgraph==0.0.68
|
| 93 |
langsmith==0.1.77
|
| 94 |
Lazify==0.4.0
|
|
|
|
| 95 |
literalai==0.0.604
|
| 96 |
logfire==0.42.0
|
| 97 |
lru-dict==1.2.0
|
|
@@ -104,6 +115,7 @@ mdurl==0.1.2
|
|
| 104 |
mistune==3.0.2
|
| 105 |
multidict==6.0.5
|
| 106 |
multitasking==0.0.11
|
|
|
|
| 107 |
mypy-extensions==1.0.0
|
| 108 |
nbclient==0.10.0
|
| 109 |
nbconvert==7.16.4
|
|
@@ -111,6 +123,7 @@ nbformat==5.10.4
|
|
| 111 |
nest-asyncio==1.6.0
|
| 112 |
numexpr==2.10.0
|
| 113 |
numpy==1.26.4
|
|
|
|
| 114 |
openai==1.34.0
|
| 115 |
opentelemetry-api==1.25.0
|
| 116 |
opentelemetry-exporter-otlp==1.25.0
|
|
@@ -142,6 +155,7 @@ pickleshare==0.7.5
|
|
| 142 |
pipdeptree==2.22.0
|
| 143 |
pipreqs==0.5.0
|
| 144 |
platformdirs==4.2.2
|
|
|
|
| 145 |
prompt_toolkit==3.0.47
|
| 146 |
protobuf==4.25.3
|
| 147 |
psutil==5.9.8
|
|
@@ -149,6 +163,7 @@ psycopg==3.1.19
|
|
| 149 |
psycopg2==2.9.9
|
| 150 |
ptyprocess==0.7.0
|
| 151 |
pure-eval==0.2.2
|
|
|
|
| 152 |
pycryptodome==3.20.0
|
| 153 |
pydantic==2.7.4
|
| 154 |
pydantic-settings==2.3.3
|
|
@@ -175,6 +190,7 @@ rich==13.7.1
|
|
| 175 |
rlp==4.0.1
|
| 176 |
rpc.py==0.6.0
|
| 177 |
rpds-py==0.18.1
|
|
|
|
| 178 |
s3fs==2024.6.0
|
| 179 |
s3transfer==0.10.1
|
| 180 |
shellingham==1.5.4
|
|
@@ -202,11 +218,13 @@ types-requests==2.32.0.20240602
|
|
| 202 |
typing-inspect==0.9.0
|
| 203 |
typing_extensions==4.12.2
|
| 204 |
tzdata==2024.1
|
|
|
|
| 205 |
ulid==1.1
|
| 206 |
upstash-redis==1.1.0
|
| 207 |
uptrace==1.24.0
|
| 208 |
urllib3==2.2.1
|
| 209 |
-
uvicorn==0.
|
|
|
|
| 210 |
watchfiles==0.20.0
|
| 211 |
wcwidth==0.2.13
|
| 212 |
web3==6.19.0
|
|
|
|
| 8 |
anyio==3.7.1
|
| 9 |
appdirs==1.4.4
|
| 10 |
appnope==0.1.4
|
| 11 |
+
APScheduler==3.10.4
|
| 12 |
asgiref==3.8.1
|
| 13 |
asttokens==2.4.1
|
| 14 |
async-timeout==4.0.3
|
| 15 |
asyncer==0.0.2
|
| 16 |
attrs==23.2.0
|
| 17 |
backcall==0.2.0
|
| 18 |
+
backoff==2.2.1
|
| 19 |
baize==0.20.8
|
| 20 |
beautifulsoup4==4.12.3
|
| 21 |
bidict==0.23.1
|
|
|
|
| 23 |
bleach==6.1.0
|
| 24 |
boto3==1.34.106
|
| 25 |
botocore==1.34.106
|
| 26 |
+
cached-property==1.5.2
|
| 27 |
certifi==2024.6.2
|
| 28 |
+
cffi==1.16.0
|
| 29 |
chainlit==1.1.300
|
| 30 |
charset-normalizer==3.3.2
|
|
|
|
| 31 |
chevron==0.14.0
|
| 32 |
ckzg==1.0.2
|
| 33 |
click==8.1.7
|
| 34 |
coingecko==0.13
|
| 35 |
+
cryptography==42.0.8
|
| 36 |
cytoolz==0.12.3
|
| 37 |
dataclasses-json==0.5.14
|
| 38 |
decorator==5.1.1
|
| 39 |
defusedxml==0.7.1
|
| 40 |
Deprecated==1.2.14
|
| 41 |
distro==1.9.0
|
| 42 |
+
dnspython==2.6.1
|
| 43 |
docopt==0.6.2
|
| 44 |
duckduckgo_search==6.1.6
|
| 45 |
+
email_validator==2.2.0
|
| 46 |
eth-account==0.11.2
|
| 47 |
eth-hash==0.7.0
|
| 48 |
eth-keyfile==0.8.1
|
|
|
|
| 53 |
eth_abi==5.1.0
|
| 54 |
exceptiongroup==1.2.1
|
| 55 |
executing==2.0.1
|
| 56 |
+
fastapi==0.111.1
|
| 57 |
+
fastapi-cli==0.0.4
|
| 58 |
+
fastapi-sso==0.10.0
|
| 59 |
fastjsonschema==2.19.1
|
| 60 |
filelock==3.15.1
|
| 61 |
filetype==1.2.0
|
|
|
|
| 70 |
googleapis-common-protos==1.63.1
|
| 71 |
greenlet==3.0.3
|
| 72 |
grpcio==1.64.1
|
| 73 |
+
gunicorn==22.0.0
|
| 74 |
h11==0.14.0
|
| 75 |
hexbytes==0.3.1
|
| 76 |
html5lib==1.1
|
| 77 |
httpcore==1.0.5
|
| 78 |
+
httptools==0.6.1
|
| 79 |
httpx==0.27.0
|
| 80 |
huggingface-hub==0.23.3
|
| 81 |
idna==3.7
|
|
|
|
| 102 |
langgraph==0.0.68
|
| 103 |
langsmith==0.1.77
|
| 104 |
Lazify==0.4.0
|
| 105 |
+
litellm==1.41.21
|
| 106 |
literalai==0.0.604
|
| 107 |
logfire==0.42.0
|
| 108 |
lru-dict==1.2.0
|
|
|
|
| 115 |
mistune==3.0.2
|
| 116 |
multidict==6.0.5
|
| 117 |
multitasking==0.0.11
|
| 118 |
+
mypy==1.10.1
|
| 119 |
mypy-extensions==1.0.0
|
| 120 |
nbclient==0.10.0
|
| 121 |
nbconvert==7.16.4
|
|
|
|
| 123 |
nest-asyncio==1.6.0
|
| 124 |
numexpr==2.10.0
|
| 125 |
numpy==1.26.4
|
| 126 |
+
oauthlib==3.2.2
|
| 127 |
openai==1.34.0
|
| 128 |
opentelemetry-api==1.25.0
|
| 129 |
opentelemetry-exporter-otlp==1.25.0
|
|
|
|
| 155 |
pipdeptree==2.22.0
|
| 156 |
pipreqs==0.5.0
|
| 157 |
platformdirs==4.2.2
|
| 158 |
+
portkey-ai==1.7.0
|
| 159 |
prompt_toolkit==3.0.47
|
| 160 |
protobuf==4.25.3
|
| 161 |
psutil==5.9.8
|
|
|
|
| 163 |
psycopg2==2.9.9
|
| 164 |
ptyprocess==0.7.0
|
| 165 |
pure-eval==0.2.2
|
| 166 |
+
pycparser==2.22
|
| 167 |
pycryptodome==3.20.0
|
| 168 |
pydantic==2.7.4
|
| 169 |
pydantic-settings==2.3.3
|
|
|
|
| 190 |
rlp==4.0.1
|
| 191 |
rpc.py==0.6.0
|
| 192 |
rpds-py==0.18.1
|
| 193 |
+
rq==1.16.2
|
| 194 |
s3fs==2024.6.0
|
| 195 |
s3transfer==0.10.1
|
| 196 |
shellingham==1.5.4
|
|
|
|
| 218 |
typing-inspect==0.9.0
|
| 219 |
typing_extensions==4.12.2
|
| 220 |
tzdata==2024.1
|
| 221 |
+
tzlocal==5.2
|
| 222 |
ulid==1.1
|
| 223 |
upstash-redis==1.1.0
|
| 224 |
uptrace==1.24.0
|
| 225 |
urllib3==2.2.1
|
| 226 |
+
uvicorn==0.22.0
|
| 227 |
+
uvloop==0.19.0
|
| 228 |
watchfiles==0.20.0
|
| 229 |
wcwidth==0.2.13
|
| 230 |
web3==6.19.0
|
src/config/portkey_config.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
def generate_portkey_config(local: bool = True):
|
| 5 |
+
if local:
|
| 6 |
+
config = {
|
| 7 |
+
"strategy": {
|
| 8 |
+
"mode": "fallback"
|
| 9 |
+
},
|
| 10 |
+
"cache": {
|
| 11 |
+
"mode": "semantic",
|
| 12 |
+
"max_age": 10000
|
| 13 |
+
},
|
| 14 |
+
"retry": {
|
| 15 |
+
"attempts": 3,
|
| 16 |
+
"on_status_codes": [429]
|
| 17 |
+
},
|
| 18 |
+
"targets": [
|
| 19 |
+
# {
|
| 20 |
+
# "provider": "mistral-ai",
|
| 21 |
+
# "api_key": os.getenv("MISTRAL_API_KEY"),
|
| 22 |
+
# "override_params": {
|
| 23 |
+
# "model": "codestral-latest",
|
| 24 |
+
# "max_tokens": 1024,
|
| 25 |
+
# "temperature": 0
|
| 26 |
+
# }
|
| 27 |
+
# },
|
| 28 |
+
{
|
| 29 |
+
"provider": "anthropic",
|
| 30 |
+
"api_key": os.getenv("ANTHROPIC_API_KEY"),
|
| 31 |
+
"override_params": {
|
| 32 |
+
"model": "claude-3-5-sonnet-20240620",
|
| 33 |
+
"max_tokens": 1024,
|
| 34 |
+
"temperature": 0
|
| 35 |
+
}
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"provider": "openai",
|
| 39 |
+
"api_key": os.getenv("OPENAI_API_KEY"),
|
| 40 |
+
"override_params": {
|
| 41 |
+
"model": "gpt-4o",
|
| 42 |
+
"max_tokens": 1024,
|
| 43 |
+
"temperature": 0
|
| 44 |
+
}
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"provider": "anthropic",
|
| 48 |
+
"api_key": os.getenv("ANTHROPIC_API_KEY"),
|
| 49 |
+
"override_params": {
|
| 50 |
+
"model": "claude-3-opus-20240229",
|
| 51 |
+
"max_tokens": 1024,
|
| 52 |
+
"temperature": 0
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
]
|
| 56 |
+
}
|
| 57 |
+
else:
|
| 58 |
+
config = {
|
| 59 |
+
"strategy": {
|
| 60 |
+
"mode": "fallback"
|
| 61 |
+
},
|
| 62 |
+
"cache": {
|
| 63 |
+
"mode": "semantic",
|
| 64 |
+
"max_age": 10000
|
| 65 |
+
},
|
| 66 |
+
"retry": {
|
| 67 |
+
"attempts": 3,
|
| 68 |
+
"on_status_codes": [429]
|
| 69 |
+
},
|
| 70 |
+
"targets": [
|
| 71 |
+
|
| 72 |
+
{
|
| 73 |
+
"virtual_key": os.getenv("PORTKEY_OPENAI_VIRTUAL_KEY"),
|
| 74 |
+
"override_params": {
|
| 75 |
+
"model": "gpt-4o",
|
| 76 |
+
"max_tokens": 1024,
|
| 77 |
+
"temperature": 0
|
| 78 |
+
}
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"provider": "anthropic",
|
| 82 |
+
"api_key": os.getenv("POETRY_ANTHROPIC_API_KEY"),
|
| 83 |
+
"override_params": {
|
| 84 |
+
"model": "claude-3-5-sonnet-20240620",
|
| 85 |
+
"max_tokens": 1024,
|
| 86 |
+
"temperature": 0
|
| 87 |
+
}
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"virtual_key": os.getenv("PORTKEY_ANTHROPIC_API_KEY"),
|
| 91 |
+
"override_params": {
|
| 92 |
+
"model": "claude-3-opus-20240229",
|
| 93 |
+
"max_tokens": 1024,
|
| 94 |
+
"temperature": 0
|
| 95 |
+
}
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"virtual_key": os.getenv("PORTKEY_MISTRAL_API_KEY"),
|
| 99 |
+
"override_params": {
|
| 100 |
+
"model": "codestral-latest",
|
| 101 |
+
"max_tokens": 1024,
|
| 102 |
+
"temperature": 0
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
]
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
return json.dumps(config)
|