Merge branch 'kyegomez:master' into master

pull/849/head
Pavan Kumar 3 weeks ago committed by GitHub
commit cd074d0f6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,13 @@
from swarms.structs.agent import Agent
agent = Agent(
agent_name="Financial-Analysis-Agent",
agent_description="Personal finance advisor agent",
max_loops=4,
model_name="cerebras/llama3-70b-instruct",
dynamic_temperature_enabled=True,
interactive=False,
output_type="all",
)
agent.run("Conduct an analysis of the best real undervalued ETFs")

@ -347,6 +347,7 @@ nav:
- OpenAIChat: "swarms/models/openai.md"
- OpenAIFunctionCaller: "swarms/models/openai_function_caller.md"
- Groq: "swarms/models/groq.md"
- Cerebras: "swarms/models/cerebras.md"
- MultiModal Models:
- BaseMultiModalModel: "swarms/models/base_multimodal_model.md"
- Multi Modal Models Available: "swarms/models/multimodal_models.md"

@ -0,0 +1,89 @@
# Using Cerebras LLaMA with Swarms
This guide demonstrates how to create and use an AI agent powered by the Cerebras LLaMA 3 70B model using the Swarms framework.
## Prerequisites
- Python 3.7+
- Swarms library installed (`pip install swarms`)
- Set your ENV key `CEREBRAS_API_KEY`
## Step-by-Step Guide
### 1. Import Required Module
```python
from swarms.structs.agent import Agent
```
This imports the `Agent` class from Swarms, which is the core component for creating AI agents.
### 2. Create an Agent Instance
```python
agent = Agent(
agent_name="Financial-Analysis-Agent",
agent_description="Personal finance advisor agent",
max_loops=4,
model_name="cerebras/llama3-70b-instruct",
dynamic_temperature_enabled=True,
interactive=False,
output_type="all",
)
```
Let's break down each parameter:
- `agent_name`: A descriptive name for your agent (here, "Financial-Analysis-Agent")
- `agent_description`: A brief description of the agent's purpose
- `max_loops`: Maximum number of interaction loops the agent can perform (set to 4)
- `model_name`: Specifies the Cerebras LLaMA 3 70B model to use
- `dynamic_temperature_enabled`: Enables dynamic adjustment of temperature for varied responses
- `interactive`: When False, runs without requiring user interaction
- `output_type`: Set to "all" to return complete response information
### 3. Run the Agent
```python
agent.run("Conduct an analysis of the best real undervalued ETFs")
```
This command:
1. Activates the agent
2. Processes the given prompt about ETF analysis
3. Returns the analysis based on the model's knowledge
## Notes
- The Cerebras LLaMA 3 70B model is a powerful language model suitable for complex analysis tasks
- The agent can be customized further with additional parameters
- The `max_loops=4` setting prevents infinite loops while allowing sufficient processing depth
- Setting `interactive=False` makes the agent run autonomously without user intervention
## Example Output
The agent will provide a detailed analysis of undervalued ETFs, including:
- Market analysis
- Performance metrics
- Risk assessment
- Investment recommendations
Note: Actual output will vary based on current market conditions and the model's training data.

