Skip to content

Hello! How to use adk web with non google api model? (Deepinfra or local) #1702

Closed

Description

@Blynskyniki
No description provided.

Activity

  1. omanandswami2005 commented on Jun 28, 2025

    @omanandswami2005

    description ? or any code snippet ? (you can use LiteLLM library available in ADK)

  2. NewGenesis04 commented on Jun 28, 2025

    @NewGenesis04

    description ? or any code snippet ? (you can use LiteLLM library available in ADK)

    I tried and I got an error after the first output when I used tools. This is my code:

    from google.adk.agents import LlmAgent, Agent
    from google.genai import types
    import os
    from google.adk.models.lite_llm import LiteLlm
    from pathlib import Path
    import praw
    from dotenv import load_dotenv
    load_dotenv(dotenv_path=Path('.') / '.env')
    from .prompts import SYSTEM_INSTRUCTION
    api_key = os.getenv("OPENROUTER_API_KEY")

    def get_reddit_ai_news(subreddit: str, limit: int = 5) -> dict[str, list[str]]:
    """
    Fetches top post titles from a specified subreddit using the Reddit API.

    Args:
        subreddit: The name of the subreddit to fetch news from (e.g., 'AINewsAndTrends').
        limit: The maximum number of top posts to fetch.
    
    Returns:
        A dictionary with the subreddit name as key and a list of
        post titles as value. Returns an error message if credentials are
        missing, the subreddit is invalid, or an API error occurs.
    """
    
    print(f"--- Tool called: Fetching from r/{subreddit} via Reddit API ---")
    client_id = os.getenv("REDDIT_CLIENT_ID")
    client_secret = os.getenv("REDDIT_CLIENT_SECRET")
    user_agent = os.getenv("REDDIT_USER_AGENT")
    
    if not all([client_id, client_secret, user_agent]):
        print("--- Tool error: Reddit API credentials missing in .env file. ---")
        return {subreddit: ["Error: Reddit API credentials not configured."]}
    
    try:
        reddit = praw.Reddit(
            client_id=client_id,
            client_secret=client_secret,
            user_agent=user_agent
        )
        # Check if the subreddit exists
        reddit.subreddits.search_by_name(subreddit, exact=True)
        sub = reddit.subreddit(subreddit)
        top_posts = list(sub.hot(limit=limit)) # Fetch hot posts
        titles = [post.title for post in top_posts]
        if not titles:
             return {subreddit: [f"No recent hot posts found in r/{subreddit}."]}
        
        return {subreddit: titles}
    
    except praw.exceptions.PRAWException as e:
        print(f"--- Tool error: {e} ---")
        return {subreddit: [f"Error fetching from r/{subreddit}: {str(e)}"]}
    
    except Exception as e:
        print(f"--- Tool error: {e} ---")
        return {subreddit: [f"An unexpected error occurred: {str(e)}"]}
    

    model = LiteLlm(
    model="openrouter/mistralai/mistral-7b-instruct:free",
    api_key=api_key
    )

    root_agent = LlmAgent(
    name="reddit_news_agent",
    description="Agent to help users find news articles on Reddit.",
    model=model,
    instruction=SYSTEM_INSTRUCTION,
    tools=[get_reddit_ai_news],
    output_key="summary"
    )

  3. omanandswami2005 commented on Jun 29, 2025

    @omanandswami2005

    What was ur error? It's Working for me
    Try pasting this code in same file in local installation of adk

  4. boyangsvl commented on Jun 30, 2025

    @boyangsvl
    Collaborator

    Thanks for the discussions. I will move this to the discussions section since it doesn't seems to be an issue of ADK iteself.

  5. locked and limited conversation to collaborators on Jun 30, 2025
  6. converted this issue into a discussion #1719 on Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    models[Component] This issue is related to model support

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions