Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API keys to AgenticSystemConfig instead of relying on dotenv #33

Merged
merged 2 commits into from
Aug 21, 2024
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
16 changes: 13 additions & 3 deletions llama_toolchain/agentic_system/meta_reference/agentic_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ async def get_provider_impl(config: AgenticSystemConfig, deps: Dict[Api, Provide
), f"Unexpected config type: {type(config)}"

impl = MetaReferenceAgenticSystemImpl(
config,
deps[Api.inference],
deps[Api.safety],
)
Expand All @@ -58,7 +59,10 @@ async def get_provider_impl(config: AgenticSystemConfig, deps: Dict[Api, Provide


class MetaReferenceAgenticSystemImpl(AgenticSystem):
def __init__(self, inference_api: Inference, safety_api: Safety):
def __init__(
self, config: AgenticSystemConfig, inference_api: Inference, safety_api: Safety
):
self.config = config
self.inference_api = inference_api
self.safety_api = safety_api

Expand All @@ -77,9 +81,15 @@ async def create_agentic_system(
for dfn in cfg.available_tools:
if isinstance(dfn.tool_name, BuiltinTool):
if dfn.tool_name == BuiltinTool.wolfram_alpha:
tool = WolframAlphaTool(os.environ.get("WOLFRAM_ALPHA_API_KEY"))
key = self.config.wolfram_api_key
if not key:
raise ValueError("Wolfram API key not defined in config")
tool = WolframAlphaTool(key)
elif dfn.tool_name == BuiltinTool.brave_search:
tool = BraveSearchTool(os.environ.get("BRAVE_SEARCH_API_KEY"))
key = self.config.brave_search_api_key
if not key:
raise ValueError("Brave API key not defined in config")
tool = BraveSearchTool(key)
elif dfn.tool_name == BuiltinTool.code_interpreter:
tool = CodeInterpreterTool()
elif dfn.tool_name == BuiltinTool.photogen:
Expand Down
6 changes: 4 additions & 2 deletions llama_toolchain/agentic_system/meta_reference/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.

from typing import Optional

from pydantic import BaseModel


class AgenticSystemConfig(BaseModel):
# placeholder, no separate configuration is needed for now
pass
brave_search_api_key: Optional[str] = None
wolfram_api_key: Optional[str] = None
1 change: 0 additions & 1 deletion llama_toolchain/distribution/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
# `llama-toolchain` is automatically installed by the installation script.
SERVER_DEPENDENCIES = [
"fastapi",
"python-dotenv",
"uvicorn",
]

Expand Down
3 changes: 0 additions & 3 deletions llama_toolchain/distribution/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import fire
import httpx
import yaml
from dotenv import load_dotenv

from fastapi import FastAPI, HTTPException, Request, Response
from fastapi.exceptions import RequestValidationError
Expand All @@ -42,8 +41,6 @@

from .registry import resolve_distribution_spec

load_dotenv()


def is_async_iterator_type(typ):
if hasattr(typ, "__origin__"):
Expand Down