Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
OPENAI_BASE_URL="https://generativelanguage.googleapis.com/v1beta/openai/"
OPENAI_API_KEY="..."

DEFAULT_PLANNER_MODEL="..."
DEFAULT_WORKER_MODEL="..."

# Embedding model
EMBEDDING_BASE_URL="https://..."
EMBEDDING_API_KEY="..."
EMBEDDING_MODEL_NAME="..."

# LangFuse
LANGFUSE_SECRET_KEY="sk-lf-..."
Expand All @@ -20,9 +24,11 @@ WEAVIATE_HTTP_PORT="443" # or 8080 for localhost
WEAVIATE_GRPC_PORT="443" # or 50051 for localhost
WEAVIATE_HTTP_SECURE="true" # set to false for localhost
WEAVIATE_GRPC_SECURE="true" # set to false for localhost
WEAVIATE_COLLECTION_NAME="..."

# Optionally, specify E2B.dev API key for Python Code Interpreter
E2B_API_KEY="e2b_..."
DEFAULT_CODE_INTERPRETER_TEMPLATE="..."

WEB_SEARCH_BASE_URL="..."
WEB_SEARCH_API_KEY="..."
4 changes: 2 additions & 2 deletions src/1_basics/0_search_demo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

load_dotenv(verbose=True)

