Git Product home page Git Product logo

groqcall's Introduction

GroqCall.ai - Lightning-Fast LLM Function Calls

Open In Colab Version License

GroqCall is a proxy server that enables lightning-fast function calls for Groq's Language Processing Unit (LPU) and other AI providers. It simplifies the creation of AI assistants by offering a wide range of built-in functions hosted on the cloud.

Quickstart

Using the Pre-built Server

To quickly start using GroqCall without running it locally, make requests to one of the following base URLs:

  • Cloud: https://groqcall.ai/proxy/groq/v1
  • Local: http://localhost:8000 (if running the proxy server locally)

Running the Proxy Locally

  1. Clone the repository:
git clone https://github.com/unclecode/groqcall.git
cd groqcall
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the FastAPI server:
./venv/bin/uvicorn --app-dir app/ main:app --reload

Examples

Using GroqCall with PhiData

from phi.llm.openai.like import OpenAILike
from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo

my_groq = OpenAILike(
    model="mixtral-8x7b-32768",
    api_key="YOUR_GROQ_API_KEY",
    base_url="https://groqcall.ai/proxy/groq/v1"  # or "http://localhost:8000/proxy/groq/v1" if running locally
)

assistant = Assistant(
    llm=my_groq,
    tools=[DuckDuckGo()], 
    show_tool_calls=True, 
    markdown=True
)

assistant.print_response("What's happening in France? Summarize top stories with sources, very short and concise.", stream=False)

Using GroqCall with Requests

FuncHub: Schema-less Function Calls

GroqCall introduces FuncHub, which allows you to make function calls without passing the function schema.

import requests

api_key = "YOUR_GROQ_API_KEY"
header = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

proxy_url = "https://groqcall.ai/proxy/groq/v1/chat/completions" # or "http://localhost:8000/proxy/groq/v1/chat/completions" if running locally

request = {
    "messages": [
        {
            "role": "system",
            "content": "YOU MUST FOLLOW THESE INSTRUCTIONS CAREFULLY.\n<instructions>\n1. Use markdown to format your answers.\n</instructions>"
        },
        {
            "role": "user", 
            "content": "What's happening in France? Summarize top stories with sources, very short and concise."
        }
    ],
    "model": "mixtral-8x7b-32768",
    "tool_choice": "auto",
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "duckduck.search"
            }
        },
        {
            "type": "function",
            "function": {
                "name": "duckduck.news"
            }
        }
    ]
}

response = requests.post(
    proxy_url,
    headers=header,
    json=request
)

print(response.json()["choices"][0]["message"]["content"])
  • If you notice, the function schema is not passed in the request. This is because GroqCall uses FuncHub to automatically detect and call the function based on the function name in the cloud, Therefore you dont't need to parse the first response, call the function, and pass again. Check "functions" folder to add your own functions. I will create more examples in the close future to explain how to add your own functions.

Passing Function Schemas

If you prefer to pass your own function schemas, refer to the Function Schema example in the cookbook.

Rune proxy with Ollama locally

Function call proxy can be used with Ollama. You should first install Ollama and run it locally. Then refer to the Ollama example in the cookbook.

Cookbook

Explore the Cookbook for more examples and use cases of GroqCall.

Motivation

Groq is a startup that designs highly specialized processor chips aimed specifically at running inference on large language models. They've introduced what they call the Language Processing Unit (LPU), and the speed is astounding—capable of producing 500 to 800 tokens per second or more.

As an admirer of Groq and their community, I built this proxy to enable function calls using the OpenAI interface, allowing it to be called from any library. This engineering workaround has proven to be immensely useful in my company for various projects.

Contributing

Contributions are welcome! If you have ideas, suggestions, or would like to contribute to this project, please reach out to me on Twitter (X) @unclecode or via email at [email protected].

Let's collaborate and make this repository even more awesome! 🚀

License

This project is licensed under the Apache License 2.0. See LICENSE for more information.

groqcall's People

Contributors

levitrammell avatar shakkaw avatar unclecode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

groqcall's Issues

No tools found!

When prompting the LLM through the proxy for something that does not require any of the tools, (Ex: "Write me a poem about the moon" or "How are you today") I get Error: 500 {"tool_calls":[]}.

I see there is logic in place for is_normal_chat but as long as the user has any function defined this variable can never be true.

Also, if forcing is_normal_chat, I get a different error Error calling GroqProvider: Object of type ChatCompletion is not JSON serializable.
And I can see with some debug tests that the LLM is returning a good response, but the proxy is messing up the parsing of it.

I'm testing and trying to find a different check to be implemented so we can have tools defined but still ask a normal question, but I'm not even sure it's possible without major code changes, so it might take a while.

Maybe @unclecode or someone more skilled than me can find a solution first 👍

Cells not working / Connection Timed Out (fixed code) - Colab

I tried your shared Google Colab notebook
Open In Colab

I'm not sure if it's intended to be like that or if it's meant to be done differently, but I couldn't get that part to work without altering it.

# Here you pass your own GROQ API key

Sending POST request, with full functions implementation

from dotenv import load_dotenv
from duckduckgo_search import DDGS
import requests, os
import json

load_dotenv()

api_key = os.getenv("<your_groq_api_key>")

header = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}
proxy_url = "https://groqcall.ai/proxy/groq/v1/chat/completions"

But then received a ConnectTimeout error while making an API request, resulting in an APITimeoutError due to a timed-out request.

Screen Shot 2024-04-30 at 8 05 03 AM

Schema-less Function Call 🤩

from dotenv import load_dotenv
from duckduckgo_search import DDGS
import requests, os
import json

load_dotenv()

api_key = os.getenv("<your_groq_api_key>")
Screen Shot 2024-04-30 at 8 49 24 AM

Using with PhiData (Or similar libraries)

from phi.llm.openai.like import OpenAILike
from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo
import os, json
import dotenv

load_dotenv()


api_key = os.getenv("<your_groq_api_key>")

Uploading Screen Shot 2024-04-30 at 8.52.03 AM.png…

[NOT ISSUE] Can you make conversational type python script

What i simply mean is that if we can do continuous conversation with it rather than just getting response for once and script ends. I have seen and used some conversational type scripts which use langchain so if you have deeper understanding of its implication with tools and other stuff then please make one or two scripts for that and add it in example :-))

500 Internal Server Error .....

I am actually in China, i find that when i use the requests to post "https://groqcall.ai/proxy/groq/v1/chat/completions" ,it works and there is no error ,but when I deploy the program running locally according to the deployment order described by you, an internal server error occurs when I call the local port

QQ截图20240426175417
Which means I was intercepted by groq....

But I can access into "http://localhost:8000/proxy/groq/v1/chat/completions" from the browser, and shows the style of the json

Is there any way to fix this without mounting the clash web proxy??

Thank you for answering for me !!!!!!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.