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

Implement OpenAIServerModel #109

Merged
merged 1 commit into from
Jan 8, 2025
Merged

Conversation

Zetaphor
Copy link
Contributor

@Zetaphor Zetaphor commented Jan 7, 2025

This PR implements a new model type, OpenAIServerModel, which is compatible with any server host using an OpenAI compatible API without having to introduce LiteLLM as a middleware dependency.

This PR closes #96

Example implementation, tested with LM Studio:

from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel

def test_openai_compatible():
    # Initialize the agent with DuckDuckGo search and OpenAI-compatible model
    agent = CodeAgent(
        tools=[DuckDuckGoSearchTool()],
        model=OpenAIServerModel(
            model_id="qwen2.5-coder-32b-instruct",  # or whatever model ID your server uses
            api_base="http://localhost:1234/v1",  # replace with your server URL
            api_key="lm-studio",  # replace with your API key
            temperature=0.7
        )
    )

    # Test the agent with a query
    query = "How many seconds would it take for a leopard at full speed to run through Pont des Arts?"
    result = agent.run(query)

    # Print the result
    print(f"Query: {query}")
    print(f"Response: {result}")

if __name__ == "__main__":
    test_openai_compatible()

This PR does not (yet) contain the required documentation changes, as I wanted to ensure this meets the standards of the project before I move forward with documentation changes. Maybe documentation changes should be a separate PR?

@aymeric-roucher aymeric-roucher merged commit b4528d6 into huggingface:main Jan 8, 2025
2 of 3 checks passed
@aymeric-roucher
Copy link
Collaborator

Thanks a lot @Zetaphor, great contribution! 🤗 Indeed having the doc on this would be great!

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.

Add generic model interface using HTTP and/or OpenAI spec
2 participants