|
| 1 | +import os |
| 2 | + |
| 3 | +import select_ai |
| 4 | +from select_ai.agent import ( |
| 5 | + Agent, |
| 6 | + AgentAttributes, |
| 7 | + Task, |
| 8 | + TaskAttributes, |
| 9 | + Team, |
| 10 | + TeamAttributes, |
| 11 | + Tool, |
| 12 | +) |
| 13 | + |
| 14 | +OPEN_AI_CREDENTIAL_NAME = "OPENAI_CRED" |
| 15 | +OPEN_AI_PROFILE_NAME = "OPENAI_PROFILE" |
| 16 | +SELECT_AI_AGENT_NAME = "WEB_SEARCH_AGENT" |
| 17 | +SELECT_AI_TASK_NAME = "WEB_SEARCH_TASK" |
| 18 | +SELECT_AI_TOOL_NAME = "WEB_SEARCH_TOOL" |
| 19 | +SELECT_AI_TEAM_NAME = "WEB_SEARCH_TEAM" |
| 20 | + |
| 21 | +USER_QUERIES = { |
| 22 | + "d917b055-e8a1-463a-a489-d4328a7b2210": "What are the key features for the product highlighted at this URL https://www.oracle.com/artificial-intelligence/database-machine-learning", |
| 23 | + "c2e3ff20-f56d-40e7-987c-cc72740c75a5": "What is the main topic at this URL https://www.oracle.com/artificial-intelligence/database-machine-learning", |
| 24 | + "25e23a25-07b9-4ed7-be11-f7e5e445d286": "What is the main topic at this URL https://openai.com", |
| 25 | +} |
| 26 | + |
| 27 | +# connect |
| 28 | +user = os.getenv("SELECT_AI_USER") |
| 29 | +password = os.getenv("SELECT_AI_PASSWORD") |
| 30 | +dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING") |
| 31 | +select_ai.connect(user=user, password=password, dsn=dsn) |
| 32 | + |
| 33 | +# Create Open AI credential |
| 34 | +select_ai.create_credential( |
| 35 | + credential={ |
| 36 | + "credential_name": OPEN_AI_CREDENTIAL_NAME, |
| 37 | + "username": "OPENAI", |
| 38 | + "password": os.getenv("OPEN_AI_API_KEY"), |
| 39 | + }, |
| 40 | + replace=True, |
| 41 | +) |
| 42 | +print("Created credential: ", OPEN_AI_CREDENTIAL_NAME) |
| 43 | + |
| 44 | +# # Create Open AI Profile |
| 45 | +profile = select_ai.Profile( |
| 46 | + profile_name=OPEN_AI_PROFILE_NAME, |
| 47 | + attributes=select_ai.ProfileAttributes( |
| 48 | + credential_name=OPEN_AI_CREDENTIAL_NAME, |
| 49 | + provider=select_ai.OpenAIProvider(model="gpt-4.1"), |
| 50 | + ), |
| 51 | + description="My Open AI Profile", |
| 52 | + replace=True, |
| 53 | +) |
| 54 | +print("Created profile: ", OPEN_AI_PROFILE_NAME) |
| 55 | + |
| 56 | +# Create an AI Agent team |
| 57 | +team = Team( |
| 58 | + team_name=SELECT_AI_TEAM_NAME, |
| 59 | + attributes=TeamAttributes( |
| 60 | + agents=[{"name": SELECT_AI_AGENT_NAME, "task": SELECT_AI_TASK_NAME}] |
| 61 | + ), |
| 62 | +) |
| 63 | +team.create(replace=True) |
| 64 | + |
| 65 | +# Agent |
| 66 | +agent = Agent( |
| 67 | + agent_name=SELECT_AI_AGENT_NAME, |
| 68 | + attributes=AgentAttributes( |
| 69 | + profile_name=OPEN_AI_PROFILE_NAME, |
| 70 | + enable_human_tool=False, |
| 71 | + role="You are a specialized web search agent that can access web page contents and respond to questions based on its content.", |
| 72 | + ), |
| 73 | +) |
| 74 | +agent.create(replace=True) |
| 75 | + |
| 76 | +# Task |
| 77 | +task = Task( |
| 78 | + task_name=SELECT_AI_TASK_NAME, |
| 79 | + attributes=TaskAttributes( |
| 80 | + instruction="Answer the user question about the provided URL:{query}", |
| 81 | + enable_human_tool=False, |
| 82 | + tools=[SELECT_AI_TOOL_NAME], |
| 83 | + ), |
| 84 | +) |
| 85 | +task.create(replace=True) |
| 86 | + |
| 87 | +# Tool |
| 88 | +web_search_tool = Tool.create_websearch_tool( |
| 89 | + tool_name=SELECT_AI_TOOL_NAME, |
| 90 | + credential_name=OPEN_AI_CREDENTIAL_NAME, |
| 91 | + description="Web Search Tool using OpenAI", |
| 92 | + replace=True, |
| 93 | +) |
| 94 | +print("Created tool: ", SELECT_AI_TOOL_NAME) |
| 95 | + |
| 96 | +# Run the Agent Team |
| 97 | +for conversation_id, prompt in USER_QUERIES.items(): |
| 98 | + response = team.run( |
| 99 | + prompt=prompt, params={"conversation_id": conversation_id} |
| 100 | + ) |
| 101 | + print(response) |
0 commit comments