Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 162 additions & 0 deletions AI Twitter Manager/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
7 changes: 7 additions & 0 deletions AI Twitter Manager/.streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[theme]

primaryColor="#F63366"
backgroundColor="#1DA1F2"
secondaryBackgroundColor="#F0F2F6"
textColor="#000"
font="sans serif"
69 changes: 69 additions & 0 deletions AI Twitter Manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Lyzr Twitter Agent

A **Streamlit** application powered by **Lyzr Agent API** and **OpenAI** that allows users to research topics by sending queries to the Lyzr API, which then processes the requests and returns responses using a large language model.

## Features

- User-friendly text input interface for querying the Lyzr API.
- Streamlit interface with wide layout and responsive columns for input and output.
- Integrates **OpenAI** and **Lyzr APIs** for query handling and task completion.
- Displays research status and final results within the Streamlit app.

## Prerequisites

Before you begin, ensure you have met the following requirements:

- Python 3.7+
- Streamlit installed (`pip install streamlit`)
- Lyzr Agent installed (`pip install lyzr-agent`)
- A valid OpenAI API key and Lyzr API key

## Installation

1. **Clone the repository**:

```bash
git clone https://github.com/harshit-lyzr/auto_tweet.git
cd lyzr-twitter-agent
```

2. **Install dependencies**:

Make sure you have Python and pip installed. Then, run:

```bash
pip install -r requirements.txt
```

3. **Set up environment variables**:

Create a `.env` file in the root directory of the project and add your OpenAI and Lyzr API keys:

```bash
OPENAI_API_KEY=your_openai_api_key
LYZR_API_KEY=your_lyzr_api_key
```

4. **Run the Streamlit app**:

Launch the application using Streamlit:

```bash
streamlit run app.py
```

## Usage

1. Open the app in your browser (typically, it will open automatically at `http://localhost:8501`).
2. Enter your query in the "Enter Text Here" text box on the left-hand side.
3. Click the **Generate** button to send your query.
4. Wait for the response to be generated. The response will appear on the right-hand side under **Response**.

## Project Structure

```plaintext
.
├── .env # API keys for OpenAI and Lyzr
├── app.py # Main application code
├── requirements.txt # Python dependencies
└── README.md # This readme file
55 changes: 55 additions & 0 deletions AI Twitter Manager/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
from lyzr_agent import LyzrAgent
import streamlit as st
from dotenv import load_dotenv

# Load environment variables
load_dotenv()
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
LYZR_API_KEY = os.getenv("LYZR_API_KEY")
AGENT_ID = os.getenv("AGENT_ID")

# Streamlit page configuration
st.set_page_config(
page_title="Lyzr Twitter Agent",
layout="wide", # Set the layout to wide
initial_sidebar_state="auto",
page_icon="lyzr-logo-cut.png",
)


# Set up two columns for input and output areas
col1, col2 = st.columns([1, 1]) # Adjust the ratio to match the design in the image

with col1:
st.markdown("## Lyzr Twitter Agent")

# Input area for the query
query = st.text_area("Enter Text Here", height=150)

# Generate button
if st.button("Generate"):
if query.strip():
with st.spinner("🕵🏼‍Researching About Your Topic..."):
# Initialize the LyzrAgent
Agent = LyzrAgent(api_key=LYZR_API_KEY, llm_api_key=OPENAI_API_KEY)
with st.spinner("⚙️Executing Your Tasks...."):
response = Agent.send_message(
agent_id=AGENT_ID,
user_id="7422",
session_id="IITV",
message=query
)
st.markdown("🤯Research Completed")
st.markdown("✅Your Task Is Completed")

# Display the response in the second column
with col2:
st.markdown("## Response:")
st.markdown(f"**Thoughts:**\n\n{response}")
else:
st.warning("Please provide Text")

# Optional footer
st.markdown("---")
st.markdown("Powered by Lyzr and OpenAI")
89 changes: 89 additions & 0 deletions AI Twitter Manager/lyzr_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import requests
import json
from dotenv import load_dotenv
import os

load_dotenv()
LYZR_URL = os.getenv("LYZR_URL")

class LyzrAgent:
def __init__(self, api_key, llm_api_key):
self.url = str(LYZR_URL)
self.headers = {
"accept": "application/json",
"x-api-key": api_key
}
self.llm_api_key = llm_api_key

def create_environment(self, name, features, tools):
payload = json.dumps({
"name": name,
"features": features,
"tools": tools,
"llm_api_key": self.llm_api_key
})

url = self.url + "environment"

response = requests.post(url, headers=self.headers, data=payload)

if response.status_code == 200:
return response.json()
else:
print(f"Error: {response.status_code} - {response.text}")
return None

def create_agent(self, env_id, system_prompt, name):
payload = json.dumps({
"env_id": env_id,
"system_prompt": system_prompt,
"name": name,
"agent_persona": "",
"agent_instructions": "",
"agent_description": ""
})

url = self.url + "agent"

response = requests.post(url, headers=self.headers, data=payload)

if response.status_code == 200:
return response.json()
else:
print(f"Error: {response.status_code} - {response.text}")
return None

def send_message(self, agent_id, user_id, session_id, message):
payload = json.dumps({
"user_id": user_id,
"agent_id": agent_id,
"session_id": session_id,
"message": message
})

url = self.url + "chat/"

response = requests.post(url, headers=self.headers, data=payload)

if response.status_code == 200:
return response.json()
else:
print(f"Error: {response.status_code} - {response.text}")
return None

def create_task(self, agent_id, session_id, input_message):
payload = json.dumps({
"agent_id": agent_id,
"session_id": session_id,
"input": input_message
})

url = self.url + "task"

response = requests.post(url, headers=self.headers, data=payload)

if response.status_code == 200:
return response.json()
else:
print(f"Error: {response.status_code} - {response.text}")
return None
2 changes: 2 additions & 0 deletions AI Twitter Manager/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
streamlit
python-dotenv
Loading