llm keys helper function in example agent && llm non-required api keys

This commit is contained in:
marko-kraemer 2024-11-23 00:33:24 -05:00
parent cd53a3f6b4
commit b3c189a9fa
2 changed files with 24 additions and 7 deletions

View File

@ -8,6 +8,7 @@ This agent can:
- Use either XML or Standard tool calling patterns
"""
import os
import asyncio
import json
from agentpress.thread_manager import ThreadManager
@ -88,6 +89,17 @@ file contents here
"""
def get_anthropic_api_key():
"""Get Anthropic API key from environment or prompt user."""
api_key = os.getenv("ANTHROPIC_API_KEY")
if not api_key:
api_key = input("\n🔑 Please enter your Anthropic API key: ").strip()
if not api_key:
print("❌ No API key provided. Please set ANTHROPIC_API_KEY environment variable or enter a key.")
sys.exit(1)
os.environ["ANTHROPIC_API_KEY"] = api_key
return api_key
async def run_agent(thread_id: str, use_xml: bool = True, max_iterations: int = 5):
"""Run the development agent with specified configuration."""
thread_manager = ThreadManager()
@ -181,6 +193,8 @@ def main():
"""Main entry point with synchronous setup."""
print("\n🚀 Welcome to AgentPress Web Developer Example!")
get_anthropic_api_key()
project_description = input("What would you like to build? (default: Create a modern, responsive landing page)\n> ")
if not project_description.strip():
project_description = "Create a modern, responsive landing page"

View File

@ -7,14 +7,17 @@ from openai import OpenAIError
import asyncio
import logging
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')
ANTHROPIC_API_KEY = os.environ.get('ANTHROPIC_API_KEY')
GROQ_API_KEY = os.environ.get('GROQ_API_KEY')
AGENTOPS_API_KEY = os.environ.get('AGENTOPS_API_KEY')
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY', None)
ANTHROPIC_API_KEY = os.environ.get('ANTHROPIC_API_KEY', None)
GROQ_API_KEY = os.environ.get('GROQ_API_KEY', None)
AGENTOPS_API_KEY = os.environ.get('AGENTOPS_API_KEY', None)
os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY
os.environ['ANTHROPIC_API_KEY'] = ANTHROPIC_API_KEY
os.environ['GROQ_API_KEY'] = GROQ_API_KEY
if OPENAI_API_KEY:
os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY
if ANTHROPIC_API_KEY:
os.environ['ANTHROPIC_API_KEY'] = ANTHROPIC_API_KEY
if GROQ_API_KEY:
os.environ['GROQ_API_KEY'] = GROQ_API_KEY
async def make_llm_api_call(
messages: list,