Spaces:
Sleeping
Sleeping
| import os | |
| from dotenv import load_dotenv | |
| from langchain_openai import ChatOpenAI | |
| from llama_index.embeddings.openai import OpenAIEmbedding | |
| from langchain_ollama import ChatOllama, OllamaEmbeddings | |
| # Load environment variables from .env file | |
| load_dotenv() | |
| class Config: | |
| LLM_PROVIDER="ollama" | |
| if LLM_PROVIDER == "ollama": | |
| # Ollama configuration | |
| OLLAMA_BASE_URL="http://localhost:11434" | |
| #LOCAL_LLM_MODEL="deepseek-r1:8b" | |
| #LOCAL_LLM_MODEL="deepseek-r1:7b" | |
| LOCAL_LLM_MODEL = "llama3.2" | |
| LOCAL_LLM = ChatOllama(model=LOCAL_LLM_MODEL, | |
| base_url=OLLAMA_BASE_URL, | |
| temperature=0.5) | |
| EMBED_MODEL = OllamaEmbeddings(model="nomic-embed-text") | |
| elif LLM_PROVIDER == "openai": | |
| OPENAI_API_KEY:str = os.getenv("OPENAI_API_KEY","") | |
| LLM_MODEL_NAME:str = os.getenv("LLM_MODEL","gpt-3.5-turbo") | |
| LLM_VIDEO_MODEL_NAME:str = os.getenv("LLM_VIDEO_MODEL","gpt-4o-mini") | |
| LLM = ChatOpenAI(model=LLM_MODEL_NAME, openai_api_key=OPENAI_API_KEY) | |
| EMBED_MODEL = OpenAIEmbedding(openai_api_key=OPENAI_API_KEY) | |
| FILE = None | |
| WIKI_DEFAULT_PROMPTS = { | |
| "system": ( | |
| "You are an intelligent assistant with access to Wikipedia search results related to the user's query.\n" | |
| "Use only the information provided in the search results to answer the question accurately.\n" | |
| "Carefully analyze the query to determine what the user is asking.\n" | |
| "Respond clearly and concisely, avoiding speculation or information not found in the provided content.\n" | |
| "If the answer is not present in the search results, state that explicitly." | |
| ), | |
| "user": "{query}" | |
| } | |
| SYSTEM_MSG = f""" | |
| You are a general-purpose AI assistant. | |
| When I ask you a question: | |
| - Think step by step to determine the answer. | |
| - List your reasoning steps clearly. | |
| - If additional information is required to answer the question, use the 'wiki' tool by providing the directive: tool_call: [wiki]. | |
| - Provide your final output using one of the following formats: | |
| - FINAL ANSWER: [YOUR FINAL ANSWER] | |
| - tool_call: [TOOL_NAME] | |
| Only one of these should appear in your final output — either FINAL ANSWER or tool_call. | |
| If you are unsure or need more information, always use the 'wiki' tool. | |
| Final answer formatting rules: | |
| - If the answer is a number: | |
| - Do NOT use commas (e.g., write 1000 not 1,000). | |
| - Do NOT include units like "$" or "%" unless explicitly requested. | |
| - If the answer is a string: | |
| - Do NOT use articles (e.g., "a", "an", "the"). | |
| - Do NOT use abbreviations (e.g., write "New York" instead of "NY"). | |
| - Write digits as plain text (e.g., "four" instead of "4") unless stated otherwise. | |
| - If the answer is a comma-separated list: | |
| - Follow the same rules above for each item depending on whether it’s a number or a string. | |
| Do NOT include any additional arguments in tool calls. | |
| Available tools: | |
| - wikipedia_search_tool: Search Wikipedia. | |
| """ | |
| config = Config() |