How can I resolve this issue. I have followed some suggestion to update phidata, I still cant resolve this error.
ImportError: cannot import name ‘identity’ from ‘phi.utils’
How can I resolve this issue. I have followed some suggestion to update phidata, I still cant resolve this error.
ImportError: cannot import name ‘identity’ from ‘phi.utils’
@imalaiyke can you please share your code so that I can help you better?
Hello Manthan,
Do you prefer I share a github repository or just the .py file?
Kindly let me know if you find a solution
import phi
from phi.agent import Agent
import phi.api
from phi.model.openai import OpenAIChat
from phi.tools.yfinance import YFinanceTools
from phi.tools.duckduckgo import DuckDuckGo
from dotenv import load_dotenv
from phi.model.groq import Groq
from phi.playground import Playground, serve_playground_app
import os
load_dotenv()
phi.api= os.getenv("PHI_API_KEY")
##web search agent
web_search_agent = Agent(
name= "web search Agent",
role= "Search the web for information",
model= Groq(id="llama3-groq-70b-8192-tool-use-preview"),
tools=[DuckDuckGo()],
instructions=["Always include Sources"],
show_tool_calls=True,
markdown=True,
)
## Financial Agent
finance_agent= Agent(
name="Finance AI Agent",
model= Groq(id="llama3-groq-70b-8192-tool-use-preview"),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True, company_news=True)],
instructions=["Use tables to display the data"],
show_tool_calls=True,
markdown=True,
)
app = Playground(agents=[finance_agent, web_search_agent]).get_app()
if __name__ =="__main___":
serve_playground_app("playground.app", reload=True)
error is --> (D:\AgenticAI\venv) D:\AgenticAI>python playground.py Traceback (most recent call last): File "D:\AgenticAI\playground.py", line 1, in <module> import phi File "D:\AgenticAI\venv\Lib\site-packages\phi\__init__.py", line 8, in <module> from . import builder File "D:\AgenticAI\venv\Lib\site-packages\phi\builder.py", line 18, in <module> from .utils import identity ImportError: cannot import name 'identity' from 'phi.utils' (D:\AgenticAI\venv\Lib\site-packages\phi\utils\__init__.py)
@Shafi I was able to run your code with a little adjustments
import phi
from phi.agent import Agent
import phi.api
from phi.model.openai import OpenAIChat
from phi.tools.yfinance import YFinanceTools
from phi.tools.duckduckgo import DuckDuckGo
from dotenv import load_dotenv
from phi.model.groq import Groq
from phi.playground import Playground, serve_playground_app
import os
load_dotenv()
##web search agent
web_search_agent = Agent(
name="web search Agent",
role="Search the web for information",
model=Groq(id="llama3-groq-70b-8192-tool-use-preview"),
tools=[DuckDuckGo()],
instructions=["Always include Sources"],
show_tool_calls=True,
markdown=True,
)
## Financial Agent
finance_agent= Agent(
name="Finance AI Agent",
model= Groq(id="llama3-groq-70b-8192-tool-use-preview"),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True, company_news=True)],
instructions=["Use tables to display the data"],
show_tool_calls=True,
markdown=True,
)
app = Playground(agents=[finance_agent, web_search_agent]).get_app()
if __name__ == "__main__":
serve_playground_app("playground:app", reload=True)
I tried your code, but it still shows the same error. Do I need to change anything apart from this code? i was running it on a virtual Environment.
No I didn’t change anything. How did you get hold on the code I ran prior to testing. I am guessing I don’t need to send anymore to you. This is my first time using phidata following concept I saw on YouTube. I am testing phidata for the first time and it’s not acting right. Please how do I get past this
it’s a shame that I put three underscores (___) instead of two ( __ ) in
if __name__ == "__main__":
Anyway, I tried both ‘v2.7.6’ and ‘v2.7.5’. Both of them are working fine.
I also faced this issue.
ERROR: Error loading ASGI app. Import string "playground.app" must be in format "<module>:<attribute>".
I updated the code a bit:
serve_playground_app("playground:app", port=7777, reload=True)
Now it works fine.
I recommend everyone double-check the interpreter that you are using the appropriate venv. I think it was the main issue.
import phi
from phi.agent import Agent
import phi.api
from phi.model.openai import OpenAIChat
from phi.tools.yfinance import YFinanceTools
from phi.tools.duckduckgo import DuckDuckGo
from dotenv import load_dotenv
from phi.model.groq import Groq
from phi.playground import Playground, serve_playground_app
import os
load_dotenv()
##web search agent
web_search_agent = Agent(
name=“web search Agent”,
role=“Search the web for information”,
model=Groq(id=“llama3-groq-70b-8192-tool-use-preview”),
tools=[DuckDuckGo()],
instructions=[“Always include Sources”],
show_tool_calls=True,
markdown=True,
)
finance_agent= Agent(
name=“Finance AI Agent”,
model= Groq(id=“llama3-groq-70b-8192-tool-use-preview”),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True, company_news=True)],
instructions=[“Use tables to display the data”],
show_tool_calls=True,
markdown=True,
)
app = serve_playground_app(“playground:app”, port=7777, reload=True)
if name== “main”:
serve_playground_app(“playground:app”, reload=True)
i am still facing the same error
could you please help