dependency related changes

This commit is contained in:
hjoaquim
2023-12-19 08:25:04 +00:00
parent dd848abcca
commit a31b686f4e
4 changed files with 1042 additions and 573 deletions

View File

@@ -39,7 +39,6 @@ import pytz
import requests
import yfinance as yf
from holidays import US as us_holidays
from langchain.chat_models import ChatOpenAI
from llama_index import (
LLMPredictor,
PromptHelper,
@@ -2214,98 +2213,100 @@ def remove_timezone_from_dataframe(df: pd.DataFrame) -> pd.DataFrame:
@check_api_key(["API_OPENAI_KEY"])
def query_LLM_local(query_text, gpt_model):
current_user = get_current_user()
os.environ["OPENAI_API_KEY"] = current_user.credentials.API_OPENAI_KEY
# from langchain.chat_models import ChatOpenAI
# current_user = get_current_user()
# os.environ["OPENAI_API_KEY"] = current_user.credentials.API_OPENAI_KEY
# check if index exists
index_path = GPT_INDEX_DIRECTORY / f"index_{GPT_INDEX_VER}.json"
old_index_paths = [
str(x) for x in GPT_INDEX_DIRECTORY.glob("index_*.json") if x != index_path
]
# # check if index exists
# index_path = GPT_INDEX_DIRECTORY / f"index_{GPT_INDEX_VER}.json"
# old_index_paths = [
# str(x) for x in GPT_INDEX_DIRECTORY.glob("index_*.json") if x != index_path
# ]
# define LLM
llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.5, model_name=gpt_model))
# define prompt helper
prompt_helper = PromptHelper(context_window=4096, num_output=256)
service_context = ServiceContext.from_defaults(
llm_predictor=llm_predictor, prompt_helper=prompt_helper
)
# # define LLM
# llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.5, model_name=gpt_model))
# # define prompt helper
# prompt_helper = PromptHelper(context_window=4096, num_output=256)
# service_context = ServiceContext.from_defaults(
# llm_predictor=llm_predictor, prompt_helper=prompt_helper
# )
if os.path.exists(index_path):
# rebuild storage context
storage_context = StorageContext.from_defaults(persist_dir=index_path)
index = load_index_from_storage(
service_context=service_context, storage_context=storage_context
)
else:
# If the index file doesn't exist or is of incorrect version, generate a new one
# First, remove old version(s), if any
for path in old_index_paths:
if os.path.isfile(path):
os.remove(path)
elif os.path.isdir(path):
shutil.rmtree(path)
# if os.path.exists(index_path):
# # rebuild storage context
# storage_context = StorageContext.from_defaults(persist_dir=index_path)
# index = load_index_from_storage(
# service_context=service_context, storage_context=storage_context
# )
# else:
# # If the index file doesn't exist or is of incorrect version, generate a new one
# # First, remove old version(s), if any
# for path in old_index_paths:
# if os.path.isfile(path):
# os.remove(path)
# elif os.path.isdir(path):
# shutil.rmtree(path)
# Then, generate and save new index
# import from print console and say generating index, this might take a while
console.print("Generating index, this might take a while....\n")
# # Then, generate and save new index
# # import from print console and say generating index, this might take a while
# console.print("Generating index, this might take a while....\n")
# read in documents
documents = SimpleDirectoryReader(GPT_INDEX_DIRECTORY / "data/").load_data()
index = VectorStoreIndex.from_documents(
documents, service_context=service_context
)
# # read in documents
# documents = SimpleDirectoryReader(GPT_INDEX_DIRECTORY / "data/").load_data()
# index = VectorStoreIndex.from_documents(
# documents, service_context=service_context
# )
# save to disk
console.print("Saving index to disk....\n")
index.storage_context.persist(index_path)
# # save to disk
# console.print("Saving index to disk....\n")
# index.storage_context.persist(index_path)
current_date = datetime.now().astimezone(pytz.timezone("America/New_York"))
# current_date = datetime.now().astimezone(pytz.timezone("America/New_York"))
prompt_string = f"""From the cli argparse help text above, provide the terminal
command for {query_text}. If relevant, use the examples as guidance.
Provide the exact command along with the parent command with a "/" separation to get that information,
and nothing else including any explanation. Don't add any other word such as 'Command to get', 'Answer'
or the likes. If you do not know, reply "I don't know"
# prompt_string = f"""From the cli argparse help text above, provide the terminal
# command for {query_text}. If relevant, use the examples as guidance.
# Provide the exact command along with the parent command with a "/" separation to get that information,
# and nothing else including any explanation. Don't add any other word such as 'Command to get', 'Answer'
# or the likes. If you do not know, reply "I don't know"
Current date: {current_date.strftime("%Y-%m-%d")}
Current day of the week: {current_date.strftime("%A")}
# Current date: {current_date.strftime("%Y-%m-%d")}
# Current day of the week: {current_date.strftime("%A")}
Remember:
1. It is very important to provide the full path of the command including the parent command and loading
the particular target before running any subsequent commands
2. If you are asked about dates or times, load the target dates, times span during the "load" command
before running any subsequent commands. replace all <> with the actual dates and times. The date format should
be YYYY-MM-DD. If there is no date included in the query, do not specify any.
3. Country names should be snake case and lower case. example: united_states.
4. Always use a comma to separate between countries and no spaces: example: united_states,italy,spain
5. Always use "load" command first before running any subsequent commands. example:
stocks/load <symbol>/ ....
crypto/load <symbol>/ .... etc.
6. Do not include --export unless the request asks for the data to be exported or saved to a specific file type.
7. Do not make up any subcommands or options for the specific command.
8. Do not provide anything that could be interpreted as investment advice.
9. Any request asking for options refers to stocks/options.
# Remember:
# 1. It is very important to provide the full path of the command including the parent command and loading
# the particular target before running any subsequent commands
# 2. If you are asked about dates or times, load the target dates, times span during the "load" command
# before running any subsequent commands. replace all <> with the actual dates and times. The date format should
# be YYYY-MM-DD. If there is no date included in the query, do not specify any.
# 3. Country names should be snake case and lower case. example: united_states.
# 4. Always use a comma to separate between countries and no spaces: example: united_states,italy,spain
# 5. Always use "load" command first before running any subsequent commands. example:
# stocks/load <symbol>/ ....
# crypto/load <symbol>/ .... etc.
# 6. Do not include --export unless the request asks for the data to be exported or saved to a specific file type.
# 7. Do not make up any subcommands or options for the specific command.
# 8. Do not provide anything that could be interpreted as investment advice.
# 9. Any request asking for options refers to stocks/options.
Only do what is asked and only provide a single command string, never more than one.
"""
# Only do what is asked and only provide a single command string, never more than one.
# """
# try to get the response from the index
try:
query_engine = index.as_query_engine()
response = query_engine.query(prompt_string)
return response.response, response.source_nodes
except Exception as e:
# check if the error has the following "The model: `gpt-4` does not exist"
if "The model: `gpt-4` does not exist" in str(e):
console.print(
"[red]You do not have access to GPT4 model with your API key."
" Please try again with valid API Access.[/red]"
)
return None
# # try to get the response from the index
# try:
# query_engine = index.as_query_engine()
# response = query_engine.query(prompt_string)
# return response.response, response.source_nodes
# except Exception as e:
# # check if the error has the following "The model: `gpt-4` does not exist"
# if "The model: `gpt-4` does not exist" in str(e):
# console.print(
# "[red]You do not have access to GPT4 model with your API key."
# " Please try again with valid API Access.[/red]"
# )
# return None
console.print(f"[red]Something went wrong with the query. {e}[/red]")
return None, None
# console.print(f"[red]Something went wrong with the query. {e}[/red]")
# return None, None
return None, None
def query_LLM_remote(query_text: str):

