Spaces:
Sleeping
Sleeping
File size: 4,929 Bytes
4253992 0ad63e8 e243aad 4253992 db8c25e 9a83e6f 4253992 0ad63e8 ebd164a 9c27d01 0ad63e8 db8c25e ebd164a 0ad63e8 9c27d01 9a83e6f 4253992 bd29fe6 4253992 ebd164a 4253992 ebd164a 4253992 88768f4 4253992 e243aad ebd164a f2e9400 e243aad f2e9400 e243aad f2e9400 e243aad f2e9400 e243aad 4253992 e243aad db8c25e ebd164a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
import streamlit as st
from openai import OpenAI
from dotenv import load_dotenv
import os
import requests
import hashlib
from git import Repo, exc
from crewai import Agent, Task, Crew
from langchain.tools import tool
# Load the OpenAI API key from the .env file
load_dotenv()
os.environ["OPENAI_API_KEY"] = userdata.get('OPENAI_API_KEY')
GITHUB_ACCESS_TOKEN = userdata.get('GITHUB_ACCESS_TOKEN')
# Initialize the OpenAI client
openai_client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
def check_for_updates(repo_path, remote_name='origin', branch='main'):
"""
Check for updates in the specified Git repository using GitPython.
Input: repo_path - Path to the local git repository.
Output: A string indicating if updates are available or not.
"""
try:
# Open the existing repository
repo = Repo(repo_path)
if repo.bare:
raise Exception("Repository is bare.")
# Fetch updates from the remote repository
remote = repo.remotes[remote_name]
fetch_info = remote.fetch()
# Compare local and remote branches
local_commit = repo.heads[branch].commit
remote_commit = repo.refs[f'refs/remotes/{remote_name}/{branch}'].commit
if local_commit.hexsha != remote_commit.hexsha:
return "Updates are available."
else:
return "No updates available."
except exc.InvalidGitRepositoryError:
return "Invalid Git repository."
except Exception as e:
return f"Error: {str(e)}"
# Example usage
# repo_path = "/path/to/your/streamlit-repo"
# print(check_for_updates(repo_path))
# Define the custom tool for GitHub interaction
@tool
def github_streamlit_expert() -> str:
"""
Interacts with the GitHub API to check for updates in the Streamlit repository.
Output: Summary of recent changes or a message indicating no updates.
"""
# Here, you'll implement the logic to interact with the GitHub API
# and summarize the latest changes in the Streamlit repository.
# This is a placeholder implementation.
return "Checked GitHub. No new updates." # Replace with actual implementation.
# Define the custom tool for checking Streamlit documentation updates
@tool
def check_streamlit_updates(previous_hash: str) -> str:
"""
Checks for updates in the Streamlit documentation.
Input: previous_hash - The hash of the previously known state of the documentation.
Output: A tuple containing a message indicating update status and the new hash.
"""
doc_url = 'https://docs.streamlit.io/'
response = requests.get(doc_url)
content = response.text
current_hash = hashlib.md5(content.encode()).hexdigest()
if current_hash != previous_hash:
return f'Updates found in Streamlit documentation. New Hash: {current_hash}', current_hash
else:
return 'No updates in Streamlit documentation.', current_hash
# Define the Streamlit Documentation and GitHub Expert agent
streamlit_expert = Agent(
role='Streamlit Documentation and GitHub Expert',
goal='Stay updated with the latest Streamlit documentation and GitHub repository changes',
backstory='An AI agent specialized in monitoring and reporting the latest changes in Streamlit documentation and repository.',
tools=[check_streamlit_updates, github_streamlit_expert],
verbose=True
)
# Define a task for checking updates
update_task = Task(
description='Check for updates in the Streamlit documentation.',
agent=streamlit_expert
)
# Define a crew with the Streamlit Documentation Expert
crew = Crew(
agents=[streamlit_expert],
tasks=[update_task],
verbose=True
)
# Streamlit app setup
# Initialize a list to store chat history
chat_history = []
# Streamlit app setup
st.title('CrewAI Streamlit Expert - Chat Interface')
# Chat input
user_query = st.text_input("Your question:", key="user_input")
if st.button("Ask"):
# Create a task for the streamlit_expert
user_task = Task(description=user_query, agent=streamlit_expert)
# Add the task to crew and kickoff
crew.tasks.append(user_task)
response = crew.kickoff()
# Update chat history
chat_history.append(f"You: {user_query}")
chat_history.append(f"Streamlit Expert: {response}")
# Display chat history
for chat in chat_history:
st.text(chat)
# Button to check for updates in the Streamlit GitHub repository
if st.button('Check for Streamlit GitHub Updates'):
repo_path = "/path/to/your/streamlit-repo" # Path to your local Streamlit repository
update_status = check_for_updates(repo_path)
st.write(update_status)
if "Updates are available" in update_status:
pass
# Optionally, trigger further actions like updating the local repo or analyzing changes
# For example:
# response = analyze_new_changes(repo_path)
# st.write(response)
|