subashpoudel's picture
Updated tools.py
6178c40
raw
history blame
3.2 kB
from langchain_groq import ChatGroq
from pydantic import BaseModel, Field
from dotenv import load_dotenv
load_dotenv()
import os
import numpy as np
from langchain_core.tools import tool
from .data_loader import load_influencer_data
from .models_loader import ST , llm
os.environ['GROQ_API_KEY']=os.getenv('GROQ_API_KEY')
class StoryFormatter(BaseModel):
"""Always use this tool to structure your response to the user."""
story: str=Field(description="How to introduce the scene and set the tone. What is happening in the scene? Describe key visuals and actions")
narration:str=Field(description="Suggestions for narration or voiceover that complements the visuals." )
text_in_the_Video:str=Field(description="Propose important text overlays for key moments.")
transitions:str=Field(description="Smooth transitions between scenes to maintain flow.")
emotional_tone:str=Field(description="The mood and energy of the scenes (e.g., excitement, calm, tension, joy")
key_visuals:str=Field(description="Important props, locations, sound effects, or background music to enhance the video.")
class BrainstromTopicFormatter(BaseModel):
topic1:str=Field(description="First brainstorming topic of the story")
topic2:str=Field(description="Second brainstorming topic of the story")
topic3:str=Field(description="Third brainstorming topic of the story")
topic4:str=Field(description="Fourth brainstorming topic of the story")
class QueryFormatter(BaseModel):
idea:str = Field(description="Any idea or query about the business.")
business_details: str = Field(description="The details of the business of that user.")
@tool("influencer's data-retrieval-tool", args_schema=QueryFormatter, return_direct=False,description="Retrieve influencer-related data for a given query.")
def retrieve_tool(idea, business_details):
# """This tool is responsible for the retrieval of the influencer's data using semantic search by reading any **idea or query about the business** and the **business details of the user.**
# But remember, the idea have to be valid first. Don't retrieve anything if the idea is invalid or it is like General Question Answering or follow up questions.
# If you find the idea as invalid, write the value as "None" in the idea so that i can process it."""
"""This tool is responsible for the retrieval of the influencer's data using semantic search by reading any **idea or query about the business** and the **business details of the user.**
."""
embedded_query = ST.encode(str(idea)+str(business_details)) # Embed each topic
data = load_influencer_data()
scores, retrieved_examples = data.get_nearest_examples("embeddings", embedded_query, k=3)
# Construct a list of dictionaries for this topic
result = [{user: story} for user, story in zip(retrieved_examples['username'], retrieved_examples['agentic_story'])]
# result = [{u: {"story": s, "likes": l, "comments": c}} for u, s, l, c in zip(retrieved_examples['username'], retrieved_examples['agentic_story'], retrieved_examples['likes'], retrieved_examples['comments'])]
print('The tool response:',result)
return result