Spaces:
Sleeping
Sleeping
File size: 4,468 Bytes
c3fde59 5c01b9f 97379bb 5c01b9f c3fde59 5c01b9f e0cc561 5c01b9f e0cc561 99ceb1b e0cc561 5c01b9f 7d3c11f c3fde59 5c01b9f e0cc561 99ceb1b e0cc561 f63d1d2 6570d62 5c01b9f c3fde59 5c01b9f c3fde59 5c01b9f c3fde59 5c01b9f c3fde59 5c01b9f c3fde59 5c01b9f 7d3c11f 5c01b9f c3fde59 5c01b9f 7d3c11f c3fde59 5c01b9f 97379bb c3fde59 97379bb 7d3c11f 97379bb 5c01b9f c3fde59 5c01b9f |
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 |
# Koyeb Agent.py
import streamlit as st
import os
from smolagents import (
CodeAgent,
ToolCallingAgent,
HfApiModel,
DuckDuckGoSearchTool,
LiteLLMModel,
tool,
VisitWebpageTool,
GradioUI,
PythonInterpreterTool
)
import requests
import json
from typing import List, Dict, Any
# Configuration
PAGE_CONFIG = {
"page_title": "Koyeb Documentation Search",
"page_icon": "π",
"layout": "wide"
}
AUTHORIZED_IMPORTS = [
"requests", "os", "pandas", "markdownify", "numpy", "sympy", "json", "bs4",
"pubchempy", "xml", "yahoo_finance", "Bio", "sklearn", "scipy", "pydub",
"io", "PIL", "chess", "PyPDF2", "pptx", "torch", "datetime", "fractions",
"csv", "huggingface_hub"
]
# Model configuration
MODEL_CONFIGS = {
"nano": {
"model_id": "openrouter/openai/gpt-4.1-nano",
"temperature": 0.6
},
"dolphin": {
"model_id": "openrouter/cognitivecomputations/dolphin3.0-r1-mistral-24b:free",
"temperature": 0.5
}
}
# Agent Initialization
def initialize_koyeb_agent(model=None):
"""Initialize the Koyeb Documentation Agent"""
tools = [
DuckDuckGoSearchTool(),
VisitWebpageTool()
]
if model is None:
from smolagents import HfApiModel
model = LiteLLMModel(
model_id=MODEL_CONFIGS["nano"]["model_id"],
api_key=os.environ["OPENROUTER_API_KEY"],
temperature=MODEL_CONFIGS["nano"]["temperature"]
)
return CodeAgent(
name="koyeb_agent",
description="Koyeb Documentation AI Agent",
tools=tools,
model=model,
max_steps=12,
additional_authorized_imports=AUTHORIZED_IMPORTS
)
# UI Components
def setup_ui():
"""Setup Streamlit UI components"""
st.set_page_config(**PAGE_CONFIG)
st.title("π» Koyeb Documentation Search")
st.markdown("""
This tool uses an AI agent to help you explore Koyeb documentation.
Ask questions about Koyeb features, usage, or troubleshooting.
""")
def display_results(results: str):
"""Display search results in a formatted way"""
st.markdown("### π Results")
st.markdown(results, unsafe_allow_html=True)
def setup_sidebar():
"""Setup sidebar content"""
with st.sidebar:
st.markdown("### About This Tool")
st.markdown("""
This agent specializes in Koyeb documentation, providing:
- π Quick answers from web searches
- π Webpage content retrieval
- π€ AI-powered insights
""")
st.markdown("### Tips")
st.markdown("""
- Use specific queries like "How to install Koyeb cli" or "Koyeb deepseek model deployment".
- Results may include raw data from searches or webpages.
""")
# Main App
@st.cache_resource
def initialize_app():
"""Initialize the application"""
return initialize_koyeb_agent()
def main():
setup_ui()
setup_sidebar()
if 'agent' not in st.session_state:
with st.spinner("Initializing Koyeb Documentation Agent..."):
st.session_state.agent = initialize_app()
search_query = st.text_input(
"π Search Koyeb Documentation",
placeholder="E.g., How to use Terraform with the koyeb provider ?"
)
# Single button to handle both cases
if st.button("Search", type="primary", key="search_button"):
if search_query:
with st.spinner("Searching Koyeb documentation..."):
try:
results = st.session_state.agent.run(search_query, additional_args={"reference_websites": ['https://www.koyeb.com/docs', 'https://www.koyeb.com/tutorials', 'https://www.koyeb.com/deploy'],"instructions": "Response to the user answer as a structured markdown documentation format."})
display_results(results)
st.markdown("---")
st.info("""
π‘ **How to read the results:**
- Results may include JSON from searches or webpage snippets.
- Check the sidebar for tips on refining your query.
""")
except Exception as e:
st.error(f"An error occurred: {e}")
else:
st.warning("Please enter a search query.")
st.markdown("---")
st.caption("Powered by SmolAgents and Koyeb")
if __name__ == "__main__":
main() |