Skip to content

Commit

Permalink
add fork endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-XT committed Jan 24, 2025
1 parent 6e3d9db commit c5d43f5
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions agixt/endpoints/Conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,20 +435,46 @@ async def rename_conversation(
async def fork_conversation(
fork: ConversationFork, user=Depends(verify_api_key)
) -> ResponseMessage:
conversation_name = fork.conversation_name
try:
conversation_id = uuid.UUID(fork.conversation_name)
conversation_id = uuid.UUID(conversation_name)
user_id = get_user_id(user)
fork.conversation_name = get_conversation_name_by_id(
conversation_name = get_conversation_name_by_id(
conversation_id=str(conversation_id), user_id=user_id
)
except:
conversation_id = fork.conversation_name
conversation_id = None
new_conversation_name = Conversations(
conversation_name=fork.conversation_name, user=user
conversation_name=conversation_name, user=user
).fork_conversation(message_id=fork.message_id)
return ResponseMessage(message=f"Forked conversation to {new_conversation_name}")


@app.post(
"/v1/conversation/fork/{conversation_id}/{message_id}",
response_model=ResponseMessage,
summary="Fork Conversation",
description="Creates a new conversation as a fork from an existing one up to a specific message.",
tags=["Conversation"],
dependencies=[Depends(verify_api_key)],
)
async def forkconversation(
conversation_id: str, message_id: str, user=Depends(verify_api_key)
) -> ResponseMessage:
user_id = get_user_id(user)
try:
conversation_id = uuid.UUID(conversation_id)
conversation_name = get_conversation_name_by_id(
conversation_id=str(conversation_id), user_id=user_id
)
except:
conversation_id = None
new_conversation_name = Conversations(
conversation_name=conversation_name, user=user
).fork_conversation(message_id=str(message_id))
return ResponseMessage(message=f"Forked conversation to {new_conversation_name}")


@app.get(
"/v1/conversation/{conversation_id}/tts/{message_id}",
response_model=Dict[str, str],
Expand Down

0 comments on commit c5d43f5

Please sign in to comment.