Update app.py
Browse files
app.py
CHANGED
@@ -29,8 +29,7 @@ from pydantic import BaseModel, Field
|
|
29 |
import litellm
|
30 |
from langchain.tools import Tool
|
31 |
|
32 |
-
|
33 |
-
os.environ["LITELLM_MODEL_DEFAULT_PROVIDER"] = "gemini"
|
34 |
|
35 |
# Configure logging
|
36 |
logging.basicConfig(level=logging.INFO)
|
@@ -62,7 +61,7 @@ if 'board_plan_generated' not in st.session_state:
|
|
62 |
# Load environment variables
|
63 |
#load_dotenv()
|
64 |
|
65 |
-
|
66 |
|
67 |
|
68 |
# Page title and description
|
@@ -73,6 +72,7 @@ st.write("Developed for BIA 568 (Business Intelligence and Analytics) -- Managem
|
|
73 |
st.write("---")
|
74 |
|
75 |
# Sidebar for API key configuration
|
|
|
76 |
with st.sidebar:
|
77 |
st.title("⚙️ Configuration")
|
78 |
|
@@ -81,7 +81,17 @@ with st.sidebar:
|
|
81 |
if api_key:
|
82 |
os.environ["GEMINI_API_KEY"] = api_key
|
83 |
os.environ["GOOGLE_API_KEY"] = api_key
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
st.divider()
|
87 |
|
@@ -393,10 +403,13 @@ class SectionContent(BaseModel):
|
|
393 |
class CaseBreakdownCrew:
|
394 |
def __init__(self, api_key):
|
395 |
self.api_key = api_key
|
396 |
-
|
|
|
|
|
|
|
|
|
|
|
397 |
def create_metadata_agent(self):
|
398 |
-
self.api_key = api_key
|
399 |
-
self.llm = LLM(model='gemini/gemini-2.0-flash', api_key=self.api_key) # Create a Gemini LLM instance
|
400 |
return Agent(
|
401 |
role="Metadata Analyzer",
|
402 |
goal="Extract title and author information from document content",
|
@@ -404,11 +417,16 @@ class CaseBreakdownCrew:
|
|
404 |
such as titles, authors, and other publication information. You have a keen eye for
|
405 |
identifying the most important and relevant document metadata, even when it's not
|
406 |
explicitly labeled.""",
|
|
|
|
|
|
|
|
|
|
|
407 |
verbose=True
|
408 |
)
|
409 |
|
410 |
def create_content_generator_agent(self):
|
411 |
-
|
412 |
return Agent(
|
413 |
role="Case Study Content Generator",
|
414 |
goal="Generate comprehensive case analysis content based on section requirements",
|
@@ -416,11 +434,12 @@ class CaseBreakdownCrew:
|
|
416 |
You excel at breaking down complex business cases into structured, insightful content
|
417 |
that highlights key learning points, strategies, and insights. You have extensive experience
|
418 |
in business education and know how to create content that is valuable for teaching and learning.""",
|
|
|
419 |
verbose=True
|
420 |
)
|
421 |
|
422 |
def create_content_reviewer_agent(self):
|
423 |
-
|
424 |
return Agent(
|
425 |
role="Content Quality Reviewer",
|
426 |
goal="Evaluate and score content for quality, relevance, and depth",
|
@@ -428,6 +447,7 @@ class CaseBreakdownCrew:
|
|
428 |
business case studies and educational content. You have a strong understanding of what makes
|
429 |
effective case study material and can provide constructive feedback to improve content quality.
|
430 |
You carefully analyze content for relevance, clarity, depth, and educational value.""",
|
|
|
431 |
verbose=True
|
432 |
)
|
433 |
|
@@ -506,7 +526,6 @@ class CaseBreakdownCrew:
|
|
506 |
agents=[self.create_metadata_agent()],
|
507 |
tasks=[metadata_task],
|
508 |
process=Process.sequential,
|
509 |
-
llm=LLM(model='gemini/gemini-2.0-flash', api_key=self.api_key),
|
510 |
verbose=False
|
511 |
)
|
512 |
result = crew.kickoff()
|
@@ -603,17 +622,15 @@ def extract_text(file_path: str) -> str:
|
|
603 |
except Exception as e:
|
604 |
return f"Error extracting text: {str(e)}"
|
605 |
|
606 |
-
def create_teaching_plan_crew(file_paths
|
607 |
-
# Initialize
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
my_llm = LLM(model='gemini/gemini-2.0-flash',
|
613 |
-
api_key=os.environ.get("GEMINI_API_KEY")
|
614 |
)
|
615 |
|
616 |
-
#
|
617 |
pdf_analyzer = Agent(
|
618 |
role='Case Study Analyzer',
|
619 |
goal='Extract key concepts, objectives, and data from case study files',
|
@@ -707,9 +724,13 @@ class BoardPlanAnalyzer:
|
|
707 |
api_key = os.environ.get('GEMINI_API_KEY')
|
708 |
if not api_key:
|
709 |
raise ValueError("Gemini API key not found")
|
710 |
-
# Create an LLM instance configured for Gemini
|
711 |
-
self.llm = LLM(model='gemini/gemini-2.0-flash', api_key=api_key)
|
712 |
|
|
|
|
|
|
|
|
|
|
|
|
|
713 |
litellm.set_verbose = True
|
714 |
|
715 |
# Create agents
|
@@ -811,11 +832,13 @@ class BoardPlanAnalyzer:
|
|
811 |
|
812 |
try:
|
813 |
response = litellm.completion(
|
814 |
-
model=
|
815 |
messages=messages,
|
816 |
api_key=os.environ.get("GEMINI_API_KEY"),
|
|
|
817 |
response_format={"type": "json_object"}
|
818 |
)
|
|
|
819 |
|
820 |
# Extract and parse the JSON response
|
821 |
content = response.choices[0].message.content
|
|
|
29 |
import litellm
|
30 |
from langchain.tools import Tool
|
31 |
|
32 |
+
|
|
|
33 |
|
34 |
# Configure logging
|
35 |
logging.basicConfig(level=logging.INFO)
|
|
|
61 |
# Load environment variables
|
62 |
#load_dotenv()
|
63 |
|
64 |
+
|
65 |
|
66 |
|
67 |
# Page title and description
|
|
|
72 |
st.write("---")
|
73 |
|
74 |
# Sidebar for API key configuration
|
75 |
+
# In the sidebar section:
|
76 |
with st.sidebar:
|
77 |
st.title("⚙️ Configuration")
|
78 |
|
|
|
81 |
if api_key:
|
82 |
os.environ["GEMINI_API_KEY"] = api_key
|
83 |
os.environ["GOOGLE_API_KEY"] = api_key
|
84 |
+
os.environ["LITELLM_MODEL_DEFAULT_PROVIDER"] = "gemini"
|
85 |
+
|
86 |
+
# Configure litellm
|
87 |
+
litellm.set_verbose = True
|
88 |
+
litellm_config = {
|
89 |
+
"model": "gemini/gemini-2.0-flash",
|
90 |
+
"api_key": api_key,
|
91 |
+
"provider": "gemini"
|
92 |
+
}
|
93 |
+
|
94 |
+
|
95 |
|
96 |
st.divider()
|
97 |
|
|
|
403 |
class CaseBreakdownCrew:
|
404 |
def __init__(self, api_key):
|
405 |
self.api_key = api_key
|
406 |
+
self.llm = LLM(
|
407 |
+
model='gemini/gemini-2.0-flash',
|
408 |
+
api_key=self.api_key,
|
409 |
+
provider="gemini"
|
410 |
+
)
|
411 |
+
|
412 |
def create_metadata_agent(self):
|
|
|
|
|
413 |
return Agent(
|
414 |
role="Metadata Analyzer",
|
415 |
goal="Extract title and author information from document content",
|
|
|
417 |
such as titles, authors, and other publication information. You have a keen eye for
|
418 |
identifying the most important and relevant document metadata, even when it's not
|
419 |
explicitly labeled.""",
|
420 |
+
llm=LLM(
|
421 |
+
model='gemini/gemini-2.0-flash',
|
422 |
+
api_key=self.api_key,
|
423 |
+
provider="gemini"
|
424 |
+
),
|
425 |
verbose=True
|
426 |
)
|
427 |
|
428 |
def create_content_generator_agent(self):
|
429 |
+
|
430 |
return Agent(
|
431 |
role="Case Study Content Generator",
|
432 |
goal="Generate comprehensive case analysis content based on section requirements",
|
|
|
434 |
You excel at breaking down complex business cases into structured, insightful content
|
435 |
that highlights key learning points, strategies, and insights. You have extensive experience
|
436 |
in business education and know how to create content that is valuable for teaching and learning.""",
|
437 |
+
llm=self.llm,
|
438 |
verbose=True
|
439 |
)
|
440 |
|
441 |
def create_content_reviewer_agent(self):
|
442 |
+
|
443 |
return Agent(
|
444 |
role="Content Quality Reviewer",
|
445 |
goal="Evaluate and score content for quality, relevance, and depth",
|
|
|
447 |
business case studies and educational content. You have a strong understanding of what makes
|
448 |
effective case study material and can provide constructive feedback to improve content quality.
|
449 |
You carefully analyze content for relevance, clarity, depth, and educational value.""",
|
450 |
+
llm=self.llm,
|
451 |
verbose=True
|
452 |
)
|
453 |
|
|
|
526 |
agents=[self.create_metadata_agent()],
|
527 |
tasks=[metadata_task],
|
528 |
process=Process.sequential,
|
|
|
529 |
verbose=False
|
530 |
)
|
531 |
result = crew.kickoff()
|
|
|
622 |
except Exception as e:
|
623 |
return f"Error extracting text: {str(e)}"
|
624 |
|
625 |
+
def create_teaching_plan_crew(file_paths):
|
626 |
+
# Initialize LLM
|
627 |
+
my_llm = LLM(
|
628 |
+
model='gemini/gemini-2.0-flash',
|
629 |
+
api_key=os.environ.get("GEMINI_API_KEY"),
|
630 |
+
provider="gemini"
|
|
|
|
|
631 |
)
|
632 |
|
633 |
+
# Create agents with Gemini configuration
|
634 |
pdf_analyzer = Agent(
|
635 |
role='Case Study Analyzer',
|
636 |
goal='Extract key concepts, objectives, and data from case study files',
|
|
|
724 |
api_key = os.environ.get('GEMINI_API_KEY')
|
725 |
if not api_key:
|
726 |
raise ValueError("Gemini API key not found")
|
|
|
|
|
727 |
|
728 |
+
self.llm = LLM(
|
729 |
+
model='gemini/gemini-2.0-flash',
|
730 |
+
api_key=api_key,
|
731 |
+
provider="gemini"
|
732 |
+
)
|
733 |
+
|
734 |
litellm.set_verbose = True
|
735 |
|
736 |
# Create agents
|
|
|
832 |
|
833 |
try:
|
834 |
response = litellm.completion(
|
835 |
+
model="gemini/gemini-2.0-flash",
|
836 |
messages=messages,
|
837 |
api_key=os.environ.get("GEMINI_API_KEY"),
|
838 |
+
provider="gemini",
|
839 |
response_format={"type": "json_object"}
|
840 |
)
|
841 |
+
|
842 |
|
843 |
# Extract and parse the JSON response
|
844 |
content = response.choices[0].message.content
|