Skip to content

Commit

Permalink
Create trained AGiXT agent on user registration (#1247)
Browse files Browse the repository at this point in the history
* Create trained AGiXT agent on user registration

* Add env var

* improved logic

* Update docs

* add flag

* fix token

* fix otp ref

* fix uri ref
  • Loading branch information
Josh-XT authored Sep 11, 2024
1 parent eaf563c commit c57daa0
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 26 deletions.
42 changes: 38 additions & 4 deletions agixt/Globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def getenv(var_name: str):
"DISABLED_PROVIDERS": "",
"REGISTRATION_DISABLED": "false",
"AUTH_PROVIDER": "",
"CREATE_AGENT_ON_REGISTER": "true",
"CREATE_AGIXT_AGENT": "true",
}
default_value = default_values[var_name] if var_name in default_values else ""
return os.getenv(var_name, default_value)
Expand Down Expand Up @@ -68,7 +70,7 @@ def get_default_agent_settings():
"AI_TOP_P": "1",
"MAX_TOKENS": "4096",
"helper_agent_name": "gpt4free",
"analyze_user_input": False,
"analyze_user_input": True,
"websearch": False,
"websearch_depth": 2,
"WEBSEARCH_TIMEOUT": 0,
Expand All @@ -79,6 +81,15 @@ def get_default_agent_settings():
"persona": "",
}
else:
max_tokens = int(getenv("LLM_MAX_TOKENS"))
if max_tokens == 0:
max_tokens = 16384
if max_tokens > 16384:
context_results = 20
else:
context_results = 10
if max_tokens > 32000:
context_results = 50
agent_settings = {
"provider": "ezlocalai",
"tts_provider": "ezlocalai",
Expand All @@ -96,21 +107,44 @@ def get_default_agent_settings():
"AI_TOP_P": 0.95,
"VOICE": "Morgan_Freeman",
"mode": "prompt",
"prompt_name": "Chat with Commands",
"prompt_name": "Chat",
"prompt_category": "Default",
"helper_agent_name": "gpt4free",
"analyze_user_input": False,
"analyze_user_input": True,
"websearch": False,
"websearch_depth": 2,
"WEBSEARCH_TIMEOUT": 0,
"WAIT_BETWEEN_REQUESTS": 1,
"WAIT_AFTER_FAILURE": 3,
"context_results": 10,
"context_results": context_results,
"conversation_results": 6,
"persona": "",
}
return agent_settings


def get_default_agent():
if os.path.exists("default_agent.json"):
with open("default_agent.json", "r") as f:
agent_config = json.load(f)
agent_settings = get_default_agent_settings()
agent_commands = (
agent_config["commands"] if "commands" in agent_config else {}
)
training_urls = (
agent_config["training_urls"] if "training_urls" in agent_config else []
)
return {
"settings": agent_settings,
"commands": agent_commands,
"training_urls": training_urls,
}
return {
"settings": get_default_agent_settings(),
"commands": {},
"training_urls": [],
}


DEFAULT_USER = str(getenv("DEFAULT_USER")).lower()
DEFAULT_SETTINGS = get_default_agent_settings()
55 changes: 53 additions & 2 deletions agixt/MagicalAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
)
from OAuth2Providers import get_sso_provider
from Models import UserInfo, Register, Login
from agixtsdk import AGiXTSDK
from fastapi import Header, HTTPException
from Globals import getenv
from Globals import getenv, get_default_agent
from datetime import datetime, timedelta
from fastapi import HTTPException
from sendgrid import SendGridAPIClient
Expand Down Expand Up @@ -472,7 +473,57 @@ def register(
)
except Exception as e:
pass
# Return mfa_token for QR code generation
# After registering the user, add a default AGiXT agent for the user
# Train the agent on the AGiXT documentation.
create_agent = str(getenv("CREATE_AGENT_ON_REGISTER")).lower() == "true"
if create_agent:
agixt = AGiXTSDK(base_uri=getenv("AGIXT_URI"))
otp = pyotp.TOTP(mfa_token)
agixt.login(email=new_user.email, otp=otp.now())
create_agixt_agent = str(getenv("CREATE_AGIXT_AGENT")).lower() == "true"
agent_name = getenv("AGIXT_AGENT")
agent_config = get_default_agent()
agent_settings = agent_config["settings"]
agent_commands = agent_config["commands"]
training_urls = agent_config["training_urls"]
if agent_name == "AGiXT" and create_agixt_agent:
training_urls = [
"https://josh-xt.github.io/AGiXT/",
"https://josh-xt.github.io/AGiXT/1-Getting%20started/3-Examples.html",
"https://josh-xt.github.io/AGiXT/2-Concepts/0-Core%20Concepts.html",
"https://josh-xt.github.io/AGiXT/2-Concepts/01-Processes%20and%20Frameworks.html",
"https://josh-xt.github.io/AGiXT/2-Concepts/02-Providers.html",
"https://josh-xt.github.io/AGiXT/2-Concepts/03-Agents.html",
"https://josh-xt.github.io/AGiXT/2-Concepts/04-Chat%20Completions.html",
"https://josh-xt.github.io/AGiXT/2-Concepts/05-Extension%20Commands.html",
"https://josh-xt.github.io/AGiXT/2-Concepts/06-Prompts.html",
"https://josh-xt.github.io/AGiXT/2-Concepts/07-Chains.html",
"https://josh-xt.github.io/AGiXT/2-Concepts/07-Conversations.html",
"https://josh-xt.github.io/AGiXT/2-Concepts/09-Agent%20Training.html",
"https://josh-xt.github.io/AGiXT/2-Concepts/10-Agent%20Interactions.html",
"https://josh-xt.github.io/AGiXT/3-Providers/0-ezLocalai.html",
"https://josh-xt.github.io/AGiXT/3-Providers/1-Anthropic%20Claude.html",
"https://josh-xt.github.io/AGiXT/3-Providers/2-Azure%20OpenAI.html",
"https://josh-xt.github.io/AGiXT/3-Providers/3-Google.html",
"https://josh-xt.github.io/AGiXT/3-Providers/4-GPT4Free.html",
"https://josh-xt.github.io/AGiXT/3-Providers/5-Hugging%20Face.html",
"https://josh-xt.github.io/AGiXT/3-Providers/6-OpenAI.html",
"https://josh-xt.github.io/AGiXT/4-Authentication/microsoft.html",
"https://josh-xt.github.io/AGiXT/4-Authentication/google.html",
]
agixt.add_agent(
agent_name=agent_name,
settings=agent_settings,
commands=agent_commands,
training_urls=training_urls,
)
if create_agixt_agent and agent_name != "AGiXT":
agixt.add_agent(
agent_name="AGiXT",
settings=agent_settings,
commands=agent_commands,
training_urls=training_urls,
)
return mfa_token

