This commit is contained in:
Jeffrey Chu 2025-10-22 19:15:42 +08:00
parent bac01b546d
commit 066956c85c
1 changed files with 4 additions and 4 deletions

View File

@ -8,13 +8,13 @@ class FinancialSituationMemory:
def __init__(self, name, config):
self.client = OpenAI(base_url=config["backend_url"], api_key=config.get("api_key"))
# 根據 backend 決定 embedding 策略
# Based on llm_provider to select embeddings
if config["llm_provider"] == "ollama":
self.embedding = "nomic-embed-text"
self.embedding_client = OpenAI(base_url="http://localhost:11434/v1")
self.use_local_embedding = False
elif config["llm_provider"] == "xai":
# Grok - 使用本地 Hugging Face 模型
# Grok - use local Hugging Face model
self.embedding_model = SentenceTransformer('all-MiniLM-L6-v2')
self.use_local_embedding = True
else:
@ -29,10 +29,10 @@ class FinancialSituationMemory:
def get_embedding(self, text):
"""Get embedding for a text"""
if self.use_local_embedding:
# 使用本地 Hugging Face 模型
# use local Hugging Face model
return self.embedding_model.encode(text).tolist()
else:
# 使用 API
# use API
response = self.embedding_client.embeddings.create(
model=self.embedding,
input=text