Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
@@ -31,6 +31,8 @@ from langchain_core.prompts import ChatPromptTemplate
|
|
31 |
# LangChain OpenAI imports
|
32 |
from langchain_openai import AzureOpenAIEmbeddings, AzureChatOpenAI # OpenAI embeddings and models
|
33 |
from langchain.embeddings.openai import OpenAIEmbeddings # OpenAI embeddings for text vectors
|
|
|
|
|
34 |
|
35 |
# LlamaParse & LlamaIndex imports
|
36 |
from llama_parse import LlamaParse # Document parsing library
|
@@ -54,10 +56,16 @@ from datetime import datetime
|
|
54 |
|
55 |
#====================================SETUP=====================================#
|
56 |
# Fetch secrets from Hugging Face Spaces
|
57 |
-
api_key = config.get("API_KEY")
|
58 |
-
endpoint = config.get("OPENAI_API_BASE")
|
59 |
-
llama_api_key = os.environ['GROQ_API_KEY']
|
60 |
-
MEM0_api_key = os.environ['mem0']
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
# Initialize the OpenAI embedding function for Chroma
|
63 |
embedding_function = chromadb.utils.embedding_functions.OpenAIEmbeddingFunction(
|
@@ -542,16 +550,25 @@ class NutritionBot:
|
|
542 |
"""
|
543 |
|
544 |
# Initialize a memory client to store and retrieve customer interactions
|
545 |
-
self.memory = MemoryClient(api_key=userdata.get("mem0")) # Complete the code to define the memory client API key
|
|
|
546 |
|
547 |
-
#
|
548 |
self.client = ChatOpenAI(
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
)
|
554 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
555 |
# Define tools available to the chatbot, such as web search
|
556 |
tools = [agentic_rag]
|
557 |
|
|
|
31 |
# LangChain OpenAI imports
|
32 |
from langchain_openai import AzureOpenAIEmbeddings, AzureChatOpenAI # OpenAI embeddings and models
|
33 |
from langchain.embeddings.openai import OpenAIEmbeddings # OpenAI embeddings for text vectors
|
34 |
+
from langchain_openai import ChatOpenAI # add this import
|
35 |
+
|
36 |
|
37 |
# LlamaParse & LlamaIndex imports
|
38 |
from llama_parse import LlamaParse # Document parsing library
|
|
|
56 |
|
57 |
#====================================SETUP=====================================#
|
58 |
# Fetch secrets from Hugging Face Spaces
|
59 |
+
#api_key = config.get("API_KEY")
|
60 |
+
#endpoint = config.get("OPENAI_API_BASE")
|
61 |
+
#llama_api_key = os.environ['GROQ_API_KEY']
|
62 |
+
#MEM0_api_key = os.environ['mem0']
|
63 |
+
|
64 |
+
# Fetch secrets from Hugging Face Spaces
|
65 |
+
api_key = os.environ.get("API_KEY")
|
66 |
+
endpoint = os.environ.get("OPENAI_API_BASE")
|
67 |
+
llama_api_key = os.environ.get("GROQ_API_KEY")
|
68 |
+
MEM0_api_key = os.environ.get("mem0")
|
69 |
|
70 |
# Initialize the OpenAI embedding function for Chroma
|
71 |
embedding_function = chromadb.utils.embedding_functions.OpenAIEmbeddingFunction(
|
|
|
550 |
"""
|
551 |
|
552 |
# Initialize a memory client to store and retrieve customer interactions
|
553 |
+
#self.memory = MemoryClient(api_key=userdata.get("mem0")) # Complete the code to define the memory client API key
|
554 |
+
self.memory = MemoryClient(api_key=os.environ.get("mem0"))
|
555 |
|
556 |
+
# LLM client
|
557 |
self.client = ChatOpenAI(
|
558 |
+
openai_api_base=os.environ.get("OPENAI_API_BASE"),
|
559 |
+
openai_api_key=os.environ.get("API_KEY"),
|
560 |
+
model="gpt-4o-mini",
|
561 |
+
temperature=0
|
562 |
)
|
563 |
|
564 |
+
# Initialize the OpenAI client using the provided credentials
|
565 |
+
#self.client = ChatOpenAI(
|
566 |
+
# model_name="gpt-4o-mini", # Specify the model to use (e.g., GPT-4 optimized version)
|
567 |
+
# api_key=config.get("API_KEY"), # API key for authentication
|
568 |
+
# endpoint = config.get("OPENAI_API_BASE"),
|
569 |
+
# temperature=0 # Controls randomness in responses; 0 ensures deterministic results
|
570 |
+
#)
|
571 |
+
|
572 |
# Define tools available to the chatbot, such as web search
|
573 |
tools = [agentic_rag]
|
574 |
|