Skip to content

Commit

Permalink
Multion change transcript to memory (#909)
Browse files Browse the repository at this point in the history
Lets pray it does not explode


<!-- This is an auto-generated comment: release notes by OSS
Entelligence.AI -->
### Summary by Entelligence.AI

```
- Refactor: Updated the `multion_endpoint` function in the Example plugin to improve efficiency and maintainability. The function now accepts a `Memory` object, streamlining the process of retrieving books from transcripts.
- Improvement: Enhanced error handling within the `multion_endpoint` function for better reliability.
- Consistency: Standardized the use of the response model across the function, improving consistency in our codebase.
```
<!-- end of auto-generated comment: release notes by OSS Entelligence.AI
-->
  • Loading branch information
josancamon19 authored Sep 24, 2024
2 parents f0ea1bf + da48add commit fb24868
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 40 deletions.
4 changes: 2 additions & 2 deletions community-plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,11 @@
"external_integration"
],
"external_integration": {
"triggers_on": "transcript_processed",
"triggers_on": "memory_creation",
"webhook_url": "https://based-hardware--plugins-api.modal.run/multion/process_transcript",
"setup_completed_url": "https://based-hardware--plugins-api.modal.run/multion/check_setup_completion",
"setup_instructions_file_path": "/plugins/instructions/multion-amazon/README.md"
},
"deleted": true
"deleted": false
}
]
48 changes: 10 additions & 38 deletions plugins/example/_multion/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from langchain_groq import ChatGroq

import db
from models import RealtimePluginRequest, TranscriptSegment
from models import Memory, EndpointResponse

load_dotenv()

Expand Down Expand Up @@ -159,53 +159,25 @@ async def check_setup_completion(uid: str = Query(...)):
return {"is_setup_completed": is_setup_completed}


@router.post("/multion/process_transcript", tags=['multion'])
async def initiate_process_transcript(data: RealtimePluginRequest, uid: str = Query(...)):
# return {'message': ''}
@router.post("/multion", response_model=EndpointResponse, tags=['multion'])
async def multion_endpoint(memory: Memory, uid: str = Query(...)):
user_id = db.get_multion_user_id(uid)
if not user_id:
raise HTTPException(status_code=400, detail="Invalid UID or USERID not found.")

session_id = 'multion-' + data.session_id
db.clean_all_transcripts_except(uid, session_id)
transcript: List[TranscriptSegment] = db.append_segment_to_transcript(uid, session_id, data.segments)
transcript_str = TranscriptSegment.segments_as_string(transcript)
if len(transcript_str) > 100:
transcript_str = transcript_str[-100:]
books = retrieve_books_to_buy(memory.get_transcript())
if not books:
return EndpointResponse(message='No books were suggested or mentioned.')

try:
books = retrieve_books_to_buy(transcript_str)
if not books:
return {'message': ''}
db.remove_transcript(uid, data.session_id)
result = await asyncio.wait_for(call_multion(books, user_id), timeout=120)
except asyncio.TimeoutError:
print("Timeout error occurred")
db.remove_transcript(uid, data.session_id)
return
return EndpointResponse(message="Timeout error occurred.")
except Exception as e:
print(f"Error calling Multion API: {str(e)}")
db.remove_transcript(uid, data.session_id)
return

return EndpointResponse(message=f"Error calling Multion API: {str(e)}")
if isinstance(result, bytes):
result = result.decode('utf-8')
return {"message": result}

return {"message": str(result)}

# @router.post("/multion", response_model=EndpointResponse, tags=['multion'])
# async def multion_endpoint(memory: Memory, uid: str = Query(...)):
# user_id = db.get_multion_user_id(uid)
# if not user_id:
# raise HTTPException(status_code=400, detail="Invalid UID or USERID not found.")
#
# books = await retrieve_books_to_buy(memory)
# if not books:
# return EndpointResponse(message='No books were suggested or mentioned.')
#
# result = await call_multion(books, user_id)
# if isinstance(result, bytes):
# result = result.decode('utf-8')
#
# return EndpointResponse(message=result)

return EndpointResponse(message=result)

0 comments on commit fb24868

Please sign in to comment.