Skip to content

Instantly share code, notes, and snippets.

az_client = AsyncOpenAI(
api_key=os.environ.get("AZURE_OPEN_AI_API_KEY_SWEDEN"), # Use your OpenAI API key
base_url=os.environ.get("AZURE_OPEN_AI_API_ENDPOINT_SWEDEN"),
)
gpt_model_client = AzureOpenAIChatCompletionClient(
model="gpt-4.1-mini-2025-04-14",
api_version="2024-06-01",
azure_deployment="gpt-4.1-mini",
azure_endpoint=os.environ.get("AZURE_OPEN_AI_API_ENDPOINT_SWEDEN"),
@pavlovmilen
pavlovmilen / upload_ai_report.py
Created May 13, 2025 08:20
upload_ai_report function
import os
from azure.storage.blob import BlobServiceClient
from datetime import datetime
from dotenv import load_dotenv
load_dotenv()
connection_string = os.getenv('storage_connection_string')
def upload_ai_report(report_summary: str, ticker: str):
"""
@pavlovmilen
pavlovmilen / complete_example.py
Created May 11, 2025 10:44
complete_example.py
import os
import sys
from dotenv import load_dotenv
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.base import TaskResult
from autogen_agentchat.conditions import MaxMessageTermination, TextMentionTermination
from autogen_agentchat.messages import BaseChatMessage
from autogen_agentchat.teams import SelectorGroupChat
@pavlovmilen
pavlovmilen / market_research_team_run.py
Created May 11, 2025 10:38
market_research_team_run
runtime = SingleThreadedAgentRuntime()
runtime.start()
message_count = 0
total_prompt_tokens = 0
total_completion_tokens = 0
async for message in market_reserarch_agents_team.run_stream(task="Hello, I would like to know if a stock with ticker=MSFT is a good pick for me to invest in this year?"):
if isinstance(message, TaskResult):
print("Stop Reason:", message.stop_reason)
gpt_model_client = AzureOpenAIChatCompletionClient(
model="gpt-4.1-mini-2025-04-14",
api_version="2024-06-01",
azure_deployment="gpt-4.1-mini",
azure_endpoint=os.environ.get("AZURE_OPEN_AI_API_ENDPOINT_SWEDEN"),
#azure_ad_token_provider=token_provider, # Optional if you choose key-based authentication.
api_key=os.environ.get("AZURE_OPEN_AI_API_KEY_SWEDEN"),
)
@pavlovmilen
pavlovmilen / market_reserarch_agents_team.py
Created May 11, 2025 10:33
market_reserarch_agents_team
market_reserarch_agents_team = SelectorGroupChat(
[planning_agent, doji_agent, alpha_vantage_news_sentiment_agent, alpha_vantage_company_info_agent, fomc_summary_fetch_agent, peer_valuation_modeling_agent, report_generator_agent, report_upload_agent],
termination_condition=termination,
allow_repeated_speaker=True,
model_client=gpt_model_client,
selector_prompt=selector_prompt)
selector_prompt = """Select an agent to perform task.
{roles}
Current conversation context:
{history}
Read the above conversation, then select an agent from {participants} to perform the next task.
Make sure the planner agent has assigned tasks before other agents start working.
Only select one agent at a time.
doji_tool = FunctionTool(get_finance_data, description="Download last 60 days of OHLCV data")
doji_agent = AssistantAgent(
name="doji_agent",
model_client=gpt_model_client,
description="Spot daily doji patterns",
system_message="""
You retrieve OHLCV data via doji_tool and detect doji candlesticks.
A daily bar is a doji when abs(Open – Close) ≤ 0.10 × (High – Low).
Steps: (1) call the tool, (2) run the test, (3) return a list of dates or an empty list if none.
Output strictly: comma-separated ISO dates. Provide explanations for the doji dates""",
planning_agent = AssistantAgent(
"PlanningAgent",
description="An agent for planning tasks, this agent should be the first to engage when given a new task.",
model_client=gpt_model_client,
system_message="""
You are a planning agent.
Your job is to break down complex tasks into smaller, manageable subtasks.
Your team members are:
doji_agent: Identify doji patterns in stock data using doji_tool
alpha_vantage_news_sentiment_agent: Search for a news sentiment about a stock using the search tool
@pavlovmilen
pavlovmilen / code.cs
Created November 26, 2024 10:51
Extract data and pass to LLM
// extract data as a string:
private string GetStringContentFromCrimeDataAIModel(List<CrimesAtLocationResponse> results, string postcode)
{
if(results == null || !results.Any())
{
return "No data found";
}
results = results.OrderBy(x => x.month).ToList();