Skip to content

Commit

Permalink
Merge pull request #5 from brighthive/feat-customtools
Browse files Browse the repository at this point in the history
Feat customtools
  • Loading branch information
matthewgee authored Aug 6, 2024
2 parents 3b6472c + 03e9b05 commit 7b82c9a
Show file tree
Hide file tree
Showing 18 changed files with 4,003 additions and 1,495 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
postgres-volume/
redis-volume/
backend/ui
tests/notebooks

# Operating System generated files
.DS_Store
Expand Down
8 changes: 8 additions & 0 deletions backend/app/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
RETRIEVAL_DESCRIPTION,
TOOLS,
ActionServer,
AdeptID,
Arxiv,
AvailableTools,
Connery,
Expand All @@ -42,10 +43,14 @@
YouSearch,
get_retrieval_tool,
get_retriever,
Skillup,
Skillup_Jobs,
Skillup_Training
)

Tool = Union[
ActionServer,
AdeptID,
Connery,
DDGSearch,
Arxiv,
Expand All @@ -57,6 +62,9 @@
Tavily,
TavilyAnswer,
Retrieval,
Skillup,
Skillup_Jobs,
Skillup_Training,
DallE,
]

Expand Down
51 changes: 50 additions & 1 deletion backend/app/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class AvailableTools(str, Enum):
WIKIPEDIA = "wikipedia"
DALL_E = "dall_e"
ADEPTID = "adeptid"
SKILLUP = "skillup"
SKILLUP_TRAINING = "skillup_training"
SKILLUP_JOBS = "skillup_jobs"


class ToolConfig(TypedDict):
Expand Down Expand Up @@ -102,7 +105,7 @@ class AdeptID(BaseTool):
name: str = Field("AdeptID API", const=True)
description: str = Field(
(
"Get personalized career paths and job recommendations from"
"Get personalized career paths and job recommendations from "
"[AdeptID](https://adeptid.com)"
),
const=True
Expand Down Expand Up @@ -180,6 +183,36 @@ class Wikipedia(BaseTool):
)


class Skillup(BaseTool):
type: AvailableTools = Field(AvailableTools.SKILLUP, const=True)
name: str = Field("Skillup", const=True)
description: str = Field(
(
"Searches [Skillup](https://www.skillup.com/)."
"This is a tool for skillup training opportunities and jobs"
),
const=True)

class Skillup_Training(BaseTool):
type: AvailableTools = Field(AvailableTools.SKILLUP_TRAINING, const=True)
name: str = Field("Skillup Training", const=True)
description: str = Field(
(
"Searches [Skillup](https://www.skillup.com/)."
"This is a tool for skillup training opportunities"
),
const=True)

class Skillup_Jobs(BaseTool):
type: AvailableTools = Field(AvailableTools.SKILLUP_JOBS, const=True)
name: str = Field("Skillup Jobs", const=True)
description: str = Field(
(
"Searches [Skillup](https://www.skillup.com/)."
"This is a tool for skillup jobs"
),
const=True)

class Tavily(BaseTool):
type: AvailableTools = Field(AvailableTools.TAVILY, const=True)
name: str = Field("Search (Tavily)", const=True)
Expand Down Expand Up @@ -257,6 +290,10 @@ def _get_you_search():
"Searches for documents using You.com",
)

#add retriever tool for skillup training

#add retriever tool for skillup jobs


@lru_cache(maxsize=1)
def _get_sec_filings():
Expand Down Expand Up @@ -334,6 +371,16 @@ def _get_adeptID_tools(**kwargs: ActionServerConfig):
tools = toolkit.get_tools()
return tools

def _get_skillup_training():
return create_retriever_tool(
WikipediaRetriever(), "wikipedia", "Search for training and jobs on Wikipedia"
)

def _get_skillup_jobs():
return create_retriever_tool(
WikipediaRetriever(), "wikipedia", "Search for training and jobs on Wikipedia"
)

TOOLS = {
AvailableTools.ACTION_SERVER: _get_action_server,
AvailableTools.CONNERY: _get_connery_actions,
Expand All @@ -348,4 +395,6 @@ def _get_adeptID_tools(**kwargs: ActionServerConfig):
AvailableTools.TAVILY_ANSWER: _get_tavily_answer,
AvailableTools.DALL_E: _get_dalle_tools,
AvailableTools.ADEPTID: _get_adeptID_tools,
AvailableTools.SKILLUP_TRAINING: _get_skillup_training,
AvailableTools.SKILLUP_JOBS: _get_skillup_jobs,
}
67 changes: 62 additions & 5 deletions backend/custom_tools/adeptid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from typing import List
import os

ADEPT_ID_API_KEY = os.getenv("ADEPTID_API_KEY")

# Define the input schema for the tool
class WorkHistory(BaseModel):
title: str
Expand All @@ -26,21 +28,75 @@ class Candidate(BaseModel):
education: List[Education]
skills: List[str]

class AdeptIDJobRecommendationInput(BaseModel):
class AdeptIDSkillSearchInput(BaseModel):
skills: List[str]
result_count: int = 1
offset: int = 1

class AdeptIDDestionationOccupationRecommendationInput(BaseModel):
candidates: List[Candidate]
limit: int = 10
offset: int = 1
skill_count: int = 5

class AdeptIDJobRecommendationInput(BaseModel):
skill_count: int = 0
destination_jobs: List[str]
limit: int = 1000
offset: int = 0

class AdeptIDSkillSearch(BaseTool):
name = "AdeptIDSkillSearch"
description = "Searches for skills and returns the top results."

input = AdeptIDSkillSearchInput

def _run(self, input: AdeptIDSkillSearchInput):
url = "https://api.adept-id.com/v2/skill"
api_key = os.getenv("ADEPTID_API_KEY")
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}" # Replace with your actual API key
}
payload = input.json()
#TODO: check whether this is GET or POST
response = requests.post(url, headers=headers, data=payload)

if response.status_code == 200:
return response.json()
else:
return {"error": response.json()}

class AdeptIDDestinationOccupationRecommendation(BaseTool):
name = "AdeptIDDestinationOccupationRecommendation"
description = "Recommends occupations and career paths to a candidate based on their skills and interests."

input = AdeptIDDestionationOccupationRecommendationInput

def _run(self, input: AdeptIDJobRecommendationInput):
url = "https://api.adept-id.com/v2/recommend-destination-occupation"
api_key = os.getenv("ADEPTID_API_KEY")
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}" # Replace with your actual API key
}
payload = input.json()

response = requests.post(url, headers=headers, data=payload)

if response.status_code == 200:
return response.json()
else:
return {"error": response.json()}

# Define the tool class
class AdeptIDJobRecommendation(BaseTool):
name = "AdeptIDJobRecommendation"
description = "Recommends next step career opportunities for a specific candidate."
description = "Recommends specific jobs for a candidate based on their destination occupation and skills."

input_model = AdeptIDJobRecommendationInput
input = AdeptIDJobRecommendationInput

def _run(self, input: AdeptIDJobRecommendationInput):
url = "https://api.adept-id.com/v2/recommend-destination-occupation"
url = "https://api.adept-id.com/v2/evaluate-jobs"
api_key = os.getenv("ADEPTID_API_KEY")
headers = {
"Content-Type": "application/json",
Expand Down Expand Up @@ -84,5 +140,6 @@ def _run(self, input: AdeptIDJobRecommendationInput):
skill_count=5
)


result = tool.run(input_data)
print(result)
Empty file added backend/custom_tools/skillup.py
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DROP TABLE IF EXISTS thread;
DROP TABLE IF EXISTS assistant;
DROP TABLE IF EXISTS checkpoints;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE EXTENSION IF NOT EXISTS vector;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TABLE IF NOT EXISTS assistant (
assistant_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
user_id VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
config JSON NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC'),
public BOOLEAN NOT NULL
);

CREATE TABLE IF NOT EXISTS thread (
thread_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
assistant_id UUID REFERENCES assistant(assistant_id) ON DELETE SET NULL,
user_id VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')
);

CREATE TABLE IF NOT EXISTS checkpoints (
thread_id TEXT PRIMARY KEY,
checkpoint BYTEA
);
5 changes: 5 additions & 0 deletions backend/migrations/000002_checkpoints_update_schema.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE checkpoints
DROP CONSTRAINT IF EXISTS checkpoints_pkey,
ADD PRIMARY KEY (thread_id),
DROP COLUMN IF EXISTS thread_ts,
DROP COLUMN IF EXISTS parent_ts;
11 changes: 11 additions & 0 deletions backend/migrations/000002_checkpoints_update_schema.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ALTER TABLE checkpoints
ADD COLUMN IF NOT EXISTS thread_ts TIMESTAMPTZ,
ADD COLUMN IF NOT EXISTS parent_ts TIMESTAMPTZ;

UPDATE checkpoints
SET thread_ts = CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
WHERE thread_ts IS NULL;

ALTER TABLE checkpoints
DROP CONSTRAINT IF EXISTS checkpoints_pkey,
ADD PRIMARY KEY (thread_id, thread_ts)
9 changes: 9 additions & 0 deletions backend/migrations/000003_create_user.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ALTER TABLE assistant
DROP CONSTRAINT fk_assistant_user_id,
ALTER COLUMN user_id TYPE VARCHAR USING (user_id::text);

ALTER TABLE thread
DROP CONSTRAINT fk_thread_user_id,
ALTER COLUMN user_id TYPE VARCHAR USING (user_id::text);

DROP TABLE IF EXISTS "user";
25 changes: 25 additions & 0 deletions backend/migrations/000003_create_user.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CREATE TABLE IF NOT EXISTS "user" (
user_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
sub VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')
);

INSERT INTO "user" (user_id, sub)
SELECT DISTINCT user_id::uuid, user_id
FROM assistant
WHERE user_id IS NOT NULL
ON CONFLICT (user_id) DO NOTHING;

INSERT INTO "user" (user_id, sub)
SELECT DISTINCT user_id::uuid, user_id
FROM thread
WHERE user_id IS NOT NULL
ON CONFLICT (user_id) DO NOTHING;

ALTER TABLE assistant
ALTER COLUMN user_id TYPE UUID USING (user_id::UUID),
ADD CONSTRAINT fk_assistant_user_id FOREIGN KEY (user_id) REFERENCES "user"(user_id);

ALTER TABLE thread
ALTER COLUMN user_id TYPE UUID USING (user_id::UUID),
ADD CONSTRAINT fk_thread_user_id FOREIGN KEY (user_id) REFERENCES "user"(user_id);
2 changes: 2 additions & 0 deletions backend/migrations/000004_add_metadata_to_thread.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE thread
DROP COLUMN metadata;
9 changes: 9 additions & 0 deletions backend/migrations/000004_add_metadata_to_thread.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ALTER TABLE thread
ADD COLUMN metadata JSONB;

UPDATE thread
SET metadata = json_build_object(
'assistant_type', (SELECT config->'configurable'->>'type'
FROM assistant
WHERE assistant.assistant_id = thread.assistant_id)
);
Loading

0 comments on commit 7b82c9a

Please sign in to comment.