update code so that OPENAI_API_KEY is not necessary when LLM is using others
This commit is contained in:
parent
cfd963bf5e
commit
6510923625
|
|
@ -1,2 +1,7 @@
|
||||||
ALPHA_VANTAGE_API_KEY=alpha_vantage_api_key_placeholder
|
ALPHA_VANTAGE_API_KEY=alpha_vantage_api_key_placeholder
|
||||||
|
# only select 1 to your .env
|
||||||
OPENAI_API_KEY=openai_api_key_placeholder
|
OPENAI_API_KEY=openai_api_key_placeholder
|
||||||
|
OPENROUTER_API_KEY=openrouter_api_key_placeholder
|
||||||
|
ANTHROPIC_API_KEY=anthropic_api_key_placeholder
|
||||||
|
GOOGLE_API_KEY=google_api_key_placeholder
|
||||||
|
XAI_API_KEY=xai_api_key_placeholder
|
||||||
|
|
@ -6,8 +6,6 @@ from sentence_transformers import SentenceTransformer
|
||||||
|
|
||||||
class FinancialSituationMemory:
|
class FinancialSituationMemory:
|
||||||
def __init__(self, name, config):
|
def __init__(self, name, config):
|
||||||
self.client = OpenAI(base_url=config["backend_url"], api_key=config.get("api_key"))
|
|
||||||
|
|
||||||
# Based on llm_provider to select embeddings
|
# Based on llm_provider to select embeddings
|
||||||
if config["llm_provider"] == "ollama":
|
if config["llm_provider"] == "ollama":
|
||||||
self.embedding = "nomic-embed-text"
|
self.embedding = "nomic-embed-text"
|
||||||
|
|
@ -18,6 +16,7 @@ class FinancialSituationMemory:
|
||||||
self.embedding_model = SentenceTransformer('all-MiniLM-L6-v2')
|
self.embedding_model = SentenceTransformer('all-MiniLM-L6-v2')
|
||||||
self.use_local_embedding = True
|
self.use_local_embedding = True
|
||||||
else:
|
else:
|
||||||
|
self.client = OpenAI(base_url=config["backend_url"], api_key=config.get("api_key"))
|
||||||
self.embedding = "text-embedding-3-small"
|
self.embedding = "text-embedding-3-small"
|
||||||
self.embedding_client = self.client
|
self.embedding_client = self.client
|
||||||
self.use_local_embedding = False
|
self.use_local_embedding = False
|
||||||
|
|
@ -25,7 +24,6 @@ class FinancialSituationMemory:
|
||||||
self.chroma_client = chromadb.Client(Settings(allow_reset=True))
|
self.chroma_client = chromadb.Client(Settings(allow_reset=True))
|
||||||
self.situation_collection = self.chroma_client.create_collection(name=name)
|
self.situation_collection = self.chroma_client.create_collection(name=name)
|
||||||
|
|
||||||
|
|
||||||
def get_embedding(self, text):
|
def get_embedding(self, text):
|
||||||
"""Get embedding for a text"""
|
"""Get embedding for a text"""
|
||||||
if self.use_local_embedding:
|
if self.use_local_embedding:
|
||||||
|
|
@ -39,7 +37,6 @@ class FinancialSituationMemory:
|
||||||
)
|
)
|
||||||
return response.data[0].embedding
|
return response.data[0].embedding
|
||||||
|
|
||||||
|
|
||||||
def add_situations(self, situations_and_advice):
|
def add_situations(self, situations_and_advice):
|
||||||
"""Add financial situations and their corresponding advice. Parameter is a list of tuples (situation, rec)"""
|
"""Add financial situations and their corresponding advice. Parameter is a list of tuples (situation, rec)"""
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue