Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for OpenAI Assistants in SAML #755

Merged
merged 28 commits into from
Feb 6, 2024
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d1abb7c
fix duplicate editor instances
elisalimli Feb 4, 2024
b1cf0ec
fix typo
elisalimli Feb 4, 2024
272ef84
improve logging - adding stack trace
elisalimli Feb 4, 2024
4abfa97
refactor openai assistant
elisalimli Feb 4, 2024
8930675
uploading data files to openai assistants api
elisalimli Feb 4, 2024
968e8a6
fix list workflows endpoint
elisalimli Feb 5, 2024
66b47c6
Fix conflicts
homanp Feb 5, 2024
68cd103
added openai assistant
elisalimli Feb 5, 2024
eabe12e
saving tools and datasources in yaml
elisalimli Feb 5, 2024
38df2e7
add autocompelete for openai assistant tool names
elisalimli Feb 5, 2024
45e7d2f
refactored code
elisalimli Feb 5, 2024
e7052d9
Merge branch 'developer-ui' into yaml-openai-assistant
homanp Feb 6, 2024
5ad3091
add deprecation alert in agents page
elisalimli Feb 6, 2024
33ec97d
fix metadata json errors
elisalimli Feb 6, 2024
8ed28c7
revert agent chat ui page
elisalimli Feb 6, 2024
8fbc2b0
add agent icon to sidebar
elisalimli Feb 6, 2024
1f273b8
Small tweaks
homanp Feb 6, 2024
9256324
Merge branch 'developer-ui' into yaml-openai-assistant
homanp Feb 6, 2024
c686b6f
Minor tweaks
homanp Feb 6, 2024
ac0a0fb
Merge branch 'developer-ui' into yaml-openai-assistant
elisalimli Feb 6, 2024
1b1566a
Small tweaks
homanp Feb 6, 2024
29070e6
fix openai assistant's not ending stream
elisalimli Feb 6, 2024
5663985
fix deleting all agents
elisalimli Feb 6, 2024
bb8d12e
fix the build type error
elisalimli Feb 6, 2024
2ce8f81
Merge branch 'developer-ui' into yaml-openai-assistant
elisalimli Feb 6, 2024
50dad91
Small tweak
homanp Feb 6, 2024
732dcec
Merge branch 'developer-ui' into yaml-openai-assistant
elisalimli Feb 6, 2024
b4c35c9
Merge branch 'yaml-openai-assistant' of github.com:homanp/superagent …
homanp Feb 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions libs/superagent/app/api/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,15 @@ async def delete(agent_id: str, api_user=Depends(get_current_api_user)):
if SEGMENT_WRITE_KEY:
analytics.track(api_user.id, "Deleted Agent")
deleted = await prisma.agent.delete(where={"id": agent_id})
metadata = json.loads(deleted.metadata)

if deleted.type:
if deleted.type == AgentType.OPENAI_ASSISTANT:
llm = await prisma.llm.find_first_or_raise(
where={"provider": "OPENAI", "apiUserId": api_user.id}
)
assistant_factory = OpenAIAssistant(llm)
assistant_id = metadata.get("id")

assistant = AssistantHandler(assistant_factory)

if assistant_id:
await assistant.delete_assistant(assistant_id)

if deleted.openaiMetadata is None:
return {"success": True, "data": None}
openaiMetadata = json.loads(deleted.openaiMetadata)
if openaiMetadata.get("id", None):
llm = await prisma.llm.find_first_or_raise(
where={"provider": "OPENAI", "apiUserId": api_user.id}
)
oai = AsyncOpenAI(api_key=llm.apiKey)
await oai.beta.assistants.delete(openaiMetadata.get("id"))
return {"success": True, "data": None}
except Exception as e:
handle_exception(e)
Expand Down Expand Up @@ -381,9 +375,30 @@ async def update(
where={"id": agent_id},
data=new_agent_data,
)

data.metadata = json.dumps(data.metadata)

if data.openaiMetadata is None:
return {"success": True, "data": data}
openaiMetadata = json.loads(data.openaiMetadata)
if openaiMetadata:
llm = await prisma.llm.find_first_or_raise(
where={"provider": "OPENAI", "apiUserId": api_user.id}
)
oai = AsyncOpenAI(api_key=llm.apiKey)
oai_assistant = await oai.beta.assistants.update(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are already updating openai assistant above, there's no need for this.

assistant_id=openaiMetadata.get("id"),
name=data.name,
description=data.description,
instructions=data.prompt,
tools=openaiMetadata.get("tools", []),
file_ids=openaiMetadata.get("file_ids", []),
metadata=openaiMetadata.get("metadata", {}),
)
data = await prisma.agent.update(
where={"id": agent_id},
data={
"openaiMetadata": json.dumps(oai_assistant.json()),
"apiUserId": api_user.id,
},
)
return {"success": True, "data": data}
except Exception as e:
handle_exception(e)
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.