View File

@@ -2963,14 +2963,15 @@ def check_nixtla_key(show_output: bool = False) -> str:
): # pragma: allowlist secret
status = KeyStatus.NOT_DEFINED
else:
timegpt = TimeGPT(
token=get_current_user().credentials.API_KEY_NIXTLA,
)
status = (
KeyStatus.DEFINED_TEST_PASSED
if timegpt.validate_token()
else KeyStatus.DEFINED_TEST_FAILED
)
# timegpt = TimeGPT(
# token=get_current_user().credentials.API_KEY_NIXTLA,
# )
# status = (
# KeyStatus.DEFINED_TEST_PASSED
# if timegpt.validate_token()
# else KeyStatus.DEFINED_TEST_FAILED
# )
status = KeyStatus.DEFINED_TEST_FAILED
if show_output:
console.print(status.colorize())

1422
poetry.lock generated vendored

File diff suppressed because it is too large Load Diff

15
pyproject.toml vendored
View File

@@ -16,7 +16,7 @@ openbb = 'terminal:main'
[tool.poetry.dependencies]
python = "^3.8.1,<3.11, !=3.9.7"
scipy = "1.10.1" #Pinning on July 6 for pip issues
scipy = "1.10.1" #Pinning on July 6 for pip issues
iso8601 = "^0.1.14"
FundamentalAnalysis = "^0.2.6"
requests = "^2.31.0"
@@ -78,7 +78,7 @@ feedparser = "^6.0.10"
pyinstaller = { version = "^4.10", optional = true }
jupyterlab-code-formatter = { version = "^1.4.10", optional = true }
jupyterlab-lsp = { version = "^3.10.1", optional = true }
jedi-language-server = { version = "^0.40.0", optional = true }
# jedi-language-server = { version = "^0.40.0", optional = true }
tokenterminal = "^1.0.1"
torch = { version = "~1.11.0", optional = true }
watchdog = "^2.1.9"
@@ -110,19 +110,20 @@ openai-whisper = { version = "^20230124", optional = true }
setuptools-rust = { version = "^1.5.2", optional = true }
transformers = { version = "4.27.1", optional = true }
yt-dlp = { version = "^2023.2.17", optional = true }
pydantic = "<2"
pydantic = "^2.5.1"
posthog = "^3.0.1"
reportlab = "<4" #Pinning due to build error on MacOs
arch = "^5.5.0"
llama-index = "^0.8.8"
langchain = "0.0.266" # Pinned for llama index
# langchain = "0.0.266" # Pinned for llama index
ffn = "0.3.6"
jupyter-client = "7.4.1"
jupyter-server = "1.23.6"
python-jose = "^3.3.0"
nixtlats = "^0.1.11" # Pinning for stability
nltk = "^3.8.1" # Is a dependence for llama index
# nixtlats = "^0.1.11" # Pinning for stability
nltk = "^3.8.1" # Is a dependence for llama index
openai = "0.28.1"
openbb = "^4.0.1"
[tool.poetry.extras]
@@ -183,7 +184,7 @@ nbmake = ">0.5.0"
pytest-timeout = "^2.1.0"
pytest-recorder = "^0.2.1"
freezegun = "^1.2.2"
ruff = "^0.0.285"
ruff = "^0.1.6"
mypy = "^1.5.1"
toml = "^0.10.2"
tomli = "^2.0.1"