Skip to content

Commit

Permalink
Merge pull request #1 from mgunnin/dev-01
Browse files Browse the repository at this point in the history
  • Loading branch information
mgunnin authored Aug 6, 2023
2 parents a74d3d6 + 4edc91e commit 1b091ae
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 41 deletions.
1 change: 1 addition & 0 deletions app/api/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async def create_agent(body: Agent, token=Depends(JWTBearer())):
agent = prisma.agent.create(
{
"name": body.name,
"avatarUrl": body.avatarUrl,
"type": body.type,
"llm": json.dumps(body.llm),
"hasMemory": body.hasMemory,
Expand Down
40 changes: 9 additions & 31 deletions app/api/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,12 @@ async def create_document(body: Document, token=Depends(JWTBearer())):
@router.get("/documents", name="List documents", description="List all documents")
async def read_documents(token=Depends(JWTBearer())):
"""List documents endpoint"""
try:
documents = prisma.document.find_many(
where={"userId": token["userId"]},
include={"user": True},
order={"createdAt": "desc"},
)

if documents or documents == []:
return {"success": True, "data": documents}
except Exception as e:
logger.error("Couldn't find documents", exc_info=e)
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="No agents found",
)
documents = prisma.document.find_many(
where={"userId": token["userId"]},
include={"user": True},
order={"createdAt": "desc"},
)
return {"success": True, "data": documents}


@router.get(
Expand All @@ -84,23 +75,10 @@ async def read_documents(token=Depends(JWTBearer())):
)
async def read_document(documentId: str, token=Depends(JWTBearer())):
"""Get a single document"""
try:
document = prisma.document.find_unique(
where={"id": documentId}, include={"user": True}
)
except Exception as e:
logger.error("Couldn't find document with id {documentId}", exc_info=e)
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Agent with id: {documentId} not found",
)

if document:
return {"success": True, "data": document}
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Agent with id: {documentId} not found",
document = prisma.document.find_unique(
where={"id": documentId}, include={"user": True}
)
return {"success": True, "data": document}


@router.delete(
Expand Down
1 change: 1 addition & 0 deletions app/lib/models/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class Agent(BaseModel):
name: str
type: str
avatarUrl: str = None
llm: dict = None
hasMemory: bool = False
promptId: str = None
Expand Down
51 changes: 48 additions & 3 deletions fern/api/openapi/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.2
info:
title: Superagent
description: Build, deploy, and manage LLM-powered agents
version: 0.0.40
version: 0.0.43
paths:
/api/v1/agents:
get:
Expand Down Expand Up @@ -567,6 +567,30 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/api/v1/auth/oauth/callback:
post:
tags:
- Auth
summary: Oauth Handler
operationId: oauth_handler_api_v1_auth_oauth_callback_post
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/OAuth'
required: true
responses:
'200':
description: Successful Response
content:
application/json:
schema: {}
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/api/v1/users/me:
get:
tags:
Expand Down Expand Up @@ -1180,6 +1204,9 @@ components:
url:
title: Url
type: string
content:
title: Content
type: string
name:
title: Name
type: string
Expand All @@ -1192,8 +1219,7 @@ components:
from_page:
title: From Page
type: integer
default:
- 1
default: 1
to_page:
title: To Page
type: integer
Expand All @@ -1209,6 +1235,25 @@ components:
type: array
items:
$ref: '#/components/schemas/ValidationError'
OAuth:
title: OAuth
required:
- email
- name
type: object
properties:
email:
title: Email
type: string
name:
title: Name
type: string
access_token:
title: Access Token
type: string
provider:
title: Provider
type: string
PredictAgent:
title: PredictAgent
required:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Agent" ADD COLUMN "avatarUrl" TEXT;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ model Document {

model Agent {
id String @id @default(cuid()) @db.VarChar(255)
avatarUrl String? @db.Text()
userId String @db.VarChar(255)
user User @relation(fields: [userId], references: [id])
document Document? @relation(fields: [documentId], references: [id])
Expand Down
2 changes: 1 addition & 1 deletion ui/app/agents/[agentId]/client-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export default function AgentDetailClientPage({
<Divider />
<PanelHeading title="Tags" onCreate={onTagModalOpen} />
<HStack paddingX={6} paddingY={6} flexWrap="wrap" gap={2} spacing={0}>
{agent.tags.map(({ id, name, color }) => (
{agent.tags?.map(({ id, name, color }) => (
<AgentTag
key={id}
agent={agent}
Expand Down
11 changes: 11 additions & 0 deletions ui/app/agents/new/_components/agent-store-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,24 @@ export default function AgentStoreInfo({ onSubmit }) {
</Text>
<Stack spacing={3}>
<FormControl>
<FormLabel>Name</FormLabel>
<Input
type="text"
{...register("name", { required: true })}
placeholder="Name your agent..."
/>
</FormControl>
<FormControl>
<FormLabel>Avatar URL</FormLabel>
<Input
type="text"
{...register("avatarUrl", { required: false })}
placeholder="Enter a public URL..."
/>
<FormHelperText>Add an avatar to your agent.</FormHelperText>
</FormControl>
<FormControl>
<FormLabel>Description</FormLabel>
<Textarea
minHeight="200px"
type="text"
Expand Down
7 changes: 4 additions & 3 deletions ui/app/agents/new/client-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function NewAgentClientPage({ session }) {
has_memory: false,
});

const createAgent = async ({ name }) => {
const createAgent = async ({ name, avatarUrl }) => {
let promptId;
const { type, prompt, llm, has_memory, documents, tools } = data;

Expand All @@ -43,6 +43,7 @@ export default function NewAgentClientPage({ session }) {
}

const agent = await api.createAgent({
avatarUrl,
name,
type,
llm,
Expand Down Expand Up @@ -156,8 +157,8 @@ export default function NewAgentClientPage({ session }) {
)}
{activeStep === "INFO" && (
<AgentStoreInfo
onSubmit={async ({ name, description }) => {
await createAgent({ name });
onSubmit={async ({ name, avatarUrl, description }) => {
await createAgent({ name, avatarUrl });
}}
/>
)}
Expand Down
6 changes: 3 additions & 3 deletions ui/app/share/client-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function LoadingMessage() {
)
}

function Message({ message, type }) {
function Message({ agent, message, type }) {
return (
<Container
maxW="5xl"
Expand All @@ -59,7 +59,7 @@ function Message({ message, type }) {
marginTop={1}
/>
) : (
<Avatar size="xs" src="/logo.png" />
<Avatar size="xs" src={agent.avatarUrl || "./logo.png"} />
)}
{type === "human" ? (
<Text>{message}</Text>
Expand Down Expand Up @@ -252,7 +252,7 @@ export default function ShareClientPage({ agent, token }) {
paddingY={10}
>
{messages.map(({ type, message }, index) => (
<Message key={index} type={type} message={message} />
<Message key={index} agent={agent} type={type} message={message} />
))}
{isSubmitting && <LoadingMessage />}
</Box>
Expand Down
Binary file modified ui/public/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1b091ae

Please sign in to comment.