def update_user(self, **kwargs):
Expand Down
42 changes: 22 additions & 20 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,28 @@ The script supports setting any of the environment variables via command-line ar
18. `--streamlit-app-uri`: Set the Streamlit app URI (default: `http://localhost:8501`)
19. `--auth-web`: Set the authentication web URI (default: `http://localhost:3437/user`)
20. `--auth-provider`: Set the authentication provider (options: `none`, `magicalauth`)
21. `--disabled-providers`: Set disabled providers (comma-separated list)
22. `--disabled-extensions`: Set disabled extensions (comma-separated list)
23. `--working-directory`: Set the working directory (default: `./WORKSPACE`)
24. `--github-client-id`: Set GitHub client ID for authentication
25. `--github-client-secret`: Set GitHub client secret for authentication
26. `--google-client-id`: Set Google client ID for authentication
27. `--google-client-secret`: Set Google client secret for authentication
28. `--microsoft-client-id`: Set Microsoft client ID for authentication
29. `--microsoft-client-secret`: Set Microsoft client secret for authentication
30. `--tz`: Set the timezone (default: system timezone)
31. `--interactive-mode`: Set the interactive mode (default: `chat`)
32. `--theme-name`: Set the UI theme (options: `default`, `christmas`, `conspiracy`, `doom`, `easter`, `halloween`, `valentines`)
33. `--allow-email-sign-in`: Allow email sign-in (default: `true`)
34. `--database-type`: Set the database type (options: `sqlite`, `postgres`)
35. `--database-name`: Set the database name (default: `models/agixt`)
36. `--log-level`: Set the logging level (default: `INFO`)
37. `--log-format`: Set the log format (default: `%(asctime)s | %(levelname)s | %(message)s`)
38. `--uvicorn-workers`: Set the number of Uvicorn workers (default: `10`)
39. `--agixt-auto-update`: Enable or disable auto-updates (default: `true`)
40. `--with-streamlit`: Enable or disable the Streamlit UI (default: `true`)
21. `--create-agent-on-register`: Create an agent named from your `AGIXT_AGENT` environment variable if it is different than `AGiXT` using settings from `default_agent.json` if defined (default: `true`)
22. `--create-agixt-agent`: Create an agent called `AGiXT` and trains it on the AGiXT documentation upon user registration (default: `true`)
23. `--disabled-providers`: Set disabled providers (comma-separated list)
24. `--disabled-extensions`: Set disabled extensions (comma-separated list)
25. `--working-directory`: Set the working directory (default: `./WORKSPACE`)
26. `--github-client-id`: Set GitHub client ID for authentication
27. `--github-client-secret`: Set GitHub client secret for authentication
28. `--google-client-id`: Set Google client ID for authentication
29. `--google-client-secret`: Set Google client secret for authentication
30. `--microsoft-client-id`: Set Microsoft client ID for authentication
31. `--microsoft-client-secret`: Set Microsoft client secret for authentication
32. `--tz`: Set the timezone (default: system timezone)
33. `--interactive-mode`: Set the interactive mode (default: `chat`)
34. `--theme-name`: Set the UI theme (options: `default`, `christmas`, `conspiracy`, `doom`, `easter`, `halloween`, `valentines`)
35. `--allow-email-sign-in`: Allow email sign-in (default: `true`)
36. `--database-type`: Set the database type (options: `sqlite`, `postgres`)
37. `--database-name`: Set the database name (default: `models/agixt`)
38. `--log-level`: Set the logging level (default: `INFO`)
39. `--log-format`: Set the log format (default: `%(asctime)s | %(levelname)s | %(message)s`)
40. `--uvicorn-workers`: Set the number of Uvicorn workers (default: `10`)
41. `--agixt-auto-update`: Enable or disable auto-updates (default: `true`)
42. `--with-streamlit`: Enable or disable the Streamlit UI (default: `true`)

Options specific to ezLocalai:

Expand Down
2 changes: 2 additions & 0 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def get_default_env_vars():
"STREAMLIT_APP_URI": "http://localhost:8501",
"AUTH_WEB": "http://localhost:3437/user",
"AUTH_PROVIDER": "magicalauth",
"CREATE_AGENT_ON_REGISTER": "true",
"CREATE_AGIXT_AGENT": "true",
"DISABLED_PROVIDERS": "",
"DISABLED_EXTENSIONS": "",
"WORKING_DIRECTORY": workspace_folder.replace("\\", "/"),
Expand Down

0 comments on commit c57daa0

Please sign in to comment.