(feat) proxy: add curl command test + read cache config

This commit is contained in:
ishaan-jaff 2023-11-23 10:30:45 -08:00
parent dbd5f2b3cc
commit ae3eeb16ab

View file

@ -12,9 +12,7 @@ sys.path.insert(
try: try:
import uvicorn import uvicorn
import fastapi import fastapi
import tomli as tomllib
import appdirs import appdirs
import tomli_w
import backoff import backoff
import yaml import yaml
import rq import rq
@ -29,9 +27,7 @@ except ImportError:
"install", "install",
"uvicorn", "uvicorn",
"fastapi", "fastapi",
"tomli",
"appdirs", "appdirs",
"tomli-w",
"backoff", "backoff",
"pyyaml", "pyyaml",
"rq" "rq"
@ -39,9 +35,7 @@ except ImportError:
) )
import uvicorn import uvicorn
import fastapi import fastapi
import tomli as tomllib
import appdirs import appdirs
import tomli_w
import backoff import backoff
import yaml import yaml
@ -84,8 +78,6 @@ def generate_feedback_box():
"\033[1;31mGive Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new\033[0m" "\033[1;31mGive Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new\033[0m"
) )
print() print()
print("\033[1;34mDocs: https://docs.litellm.ai/docs/simple_proxy\033[0m\n")
print(f"\033[32mLiteLLM: Test your local endpoint with: \"litellm --test\" [In a new terminal tab]\033[0m\n")
print() print()
import litellm import litellm
@ -122,12 +114,6 @@ user_telemetry = True
user_config = None user_config = None
user_headers = None user_headers = None
local_logging = True # writes logs to a local api_log.json file for debugging local_logging = True # writes logs to a local api_log.json file for debugging
config_filename = "litellm.secrets.toml"
config_dir = os.getcwd()
config_dir = appdirs.user_config_dir("litellm")
user_config_path = os.getenv(
"LITELLM_CONFIG_PATH", os.path.join(config_dir, config_filename)
)
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
experimental = False experimental = False
#### GLOBAL VARIABLES #### #### GLOBAL VARIABLES ####
@ -280,7 +266,20 @@ def load_router_config(router: Optional[litellm.Router], config_file_path: str):
litellm_settings = config.get('litellm_settings', None) litellm_settings = config.get('litellm_settings', None)
if litellm_settings: if litellm_settings:
for key, value in litellm_settings.items(): for key, value in litellm_settings.items():
setattr(litellm, key, value) if key == "cache":
print("\nSetting Cache on Config\n")
from litellm.caching import Cache
cache_type = value["type"]
cache_host = os.environ.get("REDIS_HOST")
cache_port = os.environ.get("REDIS_PORT")
cache_password = os.environ.get("REDIS_PASSWORD")
litellm.cache = Cache(
type=cache_type,
host=cache_host,
port=cache_port,
password=cache_password
)
## MODEL LIST ## MODEL LIST
model_list = config.get('model_list', None) model_list = config.get('model_list', None)
if model_list: if model_list:
@ -289,10 +288,8 @@ def load_router_config(router: Optional[litellm.Router], config_file_path: str):
for model in model_list: for model in model_list:
print(f"\033[32m {model.get('model_name', '')}\033[0m") print(f"\033[32m {model.get('model_name', '')}\033[0m")
litellm_model_name = model["litellm_params"]["model"] litellm_model_name = model["litellm_params"]["model"]
# print(f"litellm_model_name: {litellm_model_name}")
if "ollama" in litellm_model_name: if "ollama" in litellm_model_name:
run_ollama_serve() run_ollama_serve()
print(f"returned general settings: {general_settings}")
return router, model_list, general_settings return router, model_list, general_settings
async def generate_key_helper_fn(duration_str: str, models: list, aliases: dict, config: dict): async def generate_key_helper_fn(duration_str: str, models: list, aliases: dict, config: dict):
@ -409,15 +406,26 @@ def initialize(
celery_setup(use_queue=use_queue) celery_setup(use_queue=use_queue)
if experimental: if experimental:
pass pass
if save:
pass
# save_params_to_config(dynamic_config)
# with open(user_config_path) as f:
# print(f.read())
# print("\033[1;32mDone successfully\033[0m")
user_telemetry = telemetry user_telemetry = telemetry
usage_telemetry(feature="local_proxy_server") usage_telemetry(feature="local_proxy_server")
curl_command = """
curl --location 'http://0.0.0.0:8000/chat/completions' \\
--header 'Content-Type: application/json' \\
--data ' {
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "what llm are you"
}
]
}'
\n
"""
print()
print(f"\033[1;34mLiteLLM: Test your local proxy with: \"litellm --test\" This runs an openai.ChatCompletion request to your proxy [In a new terminal tab]\033[0m\n")
print(f"\033[1;34mLiteLLM: Curl Command Test for your local proxy\n {curl_command} \033[0m\n")
print("\033[1;34mDocs: https://docs.litellm.ai/docs/simple_proxy\033[0m\n")
# for streaming # for streaming
def data_generator(response): def data_generator(response):
print_verbose("inside generator") print_verbose("inside generator")