Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add codestyle checks #1115

Merged
merged 4 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/code-style-check.yml
Original file line number Diff line number Diff line change
@@ -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")
3 changes: 1 addition & 2 deletions .github/workflows/operation-test-with-jupyter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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) }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-docker-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 18 additions & 12 deletions agixt/Chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}'")
Expand Down Expand Up @@ -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
Expand Down
90 changes: 53 additions & 37 deletions agixt/Embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions agixt/Interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions agixt/Memories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
8 changes: 5 additions & 3 deletions agixt/Providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
6 changes: 3 additions & 3 deletions agixt/endpoints/Memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions agixt/extensions/stable_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
37 changes: 28 additions & 9 deletions agixt/providers/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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):
"""
Expand All @@ -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:
Expand Down
Loading