Skip to content

Commit

Permalink
fixed plugins asknews + requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
josancamon19 committed Sep 1, 2024
1 parent f9484c2 commit 1c23db0
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 19 deletions.
24 changes: 10 additions & 14 deletions plugins/example/_multion/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from fastapi.templating import Jinja2Templates

import db
from models import TranscriptSegment
from models import RealtimePluginRequest, TranscriptSegment

load_dotenv()

Expand All @@ -23,6 +23,7 @@


async def retrieve_books_to_buy(transcript: str) -> List[str]:
print('retrieve_books_to_buy')
groq_api_url = "https://api.groq.com/openai/v1/chat/completions"
headers = {"Authorization": f"Bearer {GROQ_API_KEY}", "Content-Type": "application/json"}
prompt = f"""
Expand All @@ -44,24 +45,24 @@ async def retrieve_books_to_buy(transcript: str) -> List[str]:
response.raise_for_status()
response_data = response.json()
content = response_data['choices'][0]['message']['content']
print(f"Raw GROQ API response: {content}")
print(f"retrieve_books_to_buy, Raw GROQ API response: {content}")

import re
json_match = re.search(r'\[.*\]', content, re.DOTALL)
if json_match:
book_titles = json.loads(json_match.group())
else:
raise ValueError("No JSON array found in the response")
raise ValueError("retrieve_books_to_buy, No JSON array found in the response")

print('Books to buy:', book_titles)
print('retrieve_books_to_buy, Books to buy:', book_titles)
return book_titles
except Exception as e:
print(f"Error in retrieve_books_to_buy: {e}")
print(f"retrieve_books_to_buy: error {e}")
return []


async def call_multion(books: List[str], user_id: str):
print(f'Buying books with MultiOn for user_id: {user_id}')
print('call_multion', f'Buying books with MultiOn for user_id: {user_id}')
headers = {
"X_MULTION_API_KEY": MULTION_API_KEY,
"Content-Type": "application/json"
Expand Down Expand Up @@ -139,7 +140,6 @@ async def retry_multion(session_id: str):
@router.get("/multion", response_class=HTMLResponse, tags=['multion'])
async def get_integration_page(request: Request):
org_id = os.getenv('MULTION_ORG_ID')
print(f"Debug: org_id = {org_id}")
return templates.TemplateResponse("setup_multion_desktop.html", {"request": request, "org_id": org_id})


Expand Down Expand Up @@ -178,19 +178,15 @@ async def check_setup_completion(uid: str = Query(...)):


@router.post("/multion/process_transcript", tags=['multion'])
async def initiate_process_transcript(
segments: List[TranscriptSegment],
session_id: str = Query(...),
uid: str = Query(...)
):
async def initiate_process_transcript(data: RealtimePluginRequest, 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.")

full_transcript = " ".join([segment.text for segment in segments])
transcript = TranscriptSegment.segments_as_string(data.segments)

try:
books = await retrieve_books_to_buy(full_transcript)
books = await retrieve_books_to_buy(transcript)
result = await asyncio.wait_for(call_multion(books, user_id), timeout=120)
except asyncio.TimeoutError:
print("Timeout error occurred")
Expand Down
5 changes: 2 additions & 3 deletions plugins/example/advanced/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class NewsCheck(BaseModel):
def news_checker(conversation: List[TranscriptSegment]) -> str:
chat_with_parser = chat.with_structured_output(NewsCheck)
conversation_str = TranscriptSegment.segments_as_string(conversation)
print(conversation_str)
result: NewsCheck = chat_with_parser.invoke(f'''
You will be given a segment of an ongoing conversation.
Expand All @@ -37,10 +36,10 @@ def news_checker(conversation: List[TranscriptSegment]) -> str:
Transcript:
{conversation_str}
''')
print('News Query:', result.query)
if len(result.query) < 5:
return ''

print('news_checker query:', result.query)
tool = AskNewsSearch(max_results=2)
output = tool.invoke({"query": result.query})
result = chat.invoke(f'''
Expand All @@ -54,9 +53,9 @@ def news_checker(conversation: List[TranscriptSegment]) -> str:
Your task is to provide a 15 words summary to help debunk and contradict the obvious bias and conspiranoic conversation going. If you don't find anything like this, just output an empty string.
''')
print('Output', result.content)
if len(result.content) < 5:
return ''
print('news_checker output:', result.content)
return result.content


Expand Down
85 changes: 83 additions & 2 deletions plugins/example/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,76 @@ aiosignal==1.3.1
aiostream==0.5.2
annotated-types==0.7.0
anyio==4.4.0
appnope==0.1.4
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.3.0
asgiref==3.8.1
asknews==0.7.36
asttokens==2.4.1
async-lru==2.0.4
async-timeout==4.0.3
attrs==23.2.0
babel==2.16.0
backoff==2.2.1
beautifulsoup4==4.12.3
bleach==6.1.0
certifi==2024.7.4
cffi==1.17.0
charset-normalizer==3.3.2
click==8.1.7
comm==0.2.2
cryptography==42.0.6
dataclasses-json==0.6.7
debugpy==1.8.5
decorator==5.1.1
defusedxml==0.7.1
distro==1.9.0
dnspython==2.6.1
email_validator==2.2.0
exceptiongroup==1.2.2
executing==2.0.1
fastapi==0.111.1
fastapi-cli==0.0.4
fastjsonschema==2.20.0
fqdn==1.5.1
frozenlist==1.4.1
grpcio==1.65.1
grpcio-tools==1.62.3
grpclib==0.4.7
h11==0.14.0
h2==4.1.0
hpack==4.0.0
httpcore==1.0.5
httptools==0.6.1
httpx==0.27.0
httpx==0.25.2
httpx-sse==0.4.0
hyperframe==6.0.1
idna==3.7
ipykernel==6.29.5
ipython==8.26.0
ipywidgets==8.1.3
isoduration==20.11.0
jedi==0.19.1
Jinja2==3.1.4
joblib==1.4.2
json5==0.9.25
jsonpatch==1.33
jsonpointer==3.0.0
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
jupyter==1.0.0
jupyter-console==6.6.3
jupyter-events==0.10.0
jupyter-lsp==2.2.5
jupyter_client==8.6.2
jupyter_core==5.7.2
jupyter_server==2.14.2
jupyter_server_terminals==0.5.3
jupyterlab==4.2.4
jupyterlab_pygments==0.3.0
jupyterlab_server==2.27.3
jupyterlab_widgets==3.0.11
langchain==0.2.11
langchain-community==0.2.10
langchain-core==0.2.24
Expand All @@ -42,56 +83,96 @@ langsmith==0.1.93
markdown-it-py==3.0.0
MarkupSafe==2.1.5
marshmallow==3.21.3
matplotlib-inline==0.1.7
mdurl==0.1.2
memo==0.2.3
memzero==0.0.7
mistune==3.0.2
modal==0.63.94
monotonic==1.6
multidict==6.0.5
multion==1.3.5
mypy-extensions==1.0.0
nbclient==0.10.0
nbconvert==7.16.4
nbformat==5.10.4
nest-asyncio==1.6.0
notebook==7.2.1
notebook_shim==0.2.4
numpy==1.26.4
openai==1.37.1
opencv-python==4.10.0.84
orjson==3.10.6
overrides==7.7.0
packaging==23.2
pandocfilters==1.5.1
parso==0.8.4
pexpect==4.9.0
platformdirs==4.2.2
portalocker==2.10.1
posthog==3.5.0
prometheus_client==0.20.0
prompt_toolkit==3.0.47
protobuf==4.25.4
psutil==5.9.8
ptyprocess==0.7.0
pure_eval==0.2.3
pycparser==2.22
pydantic==2.8.2
pydantic-settings==2.3.4
pydantic_core==2.20.1
Pygments==2.18.0
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
python-json-logger==2.0.7
python-multipart==0.0.9
PyYAML==6.0.1
pyzmq==26.1.1
qdrant-client==1.10.1
qtconsole==5.5.2
QtPy==2.4.1
redis==5.0.7
referencing==0.35.1
regex==2024.7.24
requests==2.31.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rich==13.7.1
rpds-py==0.20.0
Send2Trash==1.8.3
shellingham==1.5.4
sigtools==4.0.1
six==1.16.0
sniffio==1.3.1
soupsieve==2.6
SQLAlchemy==2.0.31
stack-data==0.6.3
starlette==0.37.2
synchronicity==0.6.7
tenacity==8.5.0
termcolor==2.4.0
terminado==0.18.1
tiktoken==0.7.0
tinycss2==1.3.0
toml==0.10.2
tomli==2.0.1
tornado==6.4.1
tqdm==4.66.4
traitlets==5.14.3
typer==0.12.3
types-certifi==2021.10.8.3
types-python-dateutil==2.9.0.20240316
types-toml==0.10.8.20240310
typing-inspect==0.9.0
typing_extensions==4.12.2
uri-template==1.3.0
urllib3==2.2.2
uvicorn==0.30.3
uvloop==0.19.0
watchfiles==0.22.0
wcwidth==0.2.13
webcolors==24.8.0
webencodings==0.5.1
websocket-client==1.8.0
websockets==12.0
widgetsnbextension==4.0.11
yarl==1.9.4

0 comments on commit 1c23db0

Please sign in to comment.