configs = Configs.from_env_var()
configs = Configs()
async_weaviate_client = get_weaviate_async_client(
http_host=configs.weaviate_http_host,
http_port=configs.weaviate_http_port,
Expand All @@ -45,7 +45,7 @@
async_openai_client = AsyncOpenAI()
async_knowledgebase = AsyncWeaviateKnowledgeBase(
async_weaviate_client,
collection_name="enwiki_20250520",
collection_name=configs.weaviate_collection_name,
)


Expand Down
8 changes: 3 additions & 5 deletions src/1_basics/1_react_rag/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
load_dotenv(verbose=True)

MAX_TURNS = 5
AGENT_LLM_NAME = "gemini-2.5-flash"


tools: list["ChatCompletionToolParam"] = [
{
Expand Down Expand Up @@ -76,7 +74,7 @@ async def react_rag(query: str, history: list[ChatMessage]):

for _ in range(MAX_TURNS):
completion = await async_openai_client.chat.completions.create(
model=AGENT_LLM_NAME,
model=configs.default_planner_model,
messages=oai_messages,
tools=tools,
reasoning_effort=None,
Expand Down Expand Up @@ -140,7 +138,7 @@ async def react_rag(query: str, history: list[ChatMessage]):
)

if __name__ == "__main__":
configs = Configs.from_env_var()
configs = Configs()
async_weaviate_client = get_weaviate_async_client(
http_host=configs.weaviate_http_host,
http_port=configs.weaviate_http_port,
Expand All @@ -153,7 +151,7 @@ async def react_rag(query: str, history: list[ChatMessage]):
async_openai_client = AsyncOpenAI()
async_knowledgebase = AsyncWeaviateKnowledgeBase(
async_weaviate_client,
collection_name="enwiki_20250520",
collection_name=configs.weaviate_collection_name,
)

signal.signal(signal.SIGINT, _handle_sigint)
Expand Down
7 changes: 3 additions & 4 deletions src/1_basics/1_react_rag/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
load_dotenv(verbose=True)

MAX_TURNS = 5
AGENT_LLM_NAME = "gemini-2.5-flash"

tools: list["ChatCompletionToolParam"] = [
{
Expand All @@ -49,7 +48,7 @@


async def _main():
configs = Configs.from_env_var()
configs = Configs()
async_weaviate_client = get_weaviate_async_client(
http_host=configs.weaviate_http_host,
http_port=configs.weaviate_http_port,
Expand All @@ -62,7 +61,7 @@ async def _main():
async_openai_client = AsyncOpenAI()
async_knowledgebase = AsyncWeaviateKnowledgeBase(
async_weaviate_client,
collection_name="enwiki_20250520",
collection_name=configs.weaviate_collection_name,
)

messages: list = [
Expand All @@ -81,7 +80,7 @@ async def _main():
while True:
for _ in range(MAX_TURNS):
completion = await async_openai_client.chat.completions.create(
model=AGENT_LLM_NAME,
model=configs.default_planner_model,
messages=messages,
tools=tools,
)
Expand Down
26 changes: 4 additions & 22 deletions src/2_frameworks/1_react_rag/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,6 @@
logging.basicConfig(level=logging.INFO)


AGENT_LLM_NAME = "gemini-2.5-flash"

configs = Configs.from_env_var()
async_weaviate_client = get_weaviate_async_client(
http_host=configs.weaviate_http_host,
http_port=configs.weaviate_http_port,
http_secure=configs.weaviate_http_secure,
grpc_host=configs.weaviate_grpc_host,
grpc_port=configs.weaviate_grpc_port,
grpc_secure=configs.weaviate_grpc_secure,
api_key=configs.weaviate_api_key,
)
async_openai_client = AsyncOpenAI()
async_knowledgebase = AsyncWeaviateKnowledgeBase(
async_weaviate_client,
collection_name="enwiki_20250520",
)


async def _cleanup_clients() -> None:
"""Close async clients."""
await async_weaviate_client.close()
Expand All @@ -65,8 +46,9 @@ async def _main(question: str, gr_messages: list[ChatMessage]):
instructions=REACT_INSTRUCTIONS,
tools=[agents.function_tool(async_knowledgebase.search_knowledgebase)],
model=agents.OpenAIChatCompletionsModel(
model=AGENT_LLM_NAME, openai_client=async_openai_client
model=configs.default_planner_model, openai_client=async_openai_client
),
model_settings=agents.ModelSettings(parallel_tool_calls=True),
)

result_stream = agents.Runner.run_streamed(main_agent, input=question)
Expand All @@ -88,7 +70,7 @@ async def _main(question: str, gr_messages: list[ChatMessage]):


if __name__ == "__main__":
configs = Configs.from_env_var()
configs = Configs()
async_weaviate_client = get_weaviate_async_client(
http_host=configs.weaviate_http_host,
http_port=configs.weaviate_http_port,
Expand All @@ -100,7 +82,7 @@ async def _main(question: str, gr_messages: list[ChatMessage]):
)
async_knowledgebase = AsyncWeaviateKnowledgeBase(
async_weaviate_client,
collection_name="enwiki_20250520",
collection_name=configs.weaviate_collection_name,
)

async_openai_client = AsyncOpenAI()
Expand Down
7 changes: 3 additions & 4 deletions src/2_frameworks/1_react_rag/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@

load_dotenv(verbose=True)

AGENT_LLM_NAME = "gemini-2.5-flash"
no_tracing_config = RunConfig(tracing_disabled=True)


async def _main(query: str):
configs = Configs.from_env_var()
configs = Configs()
async_weaviate_client = get_weaviate_async_client(
http_host=configs.weaviate_http_host,
http_port=configs.weaviate_http_port,
Expand All @@ -41,7 +40,7 @@ async def _main(query: str):
)
async_knowledgebase = AsyncWeaviateKnowledgeBase(
async_weaviate_client,
collection_name="enwiki_20250520",
collection_name=configs.weaviate_collection_name,
)

async_openai_client = AsyncOpenAI()
Expand All @@ -51,7 +50,7 @@ async def _main(query: str):
instructions=REACT_INSTRUCTIONS,
tools=[function_tool(async_knowledgebase.search_knowledgebase)],
model=OpenAIChatCompletionsModel(
model=AGENT_LLM_NAME, openai_client=async_openai_client
model=configs.default_planner_model, openai_client=async_openai_client
),
)

Expand Down
9 changes: 3 additions & 6 deletions src/2_frameworks/1_react_rag/langfuse_gradio.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@

set_up_logging()

AGENT_LLM_NAME = "gemini-2.5-flash"

configs = Configs.from_env_var()
configs = Configs()
async_weaviate_client = get_weaviate_async_client(
http_host=configs.weaviate_http_host,
http_port=configs.weaviate_http_port,
Expand All @@ -46,7 +45,7 @@
async_openai_client = AsyncOpenAI()
async_knowledgebase = AsyncWeaviateKnowledgeBase(
async_weaviate_client,
collection_name="enwiki_20250520",
collection_name=configs.weaviate_collection_name,
)


Expand All @@ -71,7 +70,7 @@ async def _main(question: str, gr_messages: list[ChatMessage]):
instructions=REACT_INSTRUCTIONS,
tools=[agents.function_tool(async_knowledgebase.search_knowledgebase)],
model=agents.OpenAIChatCompletionsModel(
model=AGENT_LLM_NAME, openai_client=async_openai_client
model=configs.default_planner_model, openai_client=async_openai_client
),
)

Expand Down Expand Up @@ -102,8 +101,6 @@ async def _main(question: str, gr_messages: list[ChatMessage]):


if __name__ == "__main__":
configs = Configs.from_env_var()

signal.signal(signal.SIGINT, _handle_sigint)

try:
Expand Down
13 changes: 7 additions & 6 deletions src/2_frameworks/2_multi_agent/efficient.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@

set_up_logging()

AGENT_LLM_NAMES = {
"worker": "gemini-2.5-flash", # less expensive,
"planner": "gemini-2.5-pro", # more expensive, better at reasoning and planning
}

configs = Configs.from_env_var()
configs = Configs()
async_weaviate_client = get_weaviate_async_client(
http_host=configs.weaviate_http_host,
http_port=configs.weaviate_http_port,
Expand All @@ -51,9 +47,14 @@
async_openai_client = AsyncOpenAI()
async_knowledgebase = AsyncWeaviateKnowledgeBase(
async_weaviate_client,
collection_name="enwiki_20250520",
collection_name=configs.weaviate_collection_name,
)

AGENT_LLM_NAMES = {
"worker": configs.default_worker_model, # less expensive,
"planner": configs.default_planner_model, # more expensive, better at reasoning and planning
}


async def _cleanup_clients() -> None:
"""Close async clients."""
Expand Down
13 changes: 7 additions & 6 deletions src/2_frameworks/2_multi_agent/efficient_multiple_kbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@

set_up_logging()

AGENT_LLM_NAMES = {
"worker": "gemini-2.5-flash", # less expensive,
"planner": "gemini-2.5-pro", # more expensive, better at reasoning and planning
}

configs = Configs.from_env_var()
configs = Configs()
async_weaviate_client = get_weaviate_async_client(
http_host=configs.weaviate_http_host,
http_port=configs.weaviate_http_port,
Expand All @@ -48,9 +44,14 @@
async_openai_client = AsyncOpenAI()
async_knowledgebase = AsyncWeaviateKnowledgeBase(
async_weaviate_client,
collection_name="enwiki_20250520",
collection_name=configs.weaviate_collection_name,
)

AGENT_LLM_NAMES = {
"worker": configs.default_worker_model, # less expensive,
"planner": configs.default_planner_model, # more expensive, better at reasoning and planning
}

gemini_grounding_tool = GeminiGroundingWithGoogleSearch(
model_settings=ModelSettings(model=AGENT_LLM_NAMES["worker"])
)
Expand Down
10 changes: 5 additions & 5 deletions src/2_frameworks/2_multi_agent/verbose.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async def _main(question: str, gr_messages: list[ChatMessage]):
name="Planner Agent",
instructions=PLANNER_INSTRUCTIONS,
model=agents.OpenAIChatCompletionsModel(
model="gemini-2.5-flash", openai_client=async_openai_client
model=configs.default_planner_model, openai_client=async_openai_client
),
output_type=SearchPlan,
)
Expand All @@ -151,7 +151,7 @@ async def _main(question: str, gr_messages: list[ChatMessage]):
instructions=RESEARCHER_INSTRUCTIONS,
tools=[agents.function_tool(async_knowledgebase.search_knowledgebase)],
model=agents.OpenAIChatCompletionsModel(
model="gemini-2.5-flash-lite",
model=configs.default_worker_model,
openai_client=async_openai_client,
),
model_settings=agents.ModelSettings(tool_choice="required"),
Expand All @@ -160,7 +160,7 @@ async def _main(question: str, gr_messages: list[ChatMessage]):
name="Writer Agent",
instructions=WRITER_INSTRUCTIONS,
model=agents.OpenAIChatCompletionsModel(
model="gemini-2.5-flash", openai_client=async_openai_client
model=configs.default_planner_model, openai_client=async_openai_client
),
output_type=ResearchReport,
)
Expand Down Expand Up @@ -213,7 +213,7 @@ async def _main(question: str, gr_messages: list[ChatMessage]):


if __name__ == "__main__":
configs = Configs.from_env_var()
configs = Configs()
async_weaviate_client = get_weaviate_async_client(
http_host=configs.weaviate_http_host,
http_port=configs.weaviate_http_port,
Expand All @@ -225,7 +225,7 @@ async def _main(question: str, gr_messages: list[ChatMessage]):
)
async_knowledgebase = AsyncWeaviateKnowledgeBase(
async_weaviate_client,
collection_name="enwiki_20250520",
collection_name=configs.weaviate_collection_name,
)

async_openai_client = AsyncOpenAI()
Expand Down
5 changes: 3 additions & 2 deletions src/2_frameworks/3_code_interpreter/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
You will need your E2B API Key.
"""

import os
from pathlib import Path

import agents
Expand Down Expand Up @@ -42,7 +43,6 @@
but you won't be able to install packages.
"""

AGENT_LLM_NAME = "gemini-2.5-flash"
async_openai_client = AsyncOpenAI()
code_interpreter = CodeInterpreter(
local_files=[
Expand All @@ -65,7 +65,8 @@ async def _main(question: str, gr_messages: list[ChatMessage]):
)
],
model=agents.OpenAIChatCompletionsModel(
model=AGENT_LLM_NAME, openai_client=async_openai_client
model=os.getenv("DEFAULT_PLANNER_MODEL", "gemini-2.5-flash"),
openai_client=async_openai_client,
),
)

Expand Down
Loading