Skip to content

Commit

Permalink
Update cohere
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Apr 9, 2024
1 parent 90d9e30 commit 9c17691
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 125 deletions.
2 changes: 1 addition & 1 deletion cookbook/claude/finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
show_tool_calls=True,
description="You are an investment analyst that researches stock prices, analyst recommendations, and stock fundamentals.",
instructions=["Format your response using markdown and use tables to display data where possible."],
debug_mode=True,
# debug_mode=True,
)
assistant.print_response("Share the NVDA stock price and analyst recommendations", markdown=True)
# assistant.print_response("Summarize fundamentals for TSLA", markdown=True)
20 changes: 20 additions & 0 deletions cookbook/cohere/data_analyst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from phi.assistant import Assistant
from phi.llm.cohere import CohereChat
from phi.tools.duckdb import DuckDbTools

duckdb_tools = DuckDbTools(create_tables=False, export_tables=False, summarize_tables=False)
duckdb_tools.create_table_from_path(
path="https://phidata-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv", table="movies"
)

assistant = Assistant(
llm=CohereChat(model="command-r-plus"),
tools=[duckdb_tools],
show_tool_calls=True,
add_to_system_prompt="""
Here are the tables you have access to:
- movies: Contains information about movies from IMDB.
""",
# debug_mode=True,
)
assistant.print_response("What is the average rating of movies?", markdown=True, stream=False)
12 changes: 9 additions & 3 deletions cookbook/cohere/exa_search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from phi.assistant import Assistant
from phi.llm.cohere import CohereChat
from phi.tools.exa import ExaTools
from phi.tools.website import WebsiteTools
from phi.llm.cohere import CohereChat

assistant = Assistant(llm=CohereChat(model="command-r"), tools=[ExaTools()], show_tool_calls=True)
assistant.cli_app(markdown=True)
assistant = Assistant(llm=CohereChat(model="command-r-plus"), tools=[ExaTools(), WebsiteTools()], show_tool_calls=True)
assistant.print_response(
"Produce this table: research chromatic homotopy theory."
"Access each link in the result outputting the summary for that article, its link, and keywords; "
"After the table output make conceptual ascii art of the overarching themes and constructions",
markdown=True,
)
5 changes: 4 additions & 1 deletion cookbook/cohere/finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
from phi.llm.cohere import CohereChat

assistant = Assistant(
llm=CohereChat(model="command-r"),
llm=CohereChat(model="command-r-plus"),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True)],
show_tool_calls=True,
description="You are an investment analyst that researches stock prices, analyst recommendations, and stock fundamentals.",
instructions=["Format your response using markdown and use tables to display data where possible."],
# debug_mode=True,
)
assistant.print_response("Share the NVDA stock price and analyst recommendations", markdown=True)
assistant.print_response("Summarize fundamentals for TSLA", markdown=True)
2 changes: 1 addition & 1 deletion cookbook/cohere/structured_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MovieScript(BaseModel):
llm=CohereChat(model="command-r"),
description="You help people write movie scripts.",
output_model=MovieScript,
# debug_mode=True,
debug_mode=True,
)

pprint(movie_assistant.run("New York"))
8 changes: 7 additions & 1 deletion cookbook/cohere/web_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
from phi.tools.duckduckgo import DuckDuckGo
from phi.llm.cohere import CohereChat

assistant = Assistant(llm=CohereChat(model="command-r"), tools=[DuckDuckGo()], show_tool_calls=True)
assistant = Assistant(
llm=CohereChat(model="command-r"),
tools=[DuckDuckGo()],
show_tool_calls=True,
instructions=["Format your response using markdown and use tables to display information where possible."],
debug_mode=True,
)
assistant.print_response("Share 1 story from france and 1 from germany?", markdown=True)
3 changes: 2 additions & 1 deletion phi/assistant/assistant.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from os import getenv
from textwrap import dedent
from uuid import uuid4
from typing import List, Any, Optional, Dict, Iterator, Callable, Union, Type, Tuple, Literal
Expand Down Expand Up @@ -202,7 +203,7 @@ class Assistant(BaseModel):
# debug_mode=True enables debug logs
debug_mode: bool = False
# monitoring=True logs Assistant runs on phidata.com
monitoring: bool = False
monitoring: bool = getenv("PHI_MONITORING", "false").lower() == "true"

model_config = ConfigDict(arbitrary_types_allowed=True)

Expand Down
Loading

0 comments on commit 9c17691

Please sign in to comment.