@ -0,0 +1,249 @@
"""
- For each diagnosis, pull lab results,
- egfr
- for each diagnosis, pull lab ranges,
- pull ranges for diagnosis
- if the diagnosis is x, then the lab ranges should be a to b
- train the agents, increase the load of input
- medical history sent to the agent
- setup rag for the agents
- run the first agent -> kidney disease -> don't know the stage -> stage 2 -> lab results -> indicative of stage 3 -> the case got elavated ->
- how to manage diseases and by looking at correlating lab, docs, diagnoses
- put docs in rag ->
- monitoring, evaluation, and treatment
- can we confirm for every diagnosis -> monitoring, evaluation, and treatment, specialized for these things
- find diagnosis -> or have diagnosis, -> for each diagnosis are there evidence of those 3 things
- swarm of those 4 agents, ->
- fda api for healthcare for commerically available papers
-
"""
from datetime import datetime
from swarms import Agent, AgentRearrange, create_file_in_folder
chief_medical_officer = Agent(
agent_name="Chief Medical Officer",
system_prompt="""You are the Chief Medical Officer coordinating a team of medical specialists for viral disease diagnosis.
Your responsibilities include:
- Gathering initial patient symptoms and medical history
- Coordinating with specialists to form differential diagnoses
- Synthesizing different specialist opinions into a cohesive diagnosis
- Ensuring all relevant symptoms and test results are considered
- Making final diagnostic recommendations
- Suggesting treatment plans based on team input
- Identifying when additional specialists need to be consulted
- For each diferrential diagnosis provide minimum lab ranges to meet that diagnosis or be indicative of that diagnosis minimum and maximum
Format all responses with clear sections for:
- Initial Assessment (include preliminary ICD-10 codes for symptoms)
- Differential Diagnoses (with corresponding ICD-10 codes)
- Specialist Consultations Needed
- Recommended Next Steps
""",
model_name="gpt-4o-mini",
max_loops=1,
)
virologist = Agent(
agent_name="Virologist",
system_prompt="""You are a specialist in viral diseases. For each case, provide:
Clinical Analysis:
- Detailed viral symptom analysis
- Disease progression timeline
- Risk factors and complications
Coding Requirements:
- List relevant ICD-10 codes for:
* Confirmed viral conditions
* Suspected viral conditions
* Associated symptoms
* Complications
- Include both:
* Primary diagnostic codes
* Secondary condition codes
Document all findings using proper medical coding standards and include rationale for code selection.""",
model_name="gpt-4o-mini",
max_loops=1,
)
internist = Agent(
agent_name="Internist",
system_prompt="""You are an Internal Medicine specialist responsible for comprehensive evaluation.
For each case, provide:
Clinical Assessment:
- System-by-system review
- Vital signs analysis
- Comorbidity evaluation
Medical Coding:
- ICD-10 codes for:
* Primary conditions
* Secondary diagnoses
* Complications
* Chronic conditions
* Signs and symptoms
- Include hierarchical condition category (HCC) codes where applicable
Document supporting evidence for each code selected.""",
model_name="gpt-4o-mini",
max_loops=1,
)
medical_coder = Agent(
agent_name="Medical Coder",
system_prompt="""You are a certified medical coder responsible for:
Primary Tasks:
1. Reviewing all clinical documentation
2. Assigning accurate ICD-10 codes
3. Ensuring coding compliance
4. Documenting code justification
Coding Process:
- Review all specialist inputs
- Identify primary and secondary diagnoses
- Assign appropriate ICD-10 codes
- Document supporting evidence
- Note any coding queries
Output Format:
1. Primary Diagnosis Codes
- ICD-10 code
- Description
- Supporting documentation
2. Secondary Diagnosis Codes
- Listed in order of clinical significance
3. Symptom Codes
4. Complication Codes
5. Coding Notes""",
model_name="gpt-4o-mini",
max_loops=1,
)
synthesizer = Agent(
agent_name="Diagnostic Synthesizer",
system_prompt="""You are responsible for creating the final diagnostic and coding assessment.
Synthesis Requirements:
1. Integrate all specialist findings
2. Reconcile any conflicting diagnoses
3. Verify coding accuracy and completeness
Final Report Sections:
1. Clinical Summary
- Primary diagnosis with ICD-10
- Secondary diagnoses with ICD-10
- Supporting evidence
2. Coding Summary
- Complete code list with descriptions
- Code hierarchy and relationships
- Supporting documentation
3. Recommendations
- Additional testing needed
- Follow-up care
- Documentation improvements needed
Include confidence levels and evidence quality for all diagnoses and codes.""",
model_name="gpt-4o-mini",
max_loops=1,
)
# Create agent list
agents = [
chief_medical_officer,
virologist,
internist,
medical_coder,
synthesizer,
]
# Define diagnostic flow
flow = f"""{chief_medical_officer.agent_name} -> {virologist.agent_name} -> {internist.agent_name} -> {medical_coder.agent_name} -> {synthesizer.agent_name}"""
# Create the swarm system
diagnosis_system = AgentRearrange(
name="Medical-coding-diagnosis-swarm",
description="Comprehensive medical diagnosis and coding system",
agents=agents,
flow=flow,
max_loops=1,
output_type="all",
)
def generate_coding_report(diagnosis_output: str) -> str:
"""
Generate a structured medical coding report from the diagnosis output.
"""
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
report = f"""# Medical Diagnosis and Coding Report
Generated: {timestamp}
## Clinical Summary
{diagnosis_output}
## Coding Summary
### Primary Diagnosis Codes
[Extracted from synthesis]
### Secondary Diagnosis Codes
[Extracted from synthesis]
### Symptom Codes
[Extracted from synthesis]
### Procedure Codes (if applicable)
[Extracted from synthesis]
## Documentation and Compliance Notes
- Code justification
- Supporting documentation references
- Any coding queries or clarifications needed
## Recommendations
- Additional documentation needed
- Suggested follow-up
- Coding optimization opportunities
"""
return report
if __name__ == "__main__":
# Example patient case
patient_case = """
Patient: 45-year-old White Male
Lab Results:
- egfr
- 59 ml / min / 1.73
- non african-american
"""
# Add timestamp to the patient case
case_info = f"Timestamp: {datetime.now()}\nPatient Information: {patient_case}"
# Run the diagnostic process
diagnosis = diagnosis_system.run(case_info)
# Generate coding report
coding_report = generate_coding_report(diagnosis)
# Create reports
create_file_in_folder(
"reports", "medical_diagnosis_report.md", diagnosis
)
create_file_in_folder(
"reports", "medical_coding_report.md", coding_report
)

