Try Gorilla: A Large Language Model Connected with Massive APIs

Daniel Avila
LatinXinAI
Published in
4 min readJun 3, 2023

--

Gorilla is an advanced Large Language Model (LLM) designed to effectively interact with a wide range of APIs, enhancing the capabilities of LLMs in real-world applications.

By using self-instruction and retrieval techniques, Gorilla excels at selecting and utilizing tools with overlapping and evolving functionalities.

Evaluated using the comprehensive APIBench dataset, which includes HuggingFace, TorchHub, and TensorHub APIs, Gorilla surpasses the performance of GPT-4 in generating API calls.

When paired with a document retrieval system, it showcases an impressive ability to adapt to changes in API documentation, bolstering the reliability and applicability of its outputs.

How it works

Gorilla’s process for connecting to an API involves several key steps:

  1. User prompt: A user provides a natural language prompt describing a particular task or goal they wish to achieve using an API.
  2. Retrieval (optional): In retrieval mode, Gorilla uses a document retriever (such as BM25 or GPT-Index) to fetch the most up-to-date API documentation from a database. This documentation is then concatenated to the user prompt with a message instructing Gorilla to use it for reference.
  3. API call generation: Gorilla processes the user prompt (and retrieved documentation, if applicable) to generate an appropriate API call that fulfills the user’s task or goal. This is achieved through Gorilla’s fine-tuned LLaMA-7B model, specifically designed for API calls.
  4. Output: Gorilla returns the generated API call to the user, which can then be used to interact with the desired API and complete the specified task.

It’s important to note that Gorilla is highly adaptable and can operate in both zero-shot and retrieval modes, allowing it to adjust to changes in API documentation and maintain accuracy over time.

Let’s get to the code

First, install OpenAI with pip

pip install openai

Configure the api_key and api_base like this

import openai

openai.api_key = "EMPTY" # Key is ignored and does not matter
openai.api_base = "http://34.132.127.197:8000/v1"

Create the function to obtain the Gorilla result using the OpenAI library

def get_gorilla_response(prompt="I would like to translate from English to French.", model="gorilla-7b-hf-v0"):
completion = openai.ChatCompletion.create(
model=model,
messages=[{"role": "user", "content": prompt}]
)
return completion.choices[0].message.content

Execute the function sending the prompt and the model you’d like to use, in this case, gorilla-7b-hf-v0.

prompt = "I would like to translate from English to Chinese."
print(get_gorilla_response(prompt, model="gorilla-7b-hf-v0" ))

That’s it. You will then receive the complete information from the Huggingface API and the instructions on how to execute that request.

Try a demo👇

Conclusion

Gorilla is a groundbreaking LLM that generates accurate API calls and adapts to real-time changes in documentation. This model paves the way for future LLMs to become more reliable and versatile in interacting with tools and systems.

Future advancements in LLMs could focus on further reducing hallucination errors, improving adaptability to diverse APIs, and expanding their capabilities to handle complex tasks. Potential applications include serving as a primary interface for computing infrastructure, automating processes like vacation booking, and facilitating seamless communication across various web APIs.

Web: https://gorilla.cs.berkeley.edu/

Github: https://github.com/ShishirPatil/gorilla

Paper: https://arxiv.org/abs/2305.15334

LatinX in AI (LXAI) logo

Do you identify as Latinx and are working in artificial intelligence or know someone who is Latinx and is working in artificial intelligence?

Don’t forget to hit the 👏 below to help support our community — it means a lot!

--

--