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 a simple Gradio UI for Open Deep Research #525

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

dceluis
Copy link

@dceluis dceluis commented Feb 6, 2025

Hi,

This PR makes a few changes to get open deep researcher working smoothly with Gemini 2.0 Flash through LiteLLM, and sets up a basic Gradio demo to show it off. I focused on Gemini 2.0 Flash specifically because it's a cheap way to experiment with the library.

Here's a breakdown of what I did:

  1. Gemini 2.0 Flash has a couple of quirks that needed addressing:

    • Empty user messages: Gemini 2.0 Flash (unlike some other models) requires the user message to be present. I've changed the planning_step method in src/smolagents/agents.py to send the initial_facts prompt as a user message instead of a system message. This resolves an error where Gemini would complain about contents being empty.
    • litellm.add_function_to_prompt set to True or False depending on the selected model.
    • Empty Content: model_output because sometimes returns None, causing error. Returned early in this case.
    • used getattr To avoid errors when last_input_token_count is None
  2. Tool Calling Fixes: The changes make sure Litellm can create a valid tool calling request for Gemini, avoiding an empty parameters dict.

  3. Gradio Demo App: I've included a simple Gradio application.

Peek.2025-02-06.18-50.mp4
  1. Managed Agent Prompt Changes: Prompt changes in code_agent.yaml and toolcalling_agent.yaml to improve accuracy when calling managed agents.

Blocked by this PR on LiteLLM

But one can do:

export LITELLM_LOCAL_MODEL_COST_MAP=True and set the config locally.

@@ -455,7 +454,7 @@ def planning_step(self, task, is_first_step: bool, step: int) -> None:
"""
if is_first_step:
message_prompt_facts = {
"role": MessageRole.SYSTEM,
"role": MessageRole.USER,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this actually break other models?..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I did some searching and it seems like there was a change recently that broke Gemini compatibility:

https://github.com/huggingface/smolagents/pull/502/files#diff-e03ffeb1ffdc0c18d4a29eaec2694a39de7c9ce98647a9dcf5fc372a61d4d40aL520

the above change makes the request to model() not include any USER , as it moves the task description to be a SYSTEM message. This change could have been made for a) increasing accuracy or b) simplyfing the prompting implementation. In any case, the case of models not supporting being sent a single system model was probably unknown and understadably overlooked. I can revert my change, the above change, or wait for instructions.

Regarding breaking compatibility, I know most (if not all) support being sent a single user message. The opposite is not true, as at least Gemini models do not yet support this

@@ -686,6 +691,12 @@ def __call__(
) -> ChatMessage:
import litellm

# IMPORTANT - Set this to TRUE to add the function to the prompt for Non OpenAI LLMs
if litellm.supports_function_calling(model=self.model_id) == True:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if litellm.supports_function_calling(model=self.model_id):

Or

if litellm.supports_function_calling(model=self.model_id) is True:

if you want to be very specific.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm new to this project so I'm not sure if some idioms are acceptable or not.

What do you think of:
litellm.add_function_to_prompt = not litellm.supports_function_calling(model=self.model_id)

@dceluis
Copy link
Author

dceluis commented Feb 8, 2025

Added a notice about add_function_to_prompt. Seems like the feature is broken in LiteLLM.
It wasnt working before and its not working now, so its not a breaking change. But i submitted a fix upstream. #

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants