diff --git a/.env.example b/.env.example index e18d0d69..f2d49709 100644 --- a/.env.example +++ b/.env.example @@ -1,9 +1,17 @@ -# the model name must be gpt-4o-2024-08-06 as it is dependent on structured output from open ai -MODEL_NAME="gpt-4o-2024-08-06" +# The model name must be 'gpt-4o-2024-08-06' as it is dependent on structured output from OpenAI LITELLM_LOG="ERROR" -OPENAI_API_KEY="" +# OpenAI's API settings +# Example TogetherAI endpoint +OPENAI_BASE_URL=https://api.together.xyz/v1 +OPENAI_API_KEY= + +# The model to use for the LLM +MODEL_NAME=meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo + +# Port for Google crome dev mode +CHROME_PORT=9222 # you can skip adding langfuse api keys. refer to the readme on how to disable tracing with langfuse. LANGFUSE_SECRET_KEY="sk-lf-" diff --git a/agentq/core/agent/base.py b/agentq/core/agent/base.py index 2859b983..a8ced22b 100644 --- a/agentq/core/agent/base.py +++ b/agentq/core/agent/base.py @@ -23,7 +23,7 @@ def __init__( output_format: Type[BaseModel], tools: Optional[List[Tuple[Callable, str]]] = None, keep_message_history: bool = True, - client: str = "openai", + client: str = None ): # Metdata self.agent_name = name @@ -44,13 +44,17 @@ def __init__( litellm.logging = True litellm.set_verbose = True + # Base URL & Model + base_url = os.getenv("OPENAI_BASE_URL", "https://api.openai.com/v1") + api_key = os.getenv("OPENAI_API_KEY", "") + # Llm client - if client == "openai": + if base_url == "https://api.openai.com/v1": self.client = openai.Client() - elif client == "together": + else: self.client = openai.OpenAI( - base_url="https://api.together.xyz/v1", - api_key=os.environ["TOGETHER_API_KEY"], + base_url=base_url, + api_key=api_key, ) self.client = instructor.from_openai(self.client, mode=Mode.JSON) @@ -75,8 +79,7 @@ async def run( input_data: BaseModel, screenshot: str = None, session_id: str = None, - # model: str = "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo", - model: str = "gpt-4o-2024-08-06", + model: str = os.getenv("MODEL_NAME", "gpt-4o-mini"), ) -> BaseModel: if not isinstance(input_data, self.input_format): raise ValueError(f"Input data must be of type {self.input_format.__name__}") @@ -131,10 +134,6 @@ async def run( if len(self.tools_list) == 0: response = self.client.chat.completions.create( model=model, - # model="gpt-4o-2024-08-06", - # model="gpt-4o-mini", - # model="groq/llama3-groq-70b-8192-tool-use-preview", - # model="xlam-1b-fc-r", messages=self.messages, response_model=self.output_format, max_retries=4, diff --git a/agentq/core/web_driver/playwright.py b/agentq/core/web_driver/playwright.py index 0c58d566..f3643c08 100644 --- a/agentq/core/web_driver/playwright.py +++ b/agentq/core/web_driver/playwright.py @@ -1,3 +1,4 @@ +import os import tempfile import time from typing import List, Union @@ -190,7 +191,7 @@ async def create_browser_context(self): ) else: browser = await PlaywrightManager._playwright.chromium.connect_over_cdp( - "http://localhost:9222" + "http://localhost:{}".format(int(os.getenv("CHROME_PORT", "9222"))) ) PlaywrightManager._browser_context = browser.contexts[0]