Spaces:
Sleeping
Sleeping
Commit
·
6178c40
1
Parent(s):
6853fce
Updated tools.py
Browse files- my_agent/utils/tools.py +15 -5
my_agent/utils/tools.py
CHANGED
|
@@ -6,12 +6,13 @@ import os
|
|
| 6 |
import numpy as np
|
| 7 |
from langchain_core.tools import tool
|
| 8 |
from .data_loader import load_influencer_data
|
| 9 |
-
from .models_loader import ST
|
| 10 |
|
| 11 |
|
| 12 |
os.environ['GROQ_API_KEY']=os.getenv('GROQ_API_KEY')
|
| 13 |
|
| 14 |
|
|
|
|
| 15 |
class StoryFormatter(BaseModel):
|
| 16 |
"""Always use this tool to structure your response to the user."""
|
| 17 |
story: str=Field(description="How to introduce the scene and set the tone. What is happening in the scene? Describe key visuals and actions")
|
|
@@ -29,17 +30,26 @@ class BrainstromTopicFormatter(BaseModel):
|
|
| 29 |
topic4:str=Field(description="Fourth brainstorming topic of the story")
|
| 30 |
|
| 31 |
class QueryFormatter(BaseModel):
|
| 32 |
-
idea:str = Field(description="
|
| 33 |
business_details: str = Field(description="The details of the business of that user.")
|
| 34 |
|
| 35 |
@tool("influencer's data-retrieval-tool", args_schema=QueryFormatter, return_direct=False,description="Retrieve influencer-related data for a given query.")
|
| 36 |
def retrieve_tool(idea, business_details):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
"""This tool is responsible for the retrieval of the influencer's data using semantic search by reading the video idea and the business details of the user. """
|
| 39 |
embedded_query = ST.encode(str(idea)+str(business_details)) # Embed each topic
|
| 40 |
data = load_influencer_data()
|
| 41 |
-
scores, retrieved_examples = data.get_nearest_examples("embeddings", embedded_query, k=
|
| 42 |
|
| 43 |
# Construct a list of dictionaries for this topic
|
| 44 |
result = [{user: story} for user, story in zip(retrieved_examples['username'], retrieved_examples['agentic_story'])]
|
| 45 |
-
|
|
|
|
|
|
|
|
|
| 6 |
import numpy as np
|
| 7 |
from langchain_core.tools import tool
|
| 8 |
from .data_loader import load_influencer_data
|
| 9 |
+
from .models_loader import ST , llm
|
| 10 |
|
| 11 |
|
| 12 |
os.environ['GROQ_API_KEY']=os.getenv('GROQ_API_KEY')
|
| 13 |
|
| 14 |
|
| 15 |
+
|
| 16 |
class StoryFormatter(BaseModel):
|
| 17 |
"""Always use this tool to structure your response to the user."""
|
| 18 |
story: str=Field(description="How to introduce the scene and set the tone. What is happening in the scene? Describe key visuals and actions")
|
|
|
|
| 30 |
topic4:str=Field(description="Fourth brainstorming topic of the story")
|
| 31 |
|
| 32 |
class QueryFormatter(BaseModel):
|
| 33 |
+
idea:str = Field(description="Any idea or query about the business.")
|
| 34 |
business_details: str = Field(description="The details of the business of that user.")
|
| 35 |
|
| 36 |
@tool("influencer's data-retrieval-tool", args_schema=QueryFormatter, return_direct=False,description="Retrieve influencer-related data for a given query.")
|
| 37 |
def retrieve_tool(idea, business_details):
|
| 38 |
+
|
| 39 |
+
# """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.**
|
| 40 |
+
# 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.
|
| 41 |
+
# If you find the idea as invalid, write the value as "None" in the idea so that i can process it."""
|
| 42 |
+
|
| 43 |
+
"""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.**
|
| 44 |
+
."""
|
| 45 |
+
|
| 46 |
|
|
|
|
| 47 |
embedded_query = ST.encode(str(idea)+str(business_details)) # Embed each topic
|
| 48 |
data = load_influencer_data()
|
| 49 |
+
scores, retrieved_examples = data.get_nearest_examples("embeddings", embedded_query, k=3)
|
| 50 |
|
| 51 |
# Construct a list of dictionaries for this topic
|
| 52 |
result = [{user: story} for user, story in zip(retrieved_examples['username'], retrieved_examples['agentic_story'])]
|
| 53 |
+
# 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'])]
|
| 54 |
+
print('The tool response:',result)
|
| 55 |
+
return result
|