Skip to content

Commit

Permalink
Merge pull request #695 from TransformerOptimus/palm_support
Browse files Browse the repository at this point in the history
Google Palm support
  • Loading branch information
I’m authored Jul 8, 2023
2 parents 1eac05c + dce6a86 commit 6a9663b
Show file tree
Hide file tree
Showing 39 changed files with 617 additions and 156 deletions.
2 changes: 2 additions & 0 deletions config_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PINECONE_API_KEY: YOUR_PINECONE_API_KEY
PINECONE_ENVIRONMENT: YOUR_PINECONE_ENVIRONMENT

OPENAI_API_KEY: YOUR_OPEN_API_KEY
PALM_API_KEY: YOUR_PALM_API_KEY

# For locally hosted LLMs comment out the next line and uncomment the one after
# to configure a local llm point your browser to 127.0.0.1:7860 and click on the model tab in text generation web ui.
Expand All @@ -11,6 +12,7 @@ OPENAI_API_BASE: https://api.openai.com/v1

# "gpt-3.5-turbo-0301": 4032, "gpt-4-0314": 8092, "gpt-3.5-turbo": 4032, "gpt-4": 8092, "gpt-4-32k": 32768, "gpt-4-32k-0314": 32768, "llama":2048, "mpt-7b-storywriter":45000
MODEL_NAME: "gpt-3.5-turbo-0301"
# "gpt-3.5-turbo", , "gpt-4", "models/chat-bison-001"
RESOURCES_SUMMARY_MODEL_NAME: "gpt-3.5-turbo"
MAX_TOOL_TOKEN_LIMIT: 800
MAX_MODEL_TOKEN_LIMIT: 4032 # set to 2048 for llama
Expand Down
36 changes: 6 additions & 30 deletions gui/pages/Content/Agents/AgentCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ export default function AgentCreate({sendAgentData, selectedProjectId, fetchAgen
const [goals, setGoals] = useState(['Describe the agent goals here']);
const [instructions, setInstructions] = useState(['']);

const models = ['gpt-4', 'gpt-3.5-turbo','gpt-3.5-turbo-16k', 'gpt-4-32k']
const models = ['gpt-4', 'gpt-3.5-turbo','gpt-3.5-turbo-16k', 'gpt-4-32k', 'google-palm-bison-001']
const [model, setModel] = useState(models[1]);
const modelRef = useRef(null);
const [modelDropdown, setModelDropdown] = useState(false);

const agentTypes = ["Don't Maintain Task Queue", "Maintain Task Queue"]
const agentTypes = ["Don't Maintain Task Queue", "Maintain Task Queue", "Action Based"]
const [agentType, setAgentType] = useState(agentTypes[0]);
const agentRef = useRef(null);
const [agentDropdown, setAgentDropdown] = useState(false);
Expand All @@ -61,8 +61,6 @@ export default function AgentCreate({sendAgentData, selectedProjectId, fetchAgen

const [stepTime, setStepTime] = useState(500);

const rollingWindows = ["5", "10", "15", "20"]
const [rollingWindow, setRollingWindow] = useState(rollingWindows[1]);
const rollingRef = useRef(null);
const [rollingDropdown, setRollingDropdown] = useState(false);

Expand Down Expand Up @@ -128,7 +126,6 @@ export default function AgentCreate({sendAgentData, selectedProjectId, fetchAgen
setLocalStorageArray("agent_constraints_" + String(internalId), data.constraints, setConstraints);
setLocalStorageValue("agent_iterations_" + String(internalId), data.max_iterations, setIterations);
setLocalStorageValue("agent_step_time_" + String(internalId), data.iteration_interval, setStepTime);
setLocalStorageValue("agent_rolling_window_" + String(internalId), data.memory_window, setRollingWindow);
setLocalStorageValue("agent_permission_" + String(internalId), data.permission_type, setPermission);
setLocalStorageArray("agent_instructions_" + String(internalId), data.instruction, setInstructions);
setLocalStorageValue("agent_database_" + String(internalId), data.LTM_DB, setDatabase);
Expand Down Expand Up @@ -225,10 +222,6 @@ export default function AgentCreate({sendAgentData, selectedProjectId, fetchAgen
setDatabaseDropdown(false);
};

const handleWindowSelect = (index) => {
setLocalStorageValue("agent_rolling_window_" + String(internalId), rollingWindows[index], setRollingWindow);
setRollingDropdown(false);
};

const handleStepChange = (event) => {
setLocalStorageValue("agent_step_time_" + String(internalId), event.target.value, setStepTime);
Expand All @@ -246,6 +239,9 @@ export default function AgentCreate({sendAgentData, selectedProjectId, fetchAgen

const handleModelSelect = (index) => {
setLocalStorageValue("agent_model_" + String(internalId), models[index], setModel);
if (models[index] == "google-palm-bison-001") {
setAgentType("Action Based")
}
setModelDropdown(false);
};

Expand Down Expand Up @@ -333,7 +329,7 @@ export default function AgentCreate({sendAgentData, selectedProjectId, fetchAgen

const handleAddAgent = () => {
if(!hasAPIkey) {
toast.error("Your OpenAI API key is empty!", {autoClose: 1800});
toast.error("Your OpenAI/Palm API key is empty!", {autoClose: 1800});
openNewTab(-3, "Settings", "Settings");
return
}
Expand Down Expand Up @@ -382,7 +378,6 @@ export default function AgentCreate({sendAgentData, selectedProjectId, fetchAgen
"max_iterations": maxIterations,
"permission_type": permission_type,
"LTM_DB": longTermMemory ? database : null,
"memory_window": rollingWindow
};

createAgent(agentData)
Expand Down Expand Up @@ -568,10 +563,6 @@ export default function AgentCreate({sendAgentData, selectedProjectId, fetchAgen
setAgentType(agent_type);
}

const agent_rolling_window = localStorage.getItem("agent_rolling_window_" + String(internalId));
if(agent_rolling_window) {
setRollingWindow(agent_rolling_window);
}

const agent_database = localStorage.getItem("agent_database_" + String(internalId));
if(agent_database) {
Expand Down Expand Up @@ -798,21 +789,6 @@ export default function AgentCreate({sendAgentData, selectedProjectId, fetchAgen
<label className={styles.form_label}>Time between steps (in milliseconds)</label>
<input className="input_medium" type="number" value={stepTime} onChange={handleStepChange}/>
</div>
<div style={{marginTop: '15px'}}>
<label className={styles.form_label}>Short term memory - Rolling window</label>
<div className="dropdown_container_search" style={{width:'100%'}}>
<div className="custom_select_container" onClick={() => setRollingDropdown(!rollingDropdown)} style={{width:'100%'}}>
{rollingWindow} messages<Image width={20} height={21} src={!rollingDropdown ? '/images/dropdown_down.svg' : '/images/dropdown_up.svg'} alt="expand-icon"/>
</div>
<div>
{rollingDropdown && <div className="custom_select_options" ref={rollingRef} style={{width:'100%'}}>
{rollingWindows.map((window, index) => (<div key={index} className="custom_select_option" onClick={() => handleWindowSelect(index)} style={{padding:'12px 14px',maxWidth:'100%'}}>
{window}
</div>))}
</div>}
</div>
</div>
</div>
{/*<div style={{marginTop: '15px'}}>*/}
{/* <div style={{display:'flex'}}>*/}
{/* <input className="checkbox" type="checkbox" checked={longTermMemory} onChange={() => setLocalStorageValue("has_LTM_" + String(internalId), !longTermMemory, setLongTermMemory)} />*/}
Expand Down
2 changes: 1 addition & 1 deletion gui/pages/Content/Agents/AgentWorkspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export default function AgentWorkspace({agentId, selectedView}) {
<div style={{marginLeft:'7px'}}>
<button onClick={() => setLeftPanel('activity_feed')} className={styles.tab_button} style={leftPanel === 'activity_feed' ? {background:'#454254'} : {background:'transparent'}}>Activity Feed</button>
</div>
{agentDetails && agentDetails.agent_type === 'Maintain Task Queue' && <div style={{marginLeft:'7px'}}>
{agentDetails && (agentDetails.agent_type === 'Maintain Task Queue' || agentDetails.agent_type == "Action Based") && <div style={{marginLeft:'7px'}}>
<button onClick={() => setLeftPanel('agent_type')} className={styles.tab_button} style={leftPanel === 'agent_type' ? {background:'#454254'} : {background:'transparent'}}>Task Queue</button>
</div>}
</div>
Expand Down
64 changes: 56 additions & 8 deletions gui/pages/Dashboard/Settings/Settings.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React, {useState, useEffect} from 'react';
import React, {useState, useEffect, useRef} from 'react';
import {ToastContainer, toast} from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import agentStyles from "@/pages/Content/Agents/Agents.module.css";
import {getOrganisationConfig, updateOrganisationConfig} from "@/pages/api/DashboardService";
import {EventBus} from "@/utils/eventBus";
import {removeTab} from "@/utils/utils";
import {removeTab, setLocalStorageValue} from "@/utils/utils";
import Image from "next/image";

export default function Settings({organisationId}) {
const [openAIKey, setKey] = useState('');
const [modelApiKey, setKey] = useState('');
const [temperature, setTemperature] = useState(0.5);
const [sourceDropdown, setSourceDropdown] = useState(false);
const [source, setSource] = useState('OpenAi');
const sourceRef = useRef(null);
const sources = ['OpenAi', 'Google Palm']

function getKey(key) {
getOrganisationConfig(organisationId, key)
Expand All @@ -20,8 +25,30 @@ export default function Settings({organisationId}) {
});
}

function getSource(key) {
getOrganisationConfig(organisationId, key)
.then((response) => {
setSource(response.data.value);
})
.catch((error) => {
console.error('Error fetching project:', error);
});
}

useEffect(() => {
getKey("model_api_key");
getSource("model_source");

function handleClickOutside(event) {
if (sourceRef.current && !sourceRef.current.contains(event.target)) {
setSourceDropdown(false)
}
}

document.addEventListener('mousedown', handleClickOutside);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, [organisationId]);

function updateKey(key, value) {
Expand All @@ -37,21 +64,27 @@ export default function Settings({organisationId}) {
});
}

const handleOpenAIKey = (event) => {
const handleModelApiKey = (event) => {
setKey(event.target.value);
};

const handleSourceSelect = (index) => {
setSource(sources[index]);
setSourceDropdown(false);
};

const preventDefault = (e) => {
e.stopPropagation();
};

const saveSettings = () => {
if (openAIKey === null || openAIKey.replace(/\s/g, '') === '') {
if (modelApiKey === null || modelApiKey.replace(/\s/g, '') === '') {
toast.error("API key is empty", {autoClose: 1800});
return
}

updateKey("model_api_key", openAIKey);
updateKey("model_api_key", modelApiKey);
updateKey("model_source", source);
};

const handleTemperatureChange = (event) => {
Expand All @@ -66,8 +99,23 @@ export default function Settings({organisationId}) {
<div className={agentStyles.page_title}>Settings</div>
</div>
<div>
<label className={agentStyles.form_label}>Open-AI API Key</label>
<input placeholder="Enter your Open-AI API key" className="input_medium" type="password" value={openAIKey} onChange={handleOpenAIKey}/>
<label className={agentStyles.form_label}>Model Source</label>
<div className="dropdown_container_search" style={{width:'100%'}}>
<div className="custom_select_container" onClick={() => setSourceDropdown(!sourceDropdown)} style={{width:'100%'}}>
{source}<Image width={20} height={21} src={!sourceDropdown ? '/images/dropdown_down.svg' : '/images/dropdown_up.svg'} alt="expand-icon"/>
</div>
<div>
{sourceDropdown && <div className="custom_select_options" ref={sourceRef} style={{width:'100%'}}>
{sources.map((source, index) => (<div key={index} className="custom_select_option" onClick={() => handleSourceSelect(index)} style={{padding:'12px 14px',maxWidth:'100%'}}>
{source}
</div>))}
</div>}
</div>
</div>
</div><br/>
<div>
<label className={agentStyles.form_label}>Open-AI/Palm API Key</label>
<input placeholder="Enter your Open-AI/Palm API key" className="input_medium" type="password" value={modelApiKey} onChange={handleModelApiKey}/>
</div>
{/*<div style={{marginTop:'15px'}}>*/}
{/* <label className={agentStyles.form_label}>Temperature</label>*/}
Expand Down
44 changes: 44 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,49 @@ def build_task_based_agents():
workflow_step4.next_step_id = workflow_step3.id
session.commit()

def build_action_based_agents():
agent_workflow = session.query(AgentWorkflow).filter(AgentWorkflow.name == "Action Based").first()
if agent_workflow is None:
agent_workflow = AgentWorkflow(name="Action Based", description="Action Based")
session.add(agent_workflow)
session.commit()

output = AgentPromptBuilder.start_task_based()

workflow_step1 = session.query(AgentWorkflowStep).filter(AgentWorkflowStep.unique_id == "ab1").first()
if workflow_step1 is None:
workflow_step1 = AgentWorkflowStep(unique_id="ab1",
prompt=output["prompt"], variables=str(output["variables"]),
step_type="TRIGGER",
agent_workflow_id=agent_workflow.id, next_step_id=-1,
output_type="tasks")
session.add(workflow_step1)
else:
workflow_step1.prompt = output["prompt"]
workflow_step1.variables = str(output["variables"])
workflow_step1.output_type = "tasks"
session.commit()

workflow_step2 = session.query(AgentWorkflowStep).filter(AgentWorkflowStep.unique_id == "ab2").first()
output = AgentPromptBuilder.analyse_task()
if workflow_step2 is None:
workflow_step2 = AgentWorkflowStep(unique_id="ab2",
prompt=output["prompt"], variables=str(output["variables"]),
step_type="NORMAL",
agent_workflow_id=agent_workflow.id, next_step_id=-1,
output_type="tools")
session.add(workflow_step2)
else:
workflow_step2.prompt = output["prompt"]
workflow_step2.variables = str(output["variables"])
workflow_step2.output_type = "tools"
session.commit()

session.commit()
workflow_step1.next_step_id = workflow_step2.id
workflow_step2.next_step_id = workflow_step2.id
session.commit()

def check_toolkit_registration():
organizations = session.query(Organisation).all()
for organization in organizations:
Expand All @@ -270,6 +313,7 @@ def check_toolkit_registration():

build_single_step_agent()
build_task_based_agents()
build_action_based_agents()
if env != "PROD":
check_toolkit_registration()
session.close()
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,5 @@ pypdf==3.11.0
python-pptx==0.6.21
Pillow==9.5.0
EbookLib==0.18
html2text==2020.1.16
html2text==2020.1.16
google-generativeai==0.1.0
7 changes: 3 additions & 4 deletions superagi/agent/agent_prompt_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def add_tools_to_prompt(cls, tools: List[BaseTool], add_finish: bool = True) ->
'people know you have finished your objectives"'
)
finish_string = (
f"{len(tools) + 1}. {FINISH_NAME}: "
f"{len(tools) + 1}. \"{FINISH_NAME}\": "
f"{finish_description}, args: {finish_args}"
)
if add_finish:
Expand Down Expand Up @@ -63,13 +63,12 @@ def get_super_agi_single_prompt(cls):
response_format = {
"thoughts": {
"text": "thought",
"reasoning": "reasoning",
"reasoning": "short reasoning",
"plan": "- short bulleted\n- list that conveys\n- long-term plan",
"criticism": "constructive self-criticism",
"speak": "thoughts summary to say to user",
},
"tool": {"name": "tool name/task name", "description": "tool or task description",
"args": {"arg name": "value"}}
"tool": {"name": "tool name/task name", "args": {"arg name": "arg value(escape in case of string)"}}
}
formatted_response_format = json.dumps(response_format, indent=4)

Expand Down
4 changes: 3 additions & 1 deletion superagi/agent/output_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def parse(self, text: str) -> AgentGPTAction:
class AgentOutputParser(BaseOutputParser):
def parse(self, text: str) -> AgentGPTAction:
try:
# logger.info(text)
logger.info(text)
text = JsonCleaner.check_and_clean_json(text)
parsed = json5.loads(text)
except json.JSONDecodeError:
Expand Down Expand Up @@ -55,6 +55,8 @@ def parse(self, text: str) -> AgentGPTAction:

logger.info(format_prefix_green + "Action : " + format_suffix_green)
# print(format_prefix_yellow + "Args: "+ format_suffix_yellow + parsed["tool"]["args"] + "\n")
if "tool" not in parsed:
raise Exception("No tool found in the response..")
if parsed["tool"] is None or not parsed["tool"]:
return AgentGPTAction(name="", args="")
if "name" in parsed["tool"]:
Expand Down
4 changes: 2 additions & 2 deletions superagi/agent/prompts/analyse_task.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ TOOLS:
RESPONSE FORMAT:
{
"thoughts": {
"reasoning": "reasoning"
"reasoning": "short reasoning"
},
"tool": {"name": "tool name", "args": {"arg name": "string value"}}
"tool": {"name": "tool name", "args": {"arg name": "arg value(escape in case of string)"}}
}

Your answer must be something that JSON.parse() can read, and nothing else.
2 changes: 1 addition & 1 deletion superagi/agent/prompts/initialize_tasks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GOALS:

{task_instructions}

Construct a sequence of actions, not exceeding 3 steps, to achieve this goal.
Construct a sequence of actions, not exceeding 4 steps, to achieve this goal.

Submit your response as a formatted ARRAY of strings, suitable for utilization with JSON.parse().

Expand Down
8 changes: 4 additions & 4 deletions superagi/agent/prompts/superagi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ TOOLS:
PERFORMANCE EVALUATION:
1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.
2. Use instruction to decide the flow of execution and decide the next steps for achieving the task.
2. Constructively self-criticize your big-picture behavior constantly.
3. Reflect on past decisions and strategies to refine your approach.
4. Every tool has a cost, so be smart and efficient.
5. Aim to complete tasks in the least number of steps.
3. Constructively self-criticize your big-picture behavior constantly.
4. Reflect on past decisions and strategies to refine your approach.
5. Every tool has a cost, so be smart and efficient.

I should only respond in JSON format as described below.
Response Format:
{response_format}


Ensure the response can be parsed by Python json.loads.
Loading

0 comments on commit 6a9663b

Please sign in to comment.