Skip to content

Commit

Permalink
v2.4.17
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed May 31, 2024
1 parent efece1e commit 083ee0a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
7 changes: 3 additions & 4 deletions cookbook/llms/groq/finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True, company_news=True)],
show_tool_calls=True,
)
assistant.cli_app(markdown=True, stream=False, user="Groq")
# assistant.print_response("What's the NVDA stock price", markdown=True, stream=False)
# assistant.print_response("Share NVDA analyst recommendations", markdown=True, stream=False)
# assistant.print_response("Summarize fundamentals for TSLA", markdown=True, stream=False)
assistant.print_response("What's the NVDA stock price", markdown=True)
assistant.print_response("Share NVDA analyst recommendations", markdown=True)
assistant.print_response("Summarize fundamentals for TSLA", markdown=True)
4 changes: 3 additions & 1 deletion phi/knowledge/llamaindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from llama_index.core.schema import NodeWithScore
from llama_index.core.retrievers import BaseRetriever
except ImportError:
raise ImportError("The `llama-index-core` package is not installed. Please install it via `pip install llama-index-core`.")
raise ImportError(
"The `llama-index-core` package is not installed. Please install it via `pip install llama-index-core`."
)


class LlamaIndexKnowledgeBase(AssistantKnowledge):
Expand Down
16 changes: 7 additions & 9 deletions phi/llm/groq/groq.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

try:
from groq import Groq as GroqClient
from groq.types.chat.chat_completion import ChatCompletion, ChoiceMessage
from groq.lib.chat_completion_chunk import ChatCompletionChunk, ChoiceDelta, ChoiceDeltaToolCall
except ImportError:
logger.error("`groq` not installed")
raise
Expand Down Expand Up @@ -148,14 +146,14 @@ def to_dict(self) -> Dict[str, Any]:
_dict["tool_choice"] = self.tool_choice
return _dict

def invoke(self, messages: List[Message]) -> ChatCompletion:
def invoke(self, messages: List[Message]) -> Any:
return self.client.chat.completions.create(
model=self.model,
messages=[m.to_dict() for m in messages], # type: ignore
**self.api_kwargs,
)

def invoke_stream(self, messages: List[Message]) -> Iterator[ChatCompletionChunk]:
def invoke_stream(self, messages: List[Message]) -> Iterator[Any]:
yield from self.client.chat.completions.create(
model=self.model,
messages=[m.to_dict() for m in messages], # type: ignore
Expand All @@ -171,14 +169,14 @@ def response(self, messages: List[Message]) -> str:

response_timer = Timer()
response_timer.start()
response: ChatCompletion = self.invoke(messages=messages)
response = self.invoke(messages=messages)
response_timer.stop()
logger.debug(f"Time to generate response: {response_timer.elapsed:.4f}s")
# logger.debug(f"Groq response type: {type(response)}")
# logger.debug(f"Groq response: {response}")

# -*- Parse response
response_message: ChoiceMessage = response.choices[0].message
response_message = response.choices[0].message

# -*- Create assistant message
assistant_message = Message(
Expand Down Expand Up @@ -248,18 +246,18 @@ def response_stream(self, messages: List[Message]) -> Iterator[str]:

assistant_message_role = None
assistant_message_content = ""
assistant_message_tool_calls: Optional[List[ChoiceDeltaToolCall]] = None
assistant_message_tool_calls: Optional[List[Any]] = None
response_timer = Timer()
response_timer.start()
for response in self.invoke_stream(messages=messages):
# logger.debug(f"Groq response type: {type(response)}")
# logger.debug(f"Groq response: {response}")
# -*- Parse response
response_delta: ChoiceDelta = response.choices[0].delta
response_delta = response.choices[0].delta
if assistant_message_role is None and response_delta.role is not None:
assistant_message_role = response_delta.role
response_content: Optional[str] = response_delta.content
response_tool_calls: Optional[List[ChoiceDeltaToolCall]] = response_delta.tool_calls
response_tool_calls: Optional[List[Any]] = response_delta.tool_calls

# -*- Return content if present, otherwise get tool call
if response_content is not None:
Expand Down
2 changes: 1 addition & 1 deletion phi/tools/pubmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def fetch_pubmed_ids(self, query: str, max_results: int, email: str) -> List[str
"email": email,
"usehistory": "y",
}
response = httpx.get(url, params=params)
response = httpx.get(url, params=params) # type: ignore
root = ElementTree.fromstring(response.content)
return [id_elem.text for id_elem in root.findall(".//Id") if id_elem.text is not None]

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "phidata"
version = "2.4.16"
version = "2.4.17"
description = "Memory, knowledge and tools for LLMs."
requires-python = ">=3.7"
readme = "README.md"
Expand Down

0 comments on commit 083ee0a

Please sign in to comment.