File size: 3,198 Bytes
be3a5c4
 
 
 
 
 
ca75c57
 
6178c40
be3a5c4
 
ca75c57
be3a5c4
 
6178c40
be3a5c4
 
 
 
 
 
 
 
 
 
 
 
 
 
ca75c57
 
 
6178c40
ca75c57
 
 
 
6178c40
 
 
 
 
 
 
 
ca75c57
 
 
6178c40
ca75c57
 
 
6178c40
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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