-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63859b6
commit d254514
Showing
7 changed files
with
121 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
from phi.api.schemas.ai import ConversationType | ||
from phi.cli.config import PhiCliConfig | ||
from phi.workspace.config import WorkspaceConfig | ||
|
||
|
||
def phi_ai_conversation( | ||
phi_config: PhiCliConfig, | ||
start_new_conversation: bool = False, | ||
show_previous_messages: bool = False, | ||
autonomous_conversation: bool = True, | ||
print_conversation_history: bool = False, | ||
stream: bool = False, | ||
) -> None: | ||
"""Start a conversation with Phi AI.""" | ||
|
||
from phi.ai.phi_ai import PhiAI | ||
|
||
ai = PhiAI(new_conversation=start_new_conversation, phi_config=phi_config) | ||
if show_previous_messages: | ||
conversation_type = ConversationType.AUTO if autonomous_conversation else ConversationType.RAG | ||
ai = PhiAI(new_conversation=start_new_conversation, conversation_type=conversation_type, phi_config=phi_config) | ||
if print_conversation_history: | ||
ai.print_conversation_history() | ||
|
||
ai.start_conversation(stream=stream) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing import List | ||
|
||
from phi.llm.function.registry import FunctionRegistry | ||
from phi.utils.log import logger | ||
|
||
|
||
class ShellScriptsRegistry(FunctionRegistry): | ||
def __init__(self): | ||
super().__init__(name="shell_script_registry") | ||
self.register(self.run_shell_command) | ||
|
||
def run_shell_command(self, args: List[str]) -> str: | ||
"""Runs a shell command and returns the output or error. | ||
:param args: The command to run as a list of strings. | ||
:return: The output of the command. | ||
""" | ||
logger.info(f"Running shell command: {args}") | ||
|
||
import subprocess | ||
|
||
result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
|
||
logger.debug("Return code:", result.returncode) | ||
logger.debug("Have {} bytes in stdout:\n{}".format(len(result.stdout), result.stdout.decode())) | ||
logger.debug("Have {} bytes in stderr:\n{}".format(len(result.stderr), result.stderr.decode())) | ||
|
||
if result.returncode != 0: | ||
return f"error: {result.stderr.decode()}" | ||
return result.stdout.decode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters