93 lines
2.4 KiB
Python
93 lines
2.4 KiB
Python
import os
|
|
import subprocess
|
|
|
|
# packages = ["open-interpreter", "gradio"]
|
|
|
|
# for package in packages:
|
|
# subprocess.check_call(["pip", "install", package])
|
|
|
|
|
|
# Importieren Sie die erforderlichen Bibliotheken
|
|
import asyncio
|
|
import platform
|
|
|
|
if platform.system() == 'Windows':
|
|
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
|
|
|
|
|
# Environment Variablen importieren
|
|
from dotenv import load_dotenv
|
|
load_dotenv()
|
|
|
|
# CrewAI importieren
|
|
from crewai import Agent, Task, Crew, Process
|
|
|
|
# LLMs von OpenAI und Ollama importieren
|
|
from langchain_openai import ChatOpenAI
|
|
from langchain.tools import tool
|
|
# Interpreter importieren
|
|
from interpreter import interpreter
|
|
|
|
|
|
# Configurations and Tools
|
|
gpt4turbo = ChatOpenAI(model_name="gpt-4-turbo-preview", temperature=0.8)
|
|
interpreter.auto_run = True
|
|
interpreter.llm.model = "openai/gpt-4-turbo-preview"
|
|
interpreter.llm.temperature = 0.8
|
|
|
|
|
|
@tool('Executor')
|
|
def execute_cli_command(command: str):
|
|
"""Create and Execute the code using Open Interpreter"""
|
|
result = interpreter.chat(command)
|
|
return result
|
|
|
|
|
|
# Create an agent for the CLI tasks
|
|
|
|
cli_agent = Agent(
|
|
role='Software Developer',
|
|
goal='Helpfull Assistant. Ability to perform CLI operations, write programms and execute code using Executor Tool.',
|
|
backstory='Expert in command line operations and automating tasks.',
|
|
tools=[execute_cli_command],
|
|
llm=gpt4turbo,
|
|
deligate_tools=False,
|
|
verbose=True
|
|
)
|
|
|
|
cli_task = Task(
|
|
description='Identify the OS and empty my trash bin.',
|
|
expected_output='Log all actions und result of the code execution',
|
|
agent=cli_agent
|
|
)
|
|
|
|
# Create a crew for the CLI tasks
|
|
cli_crew = Crew(
|
|
name='CLI Crew',
|
|
agents=[cli_agent],
|
|
tasks=[cli_task],
|
|
process=Process.sequential,
|
|
manager_llm=gpt4turbo
|
|
)
|
|
|
|
# Run the crew in the CLI Interface
|
|
import gradio as gr
|
|
|
|
def cli_interface(command):
|
|
cli_task.description = command
|
|
result = cli_crew.kickoff()
|
|
return result
|
|
|
|
iface = gr.Interface(
|
|
fn=cli_interface,
|
|
inputs=gr.Textbox(lines=2, placeholder="Was soll ich tun?", value="Identifiziere das Betriebssystem, nutze F:\blog-posts als Arbeitsverzeichniss und generiere eine Markdown Datei mit dem Titel 'Test' und der Liste aller Dateien in diesem Verzeichniss als Inhalt."),
|
|
outputs="text",
|
|
title="CLI Command Executor",
|
|
description="Execute CLI commands via a natural language interface."
|
|
)
|
|
|
|
iface.launch()
|
|
|
|
|
|
|