This repository has been archived on 2024-08-28. You can view files and clone it, but cannot push or open issues or pull requests.
crew-ai-codecollection/crew-code-interpreter.py

93 lines
2.4 KiB
Python
Raw Normal View History

2024-04-05 13:07:14 +00:00
import os
2024-03-27 18:09:10 +00:00
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
2024-04-05 13:07:14 +00:00
gpt4turbo = ChatOpenAI(model_name="gpt-4-turbo-preview", temperature=0.8)
2024-03-27 18:09:10 +00:00
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],
2024-04-05 13:07:14 +00:00
llm=gpt4turbo,
2024-03-27 18:09:10 +00:00
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,
2024-04-05 13:07:14 +00:00
manager_llm=gpt4turbo
2024-03-27 18:09:10 +00:00
)
# 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,
2024-04-05 13:07:14 +00:00
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."),
2024-03-27 18:09:10 +00:00
outputs="text",
title="CLI Command Executor",
description="Execute CLI commands via a natural language interface."
)
iface.launch()