Skip to content

Commit

Permalink
Committing changes for RNA-Seq Workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
minump committed Nov 21, 2023
1 parent 4970f54 commit ca7922d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
58 changes: 57 additions & 1 deletion ai_ta_backend/agents/ml4bio_agent.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import getpass
import os
import platform
from typing import List

from langchain import hub
from langchain.chat_models import AzureChatOpenAI, ChatOpenAI
from langchain.agents import AgentType, initialize_agent
from langchain.schema.language_model import BaseLanguageModel
from langchain_experimental.plan_and_execute import (PlanAndExecute,
load_agent_executor,
load_chat_planner)
from langchain.agents.agent import AgentExecutor
from langchain.agents.structured_chat.base import StructuredChatAgent
from langchain.schema.language_model import BaseLanguageModel
from langchain.tools import BaseTool

from langchain_experimental.plan_and_execute.executors.base import ChainExecutor

HUMAN_MESSAGE_TEMPLATE = """Previous steps: {previous_steps}
Current objective: {current_step}
{agent_scratchpad}"""

TASK_PREFIX = """{objective}
"""

from .tools import get_tools
from .utils import fancier_trim_intermediate_steps
Expand Down Expand Up @@ -47,6 +65,44 @@ def run(self, input):
print(f"Result: {result}")
return result

def custom_load_agent_executor(self,
llm: BaseLanguageModel,
tools: List[BaseTool],
verbose: bool = False,
callbacks: List = [],
include_task_in_prompt: bool = False,
**kwargs
) -> ChainExecutor:
"""
Load an agent executor.
Args:
llm: BaseLanguageModel
tools: List[BaseTool]
verbose: bool. Defaults to False.
include_task_in_prompt: bool. Defaults to False.
Returns:
ChainExecutor
"""
input_variables = ["previous_steps", "current_step", "agent_scratchpad"]
template = HUMAN_MESSAGE_TEMPLATE

if include_task_in_prompt:
input_variables.append("objective")
template = TASK_PREFIX + template

agent = StructuredChatAgent.from_llm_and_tools(
llm,
tools,
human_message_template=template,
input_variables=input_variables,
)
agent_executor = AgentExecutor.from_agent_and_tools(
agent=agent, tools=tools, verbose=verbose, callbacks=callbacks, **kwargs
)
return ChainExecutor(chain=agent_executor)

def make_agent(self):
# TOOLS
tools = get_tools()
Expand All @@ -56,7 +112,7 @@ def make_agent(self):

# EXECUTOR
# executor = load_agent_executor(self.llm, tools, verbose=True, trim_intermediate_steps=fancier_trim_intermediate_steps, handle_parsing_errors=True)
executor = load_agent_executor(self.llm, tools, verbose=True, handle_parsing_errors=True)
executor = self.custom_load_agent_executor(self.llm, tools, verbose=True, callbacks=[self.callback_handler], handle_parsing_errors=True)

# Create PlanAndExecute Agent
workflow_agent = PlanAndExecute(planner=planner, executor=executor, verbose=True, callbacks=[self.callback_handler])
Expand Down
8 changes: 8 additions & 0 deletions payload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{\rtf1\ansi\ansicpg1252\cocoartf2758
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}
\margl1440\margr1440\vieww11520\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0

\f0\fs24 \cf0 \{'action': 'edited', 'issue': \{'url': 'https://api.github.com/repos/KastanDay/ML4Bio/issues/21', 'repository_url': 'https://api.github.com/repos/KastanDay/ML4Bio', 'labels_url': 'https://api.github.com/repos/KastanDay/ML4Bio/issues/21/labels\{/name\}', 'comments_url': 'https://api.github.com/repos/KastanDay/ML4Bio/issues/21/comments', 'events_url': 'https://api.github.com/repos/KastanDay/ML4Bio/issues/21/events', 'html_url': 'https://github.com/KastanDay/ML4Bio/issues/21', 'id': 2002492126, 'node_id': 'I_kwDOKeJwLc53W5re', 'number': 21, 'title': 'Create a full command line executable workflow for RNA-Seq on PBMC Samples. Open a PR on different branch once done.', 'user': \{'login': 'minump', 'id': 22112888, 'node_id': 'MDQ6VXNlcjIyMTEyODg4', 'avatar_url': 'https://avatars.githubusercontent.com/u/22112888?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/minump', 'html_url': 'https://github.com/minump', 'followers_url': 'https://api.github.com/users/minump/followers', 'following_url': 'https://api.github.com/users/minump/following\{/other_user\}', 'gists_url': 'https://api.github.com/users/minump/gists\{/gist_id\}', 'starred_url': 'https://api.github.com/users/minump/starred\{/owner\}\{/repo\}', 'subscriptions_url': 'https://api.github.com/users/minump/subscriptions', 'organizations_url': 'https://api.github.com/users/minump/orgs', 'repos_url': 'https://api.github.com/users/minump/repos', 'events_url': 'https://api.github.com/users/minump/events\{/privacy\}', 'received_events_url': 'https://api.github.com/users/minump/received_events', 'type': 'User', 'site_admin': False\}, 'labels': [], 'state': 'open', 'locked': False, 'assignee': None, 'assignees': [], 'milestone': None, 'comments': 42, 'created_at': '2023-11-20T15:46:52Z', 'updated_at': '2023-11-21T19:34:30Z', 'closed_at': None, 'author_association': 'NONE', 'active_lock_reason': None, 'body': None, 'reactions': \{'url': 'https://api.github.com/repos/KastanDay/ML4Bio/issues/21/reactions', 'total_count': 0, '+1': 0, '-1': 0, 'laugh': 0, 'hooray': 0, 'confused': 0, 'heart': 0, 'rocket': 0, 'eyes': 0\}, 'timeline_url': 'https://api.github.com/repos/KastanDay/ML4Bio/issues/21/timeline', 'performed_via_github_app': None, 'state_reason': None\}, 'changes': \{'title': \{'from': 'Create a full command line executable workflow for RNA-Seq on PBMC Samples. Open a PR on different branch once done'\}\}, 'repository': \{'id': 702705709, 'node_id': 'R_kgDOKeJwLQ', 'name': 'ML4Bio', 'full_name': 'KastanDay/ML4Bio', 'private': False, 'owner': \{'login': 'KastanDay', 'id': 13607221, 'node_id': 'MDQ6VXNlcjEzNjA3MjIx', 'avatar_url': 'https://avatars.githubusercontent.com/u/13607221?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/KastanDay', 'html_url': 'https://github.com/KastanDay', 'followers_url': 'https://api.github.com/users/KastanDay/followers', 'following_url': 'https://api.github.com/users/KastanDay/following\{/other_user\}', 'gists_url': 'https://api.github.com/users/KastanDay/gists\{/gist_id\}', 'starred_url': 'https://api.github.com/users/KastanDay/starred\{/owner\}\{/repo\}', 'subscriptions_url': 'https://api.github.com/users/KastanDay/subscriptions', 'organizations_url': 'https://api.github.com/users/KastanDay/orgs', 'repos_url': 'https://api.github.com/users/KastanDay/repos', 'events_url': 'https://api.github.com/users/KastanDay/events\{/privacy\}', 'received_events_url': 'https://api.github.com/users/KastanDay/received_events', 'type': 'User', 'site_admin': False\}, 'html_url': 'https://github.com/KastanDay/ML4Bio', 'description': 'LLMs to execute Bioinformatics workflows, esp. RNA-seq', 'fork': False, 'url': 'https://api.github.com/repos/KastanDay/ML4Bio', 'forks_url': 'https://api.github.com/repos/KastanDay/ML4Bio/forks', 'keys_url': 'https://api.github.com/repos/KastanDay/ML4Bio/keys\{/key_id\}', 'collaborators_url': 'https://api.github.com/repos/KastanDay/ML4Bio/collaborators\{/collaborator\}', 'teams_url': 'https://api.github.com/repos/KastanDay/ML4Bio/teams', 'hooks_url': 'https://api.github.com/repos/KastanDay/ML4Bio/hooks', 'issue_events_url': 'https://api.github.com/repos/KastanDay/ML4Bio/issues/events\{/number\}', 'events_url': 'https://api.github.com/repos/KastanDay/ML4Bio/events', 'assignees_url': 'https://api.github.com/repos/KastanDay/ML4Bio/assignees\{/user\}', 'branches_url': 'https://api.github.com/repos/KastanDay/ML4Bio/branches\{/branch\}', 'tags_url': 'https://api.github.com/repos/KastanDay/ML4Bio/tags', 'blobs_url': 'https://api.github.com/repos/KastanDay/ML4Bio/git/blobs\{/sha\}', 'git_tags_url': 'https://api.github.com/repos/KastanDay/ML4Bio/git/tags\{/sha\}', 'git_refs_url': 'https://api.github.com/repos/KastanDay/ML4Bio/git/refs\{/sha\}', 'trees_url': 'https://api.github.com/repos/KastanDay/ML4Bio/git/trees\{/sha\}', 'statuses_url': 'https://api.github.com/repos/KastanDay/ML4Bio/statuses/\{sha\}', 'languages_url': 'https://api.github.com/repos/KastanDay/ML4Bio/languages', 'stargazers_url': 'https://api.github.com/repos/KastanDay/ML4Bio/stargazers', 'contributors_url': 'https://api.github.com/repos/KastanDay/ML4Bio/contributors', 'subscribers_url': 'https://api.github.com/repos/KastanDay/ML4Bio/subscribers', 'subscription_url': 'https://api.github.com/repos/KastanDay/ML4Bio/subscription', 'commits_url': 'https://api.github.com/repos/KastanDay/ML4Bio/commits\{/sha\}', 'git_commits_url': 'https://api.github.com/repos/KastanDay/ML4Bio/git/commits\{/sha\}', 'comments_url': 'https://api.github.com/repos/KastanDay/ML4Bio/comments\{/number\}', 'issue_comment_url': 'https://api.github.com/repos/KastanDay/ML4Bio/issues/comments\{/number\}', 'contents_url': 'https://api.github.com/repos/KastanDay/ML4Bio/contents/\{+path\}', 'compare_url': 'https://api.github.com/repos/KastanDay/ML4Bio/compare/\{base\}...\{head\}', 'merges_url': 'https://api.github.com/repos/KastanDay/ML4Bio/merges', 'archive_url': 'https://api.github.com/repos/KastanDay/ML4Bio/\{archive_format\}\{/ref\}', 'downloads_url': 'https://api.github.com/repos/KastanDay/ML4Bio/downloads', 'issues_url': 'https://api.github.com/repos/KastanDay/ML4Bio/issues\{/number\}', 'pulls_url': 'https://api.github.com/repos/KastanDay/ML4Bio/pulls\{/number\}', 'milestones_url': 'https://api.github.com/repos/KastanDay/ML4Bio/milestones\{/number\}', 'notifications_url': 'https://api.github.com/repos/KastanDay/ML4Bio/notifications\{?since,all,participating\}', 'labels_url': 'https://api.github.com/repos/KastanDay/ML4Bio/labels\{/name\}', 'releases_url': 'https://api.github.com/repos/KastanDay/ML4Bio/releases\{/id\}', 'deployments_url': 'https://api.github.com/repos/KastanDay/ML4Bio/deployments', 'created_at': '2023-10-09T20:56:43Z', 'updated_at': '2023-10-09T21:00:17Z', 'pushed_at': '2023-11-21T17:50:12Z', 'git_url': 'git://github.com/KastanDay/ML4Bio.git', 'ssh_url': '[email protected]:KastanDay/ML4Bio.git', 'clone_url': 'https://github.com/KastanDay/ML4Bio.git', 'svn_url': 'https://github.com/KastanDay/ML4Bio', 'homepage': None, 'size': 54020, 'stargazers_count': 0, 'watchers_count': 0, 'language': 'HTML', 'has_issues': True, 'has_projects': True, 'has_downloads': True, 'has_wiki': True, 'has_pages': False, 'has_discussions': False, 'forks_count': 0, 'mirror_url': None, 'archived': False, 'disabled': False, 'open_issues_count': 27, 'license': \{'key': 'mit', 'name': 'MIT License', 'spdx_id': 'MIT', 'url': 'https://api.github.com/licenses/mit', 'node_id': 'MDc6TGljZW5zZTEz'\}, 'allow_forking': True, 'is_template': False, 'web_commit_signoff_required': False, 'topics': [], 'visibility': 'public', 'forks': 0, 'open_issues': 27, 'watchers': 0, 'default_branch': 'main'\}, 'sender': \{'login': 'minump', 'id': 22112888, 'node_id': 'MDQ6VXNlcjIyMTEyODg4', 'avatar_url': 'https://avatars.githubusercontent.com/u/22112888?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/minump', 'html_url': 'https://github.com/minump', 'followers_url': 'https://api.github.com/users/minump/followers', 'following_url': 'https://api.github.com/users/minump/following\{/other_user\}', 'gists_url': 'https://api.github.com/users/minump/gists\{/gist_id\}', 'starred_url': 'https://api.github.com/users/minump/starred\{/owner\}\{/repo\}', 'subscriptions_url': 'https://api.github.com/users/minump/subscriptions', 'organizations_url': 'https://api.github.com/users/minump/orgs', 'repos_url': 'https://api.github.com/users/minump/repos', 'events_url': 'https://api.github.com/users/minump/events\{/privacy\}', 'received_events_url': 'https://api.github.com/users/minump/received_events', 'type': 'User', 'site_admin': False\}, 'installation': \{'id': 40525268, 'node_id': 'MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uNDA1MjUyNjg='\}\}}

0 comments on commit ca7922d

Please sign in to comment.