Skip to content

Commit

Permalink
Adds XAI/Grok support to Gradio Chat Test app
Browse files Browse the repository at this point in the history
  • Loading branch information
Clay-Ferguson committed Nov 17, 2024
1 parent bb556ec commit 4498080
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions QuantaGradio/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ def init_config():
p.add_argument("--openai_api_key", required=True, help="API key for OpenAI")
p.add_argument("--anth_api_key", required=True, help="API key for Anthropic")
p.add_argument("--gemini_api_key", required=True, help="API key for Gemini")
p.add_argument("--xai_api_key", required=True, help="API key for XAI")

p.add_argument("--openai_model", required=True, help="OpenAI model name")
p.add_argument("--anth_model", required=True, help="Anthropic model name")
p.add_argument("--gemini_model", required=True, help="Anthropic model name")
p.add_argument("--xai_model", required=True, help="XAi model name")

p.add_argument("--ai_service", required=True, help="AI Service")
p.add_argument("--folders_to_include", required=True, help="Folders to Include")
Expand Down
7 changes: 6 additions & 1 deletion QuantaGradio/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
openai_api_key: "your-api-key"
openai_model: "gpt-4o"

# XAI
xai_api_key: "your-api-key"
xai_model: "grok-beta"

# Anthropic
anth_api_key: "your-api-key"
anth_model: "claude-3-opus-20240229"
Expand All @@ -19,7 +23,8 @@ mode: "none"
# OPENAI = "openai"
# ANTHROPIC = "anth"
# GEMINI = "gemini"
ai_service: "openai"
# XAI = "xai"
ai_service: "xai"

scan_extensions: "py,html"
data_folder: "/home/clay/ai-agent-temp"
Expand Down
10 changes: 6 additions & 4 deletions QuantaGradio/install_modules.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/bash

# TO Reinstall the Conda Environment from scratch run these commands before first...
# TO Reinstall the Conda Environment from scratch run these commands...
# conda deactivate
# conda remove --name quanta_agent --all
# conda create --name quanta_agent python=3.12.3
# conda activate quanta_agent
# conda remove --name quanta_gradio --all
# conda create --name quanta_gradio python=3.12.3
# conda activate quanta_gradio
# ./install_modules.sh

source ./conda_init.sh

Expand All @@ -24,6 +25,7 @@ if [[ "$CONDA_DEFAULT_ENV" == "quanta_gradio" ]]; then
langchain-anthropic \
langchain_google_genai \
langchain-openai \
langchain-xai \
langchain-community \
langchain-core \
langchain-text-splitters \
Expand Down
2 changes: 1 addition & 1 deletion QuantaGradio/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export PATH="$conda_path/bin:$PATH"
source $conda_path/bin/activate quanta_gradio

if [[ "$CONDA_DEFAULT_ENV" == "quanta_gradio" ]]; then
python3 Quanta_Gradio_Agent.py
python3 Quanta_Gradio_ChatTest.py
else
echo "Failed to set Conda Environment: Expected quanta_gradio but found $CONDA_DEFAULT_ENV"
sleep 10s
Expand Down
8 changes: 8 additions & 0 deletions common/python/agent/ai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from langchain.chat_models.base import BaseChatModel
from langchain_openai import ChatOpenAI
from langchain_anthropic import ChatAnthropic
from langchain_xai import ChatXAI
from langchain_google_genai import ChatGoogleGenerativeAI
from QuantaAgent.app_config import AppConfig
from common.python.agent.app_agent import QuantaAgent
Expand Down Expand Up @@ -76,6 +77,13 @@ def create_llm(
api_key=cfg.gemini_api_key,
timeout=timeout
)
elif cfg.ai_service == AIService.XAI.value:
llm = ChatXAI(
model=cfg.xai_model,
temperature=temperature,
api_key=cfg.xai_api_key,
timeout=timeout
)
else:
raise Exception(f"Invalid AI Service: {cfg.ai_service}")
return llm
4 changes: 2 additions & 2 deletions common/python/agent/app_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from gradio import ChatMessage
from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder
from langchain.schema import HumanMessage, SystemMessage, AIMessage, BaseMessage
from langchain.agents import AgentExecutor, create_openai_tools_agent, load_tools
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain.chat_models.base import BaseChatModel
from langgraph.prebuilt import chat_agent_executor
from ..utils import RefactorMode, Utils
from ..utils import RefactorMode
from .refactoring_tools import (
UpdateBlockTool,
CreateFileTool,
Expand Down
1 change: 1 addition & 0 deletions common/python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AIService(Enum):
OPENAI = "openai"
ANTHROPIC = "anth"
GEMINI = "gemini"
XAI = "xai"

class RefactorMode(Enum):
REFACTOR = "refactor"
Expand Down

0 comments on commit 4498080

Please sign in to comment.