diff --git a/.github/workflows/code-style-check.yml b/.github/workflows/code-style-check.yml new file mode 100644 index 00000000000..7faee77eaec --- /dev/null +++ b/.github/workflows/code-style-check.yml @@ -0,0 +1,24 @@ +name: Code Style Check + +on: + pull_request: + branches: + - main + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Install Python dependencies + run: pip install black nbqa + + - name: Run Black on Python files + run: black --check $(find . -type f -name "*.py") diff --git a/.github/workflows/operation-test-with-jupyter.yml b/.github/workflows/operation-test-with-jupyter.yml index be2253e4d22..5e2b1d23957 100644 --- a/.github/workflows/operation-test-with-jupyter.yml +++ b/.github/workflows/operation-test-with-jupyter.yml @@ -44,8 +44,7 @@ jobs: digest: ${{ steps.dockerBuild.outputs.digest }} services: service-under-test: - image: | - echo "${{ inputs.image }}" | tr '[:upper:]' '[:lower:]' + image: ${{ inputs.image }} ports: - ${{ inputs.port-mapping || format('{0}:{1}', inputs.port, inputs.port) }} diff --git a/.github/workflows/publish-docker-dev.yml b/.github/workflows/publish-docker-dev.yml index d0ed4824300..deebf2c6c80 100644 --- a/.github/workflows/publish-docker-dev.yml +++ b/.github/workflows/publish-docker-dev.yml @@ -45,7 +45,7 @@ jobs: uses: josh-xt/AGiXT/.github/workflows/operation-test-with-jupyter.yml@main with: notebook: tests/tests.ipynb - image: ghcr.io/${{ github.repository }}:${{ github.sha }} + image: ghcr.io/josh-xt/agixt:${{ github.sha }} port: "7437" additional-python-dependencies: openai requests needs: build-agixt diff --git a/agixt/Chains.py b/agixt/Chains.py index 58864cac5bf..a93f0e2ce48 100644 --- a/agixt/Chains.py +++ b/agixt/Chains.py @@ -67,13 +67,15 @@ async def run_chain_step( chain_name=args["chain"], user_input=args["input"], agent_name=agent_name, - all_responses=args["all_responses"] - if "all_responses" in args - else False, + all_responses=( + args["all_responses"] if "all_responses" in args else False + ), from_step=args["from_step"] if "from_step" in args else 1, - chain_args=args["chain_args"] - if "chain_args" in args - else {"conversation_name": args["conversation_name"]}, + chain_args=( + args["chain_args"] + if "chain_args" in args + else {"conversation_name": args["conversation_name"]} + ), ) if result: if isinstance(result, dict) and "response" in result: @@ -102,9 +104,11 @@ async def run_chain( role="USER", message=user_input, agent_name=agent_override if agent_override != "" else "AGiXT", - conversation_name=f"Chain Execution History: {chain_name}" - if "conversation_name" not in chain_args - else chain_args["conversation_name"], + conversation_name=( + f"Chain Execution History: {chain_name}" + if "conversation_name" not in chain_args + else chain_args["conversation_name"] + ), user=self.user, ) logging.info(f"Running chain '{chain_name}'") @@ -155,9 +159,11 @@ async def run_chain( role=agent_override if agent_override != "" else "AGiXT", message=last_response, agent_name=agent_override if agent_override != "" else "AGiXT", - conversation_name=f"Chain Execution History: {chain_name}" - if "conversation_name" not in chain_args - else chain_args["conversation_name"], + conversation_name=( + f"Chain Execution History: {chain_name}" + if "conversation_name" not in chain_args + else chain_args["conversation_name"] + ), user=self.user, ) return last_response diff --git a/agixt/Embedding.py b/agixt/Embedding.py index 049138ff8aa..df1260bffdc 100644 --- a/agixt/Embedding.py +++ b/agixt/Embedding.py @@ -105,15 +105,21 @@ def get_embedder_settings(self): "API_URI", ], "embed": OpenAIEmbeddingFunction( - model_name=self.agent_settings["AI_MODEL"] - if "AI_MODEL" in self.agent_settings - else "zephyr-7b-beta", - api_key=self.agent_settings["LOCAL_LLM_API_KEY"] - if "LOCAL_LLM_API_KEY" in self.agent_settings - else None, - api_base=self.agent_settings["API_URI"] - if "API_URI" in self.agent_settings - else "http://localhost:8091/v1", + model_name=( + self.agent_settings["AI_MODEL"] + if "AI_MODEL" in self.agent_settings + else "zephyr-7b-beta" + ), + api_key=( + self.agent_settings["LOCAL_LLM_API_KEY"] + if "LOCAL_LLM_API_KEY" in self.agent_settings + else None + ), + api_base=( + self.agent_settings["API_URI"] + if "API_URI" in self.agent_settings + else "http://localhost:8091/v1" + ), ), }, "azure": { @@ -123,42 +129,52 @@ def get_embedder_settings(self): "AZURE_DEPLOYMENT_NAME", "AZURE_OPENAI_ENDPOINT", ], - "embed": OpenAIEmbeddingFunction( - api_key=self.agent_settings["AZURE_API_KEY"], - organization_id=self.agent_settings["AZURE_DEPLOYMENT_NAME"], - api_base=self.agent_settings["AZURE_OPENAI_ENDPOINT"], - api_type="azure", - ) - if "AZURE_API_KEY" in self.agent_settings - and "AZURE_DEPLOYMENT_NAME" in self.agent_settings - and "AZURE_OPENAI_ENDPOINT" in self.agent_settings - else self.default_embedder, + "embed": ( + OpenAIEmbeddingFunction( + api_key=self.agent_settings["AZURE_API_KEY"], + organization_id=self.agent_settings["AZURE_DEPLOYMENT_NAME"], + api_base=self.agent_settings["AZURE_OPENAI_ENDPOINT"], + api_type="azure", + ) + if "AZURE_API_KEY" in self.agent_settings + and "AZURE_DEPLOYMENT_NAME" in self.agent_settings + and "AZURE_OPENAI_ENDPOINT" in self.agent_settings + else self.default_embedder + ), }, "openai": { "chunk_size": 1000, "params": ["OPENAI_API_KEY", "API_URI"], - "embed": OpenAIEmbeddingFunction( - api_key=self.agent_settings["OPENAI_API_KEY"], - model_name="text-embedding-ada-002" - if api_base == "https://api.openai.com/v1" - else self.agent_settings["AI_MODEL"] - if "AI_MODEL" in self.agent_settings - else "Mistral-7B-OpenOrca", - api_base=api_base, - ) - if "OPENAI_API_KEY" in self.agent_settings - else self.default_embedder, + "embed": ( + OpenAIEmbeddingFunction( + api_key=self.agent_settings["OPENAI_API_KEY"], + model_name=( + "text-embedding-ada-002" + if api_base == "https://api.openai.com/v1" + else ( + self.agent_settings["AI_MODEL"] + if "AI_MODEL" in self.agent_settings + else "Mistral-7B-OpenOrca" + ) + ), + api_base=api_base, + ) + if "OPENAI_API_KEY" in self.agent_settings + else self.default_embedder + ), }, "google_vertex": { "chunk_size": 1000, "params": ["GOOGLE_API_KEY", "GOOGLE_PROJECT_ID"], - "embed": GoogleVertexEmbeddingFunction( - api_key=self.agent_settings["GOOGLE_API_KEY"], - project_id=self.agent_settings["GOOGLE_PROJECT_ID"], - ) - if "GOOGLE_PROJECT_ID" in self.agent_settings - and "GOOGLE_API_KEY" in self.agent_settings - else self.default_embedder, + "embed": ( + GoogleVertexEmbeddingFunction( + api_key=self.agent_settings["GOOGLE_API_KEY"], + project_id=self.agent_settings["GOOGLE_PROJECT_ID"], + ) + if "GOOGLE_PROJECT_ID" in self.agent_settings + and "GOOGLE_API_KEY" in self.agent_settings + else self.default_embedder + ), }, } return embedder_settings diff --git a/agixt/Interactions.py b/agixt/Interactions.py index f3c86a938cf..95776e3575a 100644 --- a/agixt/Interactions.py +++ b/agixt/Interactions.py @@ -42,11 +42,11 @@ def __init__( agent_name=self.agent_name, agent_config=self.agent.AGENT_CONFIG, ApiClient=ApiClient, - searxng_instance_url=self.agent.AGENT_CONFIG["settings"][ - "SEARXNG_INSTANCE_URL" - ] - if "SEARXNG_INSTANCE_URL" in self.agent.AGENT_CONFIG["settings"] - else "", + searxng_instance_url=( + self.agent.AGENT_CONFIG["settings"]["SEARXNG_INSTANCE_URL"] + if "SEARXNG_INSTANCE_URL" in self.agent.AGENT_CONFIG["settings"] + else "" + ), ) else: self.agent_name = "" @@ -403,9 +403,9 @@ async def run( user=self.user, ) command_output = await ext.execute_command( - command_name="Transcribe M4A Audio" - if is_m4a_audio - else "Transcribe WAV Audio", + command_name=( + "Transcribe M4A Audio" if is_m4a_audio else "Transcribe WAV Audio" + ), command_args={"base64_audio": user_input}, ) user_input = command_output diff --git a/agixt/Memories.py b/agixt/Memories.py index 1a90ba6ca57..b34fc9f97a8 100644 --- a/agixt/Memories.py +++ b/agixt/Memories.py @@ -119,9 +119,11 @@ def get_chroma_client(): return chromadb.HttpClient( host=chroma_host, port=os.environ.get("CHROMA_PORT", "8000"), - ssl=False - if os.environ.get("CHROMA_SSL", "false").lower() != "true" - else True, + ssl=( + False + if os.environ.get("CHROMA_SSL", "false").lower() != "true" + else True + ), headers=chroma_headers, settings=chroma_settings, ) diff --git a/agixt/Providers.py b/agixt/Providers.py index 5df2148e4bd..d48d4710087 100644 --- a/agixt/Providers.py +++ b/agixt/Providers.py @@ -41,9 +41,11 @@ def get_provider_options(provider_name): provider_class = getattr(module, f"{provider_name.capitalize()}Provider") signature = inspect.signature(provider_class.__init__) options = { - name: param.default - if param.default is not inspect.Parameter.empty - else None + name: ( + param.default + if param.default is not inspect.Parameter.empty + else None + ) for name, param in signature.parameters.items() if name != "self" and name != "kwargs" } diff --git a/agixt/endpoints/Memory.py b/agixt/endpoints/Memory.py index a954fa83635..d346314006b 100644 --- a/agixt/endpoints/Memory.py +++ b/agixt/endpoints/Memory.py @@ -297,9 +297,9 @@ async def agent_reader( agent_name=agent_name, agent_config=agent_config, collection_number=collection_number, - use_agent_settings=data["use_agent_settings"] - if "use_agent_settings" in data - else False, + use_agent_settings=( + data["use_agent_settings"] if "use_agent_settings" in data else False + ), ApiClient=ApiClient, user=user, ).write_github_repository_to_memory( diff --git a/agixt/extensions/stable_diffusion.py b/agixt/extensions/stable_diffusion.py index d242e497613..0c1e8668528 100644 --- a/agixt/extensions/stable_diffusion.py +++ b/agixt/extensions/stable_diffusion.py @@ -84,9 +84,11 @@ async def generate_image( ) generation_settings = { "prompt": prompt, - "negative_prompt": negative_prompt - if negative_prompt - else "out of frame,lowres,text,error,cropped,worst quality,low quality,jpeg artifacts,ugly,duplicate,morbid,mutilated,out of frame,extra fingers,mutated hands,poorly drawn hands,poorly drawn face,mutation,deformed,blurry,dehydrated,bad anatomy,bad proportions,extra limbs,cloned face,disfigured,gross proportions,malformed limbs,missing arms,missing legs,extra arms,extra legs,fused fingers,too many fingers,long neck,username,watermark,signature", + "negative_prompt": ( + negative_prompt + if negative_prompt + else "out of frame,lowres,text,error,cropped,worst quality,low quality,jpeg artifacts,ugly,duplicate,morbid,mutilated,out of frame,extra fingers,mutated hands,poorly drawn hands,poorly drawn face,mutation,deformed,blurry,dehydrated,bad anatomy,bad proportions,extra limbs,cloned face,disfigured,gross proportions,malformed limbs,missing arms,missing legs,extra arms,extra legs,fused fingers,too many fingers,long neck,username,watermark,signature" + ), "batch_size": batch_size if batch_size else 1, "cfg_scale": cfg_scale if cfg_scale else 7, "denoising_strength": denoising_strength if denoising_strength else 0, diff --git a/agixt/providers/gemini.py b/agixt/providers/gemini.py index bf79fb6b826..fd51843ae60 100644 --- a/agixt/providers/gemini.py +++ b/agixt/providers/gemini.py @@ -5,11 +5,22 @@ except ImportError: import sys import subprocess - subprocess.check_call([sys.executable, "-m", "pip", "install", "google.generativeai"]) + + subprocess.check_call( + [sys.executable, "-m", "pip", "install", "google.generativeai"] + ) import google.generativeai as genai # Import again after installation + class GeminiProvider: - def __init__(self, GOOGLE_API_KEY: str, AI_MODEL: str = "gemini-pro", MAX_TOKENS: int = 4000, AI_TEMPERATURE: float = 0.7, **kwargs): + def __init__( + self, + GOOGLE_API_KEY: str, + AI_MODEL: str = "gemini-pro", + MAX_TOKENS: int = 4000, + AI_TEMPERATURE: float = 0.7, + **kwargs, + ): """ Initialize the GeminiProvider with required parameters. @@ -33,7 +44,9 @@ def __init__(self, GOOGLE_API_KEY: str, AI_MODEL: str = "gemini-pro", MAX_TOKENS print(f"Error setting up Gemini model: {e}") # Set default generation config - self.generation_config = genai.types.GenerationConfig(max_output_tokens=self.MAX_TOKENS, temperature=self.AI_TEMPERATURE) + self.generation_config = genai.types.GenerationConfig( + max_output_tokens=self.MAX_TOKENS, temperature=self.AI_TEMPERATURE + ) async def inference(self, prompt, tokens: int = 0): """ @@ -49,17 +62,23 @@ async def inference(self, prompt, tokens: int = 0): try: # Adjust based on Gemini API new_max_tokens = int(self.MAX_TOKENS) - tokens - generation_config = genai.types.GenerationConfig(max_output_tokens=new_max_tokens, temperature=float(self.AI_TEMPERATURE)) + generation_config = genai.types.GenerationConfig( + max_output_tokens=new_max_tokens, temperature=float(self.AI_TEMPERATURE) + ) - response = await asyncio.to_thread(self.model.generate_content, - contents=prompt, - generation_config=generation_config) + response = await asyncio.to_thread( + self.model.generate_content, + contents=prompt, + generation_config=generation_config, + ) # Extract the generated text from the response if response.parts: - generated_text = ''.join(part.text for part in response.parts) + generated_text = "".join(part.text for part in response.parts) else: - generated_text = ''.join(part.text for part in response.candidates[0].content.parts) + generated_text = "".join( + part.text for part in response.candidates[0].content.parts + ) return generated_text except Exception as e: