Skip to content

Commit

Permalink
plugins groq 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
josancamon19 committed Sep 3, 2024
1 parent 162a7a1 commit 9f77804
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
7 changes: 3 additions & 4 deletions plugins/example/_multion/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_openai import ChatOpenAI
from langchain_groq import ChatGroq

import db
from models import RealtimePluginRequest, TranscriptSegment
Expand All @@ -19,7 +19,6 @@

templates = Jinja2Templates(directory="templates")

GROQ_API_KEY = os.getenv('GROQ_API_KEY')
MULTION_API_KEY = os.getenv('MULTION_API_KEY', '123')


Expand All @@ -28,7 +27,7 @@ class BooksToBuy(BaseModel):


def retrieve_books_to_buy(transcript: str) -> List[str]:
chat = ChatOpenAI(model='gpt-4o', temperature=0).with_structured_output(BooksToBuy)
chat = ChatGroq(temperature=0, model="llama-3.1-8b-instant").with_structured_output(BooksToBuy)

response: BooksToBuy = chat.invoke(f'''The following is the transcript of a conversation.
{transcript}
Expand Down Expand Up @@ -158,7 +157,7 @@ async def check_setup_completion(uid: str = Query(...)):

@router.post("/multion/process_transcript", tags=['multion'])
async def initiate_process_transcript(data: RealtimePluginRequest, uid: str = Query(...)):
return {'message': ''}
# return {'message': ''}
user_id = db.get_multion_user_id(uid)
if not user_id:
raise HTTPException(status_code=400, detail="Invalid UID or USERID not found.")
Expand Down
27 changes: 13 additions & 14 deletions plugins/example/advanced/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@

from db import clean_all_transcripts_except, append_segment_to_transcript, remove_transcript
from models import RealtimePluginRequest, EndpointResponse, TranscriptSegment
from langchain_groq import ChatGroq

router = APIRouter()
chat = ChatOpenAI(model='gpt-4o', temperature=0)


# chat = ChatGroq(
# temperature=0,
# model="llama-3.1-70b-versatile",
# # model='llama3-groq-8b-8192-tool-use-preview',
# )
chat_groq_8b = ChatGroq(
temperature=0,
# model="llama-3.1-70b-versatile",
model="llama-3.1-8b-instant",
# model='llama3-groq-8b-8192-tool-use-preview',
)


class NewsCheck(BaseModel):
query: str = Field(description="The query to ask a news search engine, can be empty.", default='')


def news_checker(conversation: List[TranscriptSegment]) -> str:
chat_with_parser = chat.with_structured_output(NewsCheck)
chat_with_parser = chat_groq_8b.with_structured_output(NewsCheck)
conversation_str = TranscriptSegment.segments_as_string(conversation)
result: NewsCheck = chat_with_parser.invoke(f'''
You will be given a segment of an ongoing conversation.
Expand All @@ -42,7 +43,7 @@ def news_checker(conversation: List[TranscriptSegment]) -> str:
print('news_checker query:', result.query)
tool = AskNewsSearch(max_results=2)
output = tool.invoke({"query": result.query})
result = chat.invoke(f'''
result = chat_groq_8b.invoke(f'''
A user just asked a search engine news the following question:
{result.query}
Expand All @@ -61,8 +62,8 @@ def news_checker(conversation: List[TranscriptSegment]) -> str:

@router.post('/news-checker', tags=['advanced', 'realtime'], response_model=EndpointResponse)
def news_checker_endpoint(uid: str, data: RealtimePluginRequest):
return {'message': ''}
# print('news_checker_endpoint', uid)
# return {'message': ''}
print('news_checker_endpoint', uid)
clean_all_transcripts_except(uid, data.session_id)
transcript: List[TranscriptSegment] = append_segment_to_transcript(uid, data.session_id, data.segments)
message = news_checker(transcript)
Expand All @@ -79,7 +80,7 @@ class EmotionalSupport(BaseModel):


def emotional_support(segments: list[TranscriptSegment]) -> str:
chat_with_parser = chat.with_structured_output(EmotionalSupport)
chat_with_parser = chat_groq_8b.with_structured_output(EmotionalSupport)
result: EmotionalSupport = chat_with_parser.invoke(f'''
You will be given a segment of an ongoing conversation.
Your task is to detect if there are any accentuated emotions on the conversation and act if it's something unpleasant.
Expand All @@ -100,7 +101,7 @@ def emotional_support(segments: list[TranscriptSegment]) -> str:

@router.post('/emotional-support', tags=['advanced', 'realtime'], response_model=EndpointResponse)
def emotional_support_plugin(uid: str, data: RealtimePluginRequest):
return {'message': ''}
# return {'message': ''}
clean_all_transcripts_except(uid, data.session_id)
transcript: List[TranscriptSegment] = append_segment_to_transcript(uid, data.session_id, data.segments)
message = emotional_support(transcript)
Expand All @@ -110,5 +111,3 @@ def emotional_support_plugin(uid: str, data: RealtimePluginRequest):
remove_transcript(uid, data.session_id)

return {'message': message}

# https://camel-lucky-reliably.ngrok-free.app

0 comments on commit 9f77804

Please sign in to comment.