@ -24,9 +24,6 @@ from datetime import datetime
from swarms import Agent, AgentRearrange, create_file_in_folder
from swarm_models import OllamaModel
model = OllamaModel(model_name="llama3.2")
chief_medical_officer = Agent(
agent_name="Chief Medical Officer",
@ -49,7 +46,7 @@ chief_medical_officer = Agent(
""",
llm=model,
model_name="ollama/llama3.2",
max_loops=1,
)
@ -73,7 +70,7 @@ virologist = Agent(
* Secondary condition codes
Document all findings using proper medical coding standards and include rationale for code selection.""",
llm=model,
model_name="ollama/llama3.2",
max_loops=1,
)
@ -98,7 +95,7 @@ internist = Agent(
- Include hierarchical condition category (HCC) codes where applicable
Document supporting evidence for each code selected.""",
llm=model,
model_name="ollama/llama3.2",
max_loops=1,
)
@ -129,7 +126,7 @@ medical_coder = Agent(
3. Symptom Codes
4. Complication Codes
5. Coding Notes""",
llm=model,
model_name="ollama/llama3.2",
max_loops=1,
)
@ -157,7 +154,7 @@ synthesizer = Agent(
- Documentation improvements needed
Include confidence levels and evidence quality for all diagnoses and codes.""",
llm=model,
model_name="ollama/llama3.2",
max_loops=1,
)

@ -279,7 +279,6 @@ class Agent:
def __init__(
self,
agent_id: Optional[str] = agent_id(),
id: Optional[str] = agent_id(),
llm: Optional[Any] = None,
template: Optional[str] = None,
@ -403,7 +402,6 @@ class Agent:
**kwargs,
):
# super().__init__(*args, **kwargs)
self.agent_id = agent_id
self.id = id
self.llm = llm
self.template = template
@ -2270,7 +2268,7 @@ class Agent:
time=time.time(),
tokens=total_tokens,
response=AgentChatCompletionResponse(
id=self.agent_id,
id=self.id,
agent_name=self.agent_name,
object="chat.completion",
choices=ChatCompletionResponseChoice(

Loading…
Cancel
Save