Merge branch 'dev' into config
This commit is contained in:
commit
6fb02dc227
9 changed files with 31 additions and 57 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import logging
|
||||
import multiprocessing
|
||||
import platform
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import typer
|
||||
|
|
@ -18,42 +17,6 @@ def get_number_of_workers(workers=None):
|
|||
return workers
|
||||
|
||||
|
||||
def replace_port(static_files_dir, host, port):
|
||||
# Load index.html from frontend directory
|
||||
# In it there is a script tag that sets the base url
|
||||
# like so setItem("port", "http://localhost:7860")
|
||||
# localhost could be anything so we need to verify for string
|
||||
# we need to set the base url to the port that the server is running on
|
||||
# so that the frontend can make requests to the backend
|
||||
# This is a hacky way to do it, but it works
|
||||
|
||||
# Check if the host is http or https
|
||||
logger.info(f"host: {host}")
|
||||
logger.info(f"port: {port}")
|
||||
url = f"{host}:{port}" if "http" in host else f"http://{host}:{port}"
|
||||
logger.info(f"url: {url}")
|
||||
new_string = f'setItem("port","{url}")'
|
||||
|
||||
with open(static_files_dir / "index.html", "r") as f:
|
||||
index_html = f.read()
|
||||
# using regex to replace the port
|
||||
index_html = re.sub(
|
||||
r"setItem\(\"port\",.*\)",
|
||||
new_string,
|
||||
index_html,
|
||||
)
|
||||
with open(static_files_dir / "index.html", "w") as f:
|
||||
f.write(index_html)
|
||||
# Verify that the port was replaced
|
||||
with open(static_files_dir / "index.html", "r") as f:
|
||||
index_html = f.read()
|
||||
if new_string not in index_html:
|
||||
raise ValueError(
|
||||
"The port was not replaced in index.html. "
|
||||
"Please check the regex in main.py"
|
||||
)
|
||||
|
||||
|
||||
def serve(
|
||||
host: str = "127.0.0.1", workers: int = 1, timeout: int = 60, port: int = 7860
|
||||
):
|
||||
|
|
@ -73,9 +36,6 @@ def serve(
|
|||
"timeout": timeout,
|
||||
}
|
||||
|
||||
# Replace the port in index.html
|
||||
replace_port(static_files_dir, host, port)
|
||||
|
||||
if platform.system() in ["Darwin", "Windows"]:
|
||||
# Run using uvicorn on MacOS and Windows
|
||||
# Windows doesn't support gunicorn
|
||||
|
|
|
|||
8
src/backend/langflow/utils/constants.py
Normal file
8
src/backend/langflow/utils/constants.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
OPENAI_MODELS = [
|
||||
"text-davinci-003",
|
||||
"text-davinci-002",
|
||||
"text-curie-001",
|
||||
"text-babbage-001",
|
||||
"text-ada-001",
|
||||
]
|
||||
CHAT_OPENAI_MODELS = ["gpt-3.5-turbo", "gpt-4", "gpt-4-32k"]
|
||||
|
|
@ -11,6 +11,8 @@ from langchain.agents.load_tools import (
|
|||
_LLM_TOOLS,
|
||||
)
|
||||
|
||||
from langflow.utils import constants
|
||||
|
||||
|
||||
def build_template_from_function(name: str, type_to_loader_dict: Dict):
|
||||
classes = [
|
||||
|
|
@ -296,9 +298,9 @@ def format_dict(d, name: Optional[str] = None):
|
|||
|
||||
# Add options to openai
|
||||
if name == "OpenAI" and key == "model_name":
|
||||
value["options"] = ["text-davinci-003", "text-davinci-002"]
|
||||
value["options"] = constants.OPENAI_MODELS
|
||||
elif name == "OpenAIChat" and key == "model_name":
|
||||
value["options"] = ["gpt-3.5-turbo", "gpt-4"]
|
||||
value["options"] = constants.CHAT_OPENAI_MODELS
|
||||
|
||||
return d
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue