Skip to content

Commit

Permalink
fix: template agents
Browse files Browse the repository at this point in the history
  • Loading branch information
okradze committed Nov 30, 2023
1 parent bfce987 commit 8deb0cf
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 67 deletions.
12 changes: 9 additions & 3 deletions apps/server/controllers/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def get_agents(
# todo need remove, is depricated
@router.get("/discover", response_model=Dict[str, List[AgentWithConfigsOutput]])
def get_template_and_system_agents() -> Dict[str, List[AgentWithConfigsOutput]]:
template_agents = AgentModel.get_template_agents(db=db)
template_agents = AgentModel.get_template_agents(
session=db.session, account_id=None
)
system_agents = AgentModel.get_public_agents(db=db)

template_agents_list = convert_agents_to_agent_list(template_agents)
Expand All @@ -156,8 +158,12 @@ def get_public_agents() -> Dict[str, List[AgentWithConfigsOutput]]:


@router.get("/discover/templates", response_model=List[AgentWithConfigsOutput])
def get_template_agents() -> Dict[str, List[AgentWithConfigsOutput]]:
template_agents = AgentModel.get_template_agents(db=db)
def get_template_agents(
auth: UserAccount = Depends(authenticate),
) -> Dict[str, List[AgentWithConfigsOutput]]:
template_agents = AgentModel.get_template_agents(
session=db.session, account_id=auth.account.id
)
return convert_agents_to_agent_list(template_agents)


Expand Down
30 changes: 21 additions & 9 deletions apps/server/models/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from typing import List

from sqlalchemy import UUID, Boolean, Column, ForeignKey, Index, String, or_
from sqlalchemy.orm import joinedload, relationship
from sqlalchemy.orm import Session, joinedload, relationship
from sqlalchemy.sql import and_

from exceptions import AgentNotFoundException
from models.agent_config import AgentConfigModel
Expand Down Expand Up @@ -216,17 +217,28 @@ def get_agents(cls, db, account):
return agents

@classmethod
def get_template_agents(cls, db):
def get_template_agents(cls, session: Session, account_id: UUID):
query = session.query(AgentModel)

if account_id is not None:
query = query.filter(
or_(
and_(
AgentModel.account_id == account_id,
AgentModel.is_template.is_(True),
),
AgentModel.is_public.is_(True),
)
)
else:
query = query.filter(AgentModel.is_public.is_(True))

agents = (
db.session.query(AgentModel)
.filter(
or_(AgentModel.is_deleted.is_(False), AgentModel.is_deleted.is_(None)),
AgentModel.is_template.is_(True),
query.filter(
AgentModel.is_deleted.is_(False),
)
.options(joinedload(AgentModel.creator))
.options(
joinedload(AgentModel.configs)
) # if you have a relationship set up named "configs"
.options(joinedload(AgentModel.configs))
.all()
)
return agents
Expand Down
9 changes: 2 additions & 7 deletions apps/ui/src/pages/Discover/Discover.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import styled from 'styled-components'
import DiscoverTeamAgents from './components/DiscoverTeamAgents'
import DiscoverTemplateAgents from './components/DiscoverTemplateAgents'

import { StyledTab, StyledTabListSpan, StyledTabListWrapper } from 'styles/tabStyles.css'

import Tab from '@l3-lib/ui-core/dist/Tab'
import TabList from '@l3-lib/ui-core/dist/TabList'
import TabPanel from '@l3-lib/ui-core/dist/TabPanel'
import TabPanels from '@l3-lib/ui-core/dist/TabPanels'
import TabsContext from '@l3-lib/ui-core/dist/TabsContext'
import { t } from 'i18next'
import { useState } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import DiscoverSystemAgents from './components/DiscoverSystemAgents'

const Discover = () => {
const navigate = useNavigate()
Expand Down Expand Up @@ -50,14 +49,10 @@ const Discover = () => {
<DiscoverTeamAgents />
</TabPanel>
<TabPanel>
<DiscoverTemplateAgents />
<DiscoverSystemAgents />
</TabPanel>
</TabPanels>
</TabsContext>

{/* {<DiscoverSystemAgents />} */}

{/* {!user && <Toolkit isPublic />} */}
</StyledRoot>
)
}
Expand Down
66 changes: 18 additions & 48 deletions apps/ui/src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
import React from 'react'

import { StyledInnerWrapper } from 'components/Layout/LayoutStyle'

import styled from 'styled-components'

import Agents from 'pages/Agents'

import { AuthContext } from 'contexts'

import DiscoverTeamAgents from 'pages/Discover/components/DiscoverTeamAgents'
import DiscoverTemplateAgents from 'pages/Discover/components/DiscoverTemplateAgents'

import TeamOfAgents from 'pages/TeamOfAgents'
import { useTeamOfAgents } from 'pages/TeamOfAgents/useTeamOfAgents'
import { useAgents } from 'pages/Agents/useAgents'


import { useGetAccountModule } from 'utils/useGetAccountModule'
import DiscoverSystemAgents from 'pages/Discover/components/DiscoverSystemAgents'

const Home = () => {
// const isProduction = import.meta.env.REACT_APP_ENV === 'production'
const { user } = React.useContext(AuthContext)

const { teamOfAgents } = useTeamOfAgents()
Expand All @@ -31,40 +21,25 @@ const Home = () => {
const agentModules = getHomeModules('agent')

return (
<>
<StyledInnerWrapperEdit>
{/* {!user && <HeaderText />} */}
{user ? (
<>
<StyledWrapper>
{teamModules?.list &&
(teamOfAgents?.length > 0 ? <TeamOfAgents isHome /> : <DiscoverTeamAgents />)}

{agentModules?.list && agentsData?.length > 0 ? (
<Agents isHome />
) : (
<DiscoverTemplateAgents />
)}
</StyledWrapper>
</>
) : (
<>
{/* <StyledIframe
width='560'
height='315'
src={`https://www.youtube.com/embed/${import.meta.env.REACT_APP_YOUTUBE_VIDEO_ID}`}
title='YouTube video player'
frameBorder='0'
allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture'
allowFullScreen
></StyledIframe> */}

<DiscoverTeamAgents />
<StyledInnerWrapperEdit>
{user ? (
<StyledWrapper>
{teamModules?.list &&
(teamOfAgents?.length > 0 ? <TeamOfAgents isHome /> : <DiscoverTeamAgents />)}

{agentModules?.list && agentsData?.length > 0 ? (
<Agents isHome />
) : (
<DiscoverSystemAgents />
</>
)}
</StyledInnerWrapperEdit>
</>
)}
</StyledWrapper>
) : (
<>
<DiscoverTeamAgents />
<DiscoverSystemAgents />
</>
)}
</StyledInnerWrapperEdit>
)
}

Expand All @@ -81,8 +56,3 @@ const StyledWrapper = styled.div`
flex-direction: column;
gap: 100px;
`

const StyledIframe = styled.iframe`
border-radius: 10px;
margin: auto;
`

0 comments on commit 8deb0cf

Please sign in to comment.