substratusai/weaviate-gorilla-v4-api-split
Dataset
Finetuned on: https://huggingface.co/datasets/weaviate/WeaviateGraphQLGorilla-APISplit-Train
Prompt template
## Instruction
Your task is to write GraphQL for the Natural Language Query provided. Use the provided API reference and Schema to generate the GraphQL. The GraphQL should be valid for Weaviate.
Only use the API reference to understand the syntax of the request.
## Natural Language Query
{nlcommand}
## Schema
{schema}
## API reference
{apiRef}
## Answer
{output}Example usage
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "substratusai/weaviate-gorilla-v4-api-split"
model = AutoModelForCausalLM.from_pretrained(
model_id,
load_in_4bit=True,
device_map='auto',
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
text = """
## Instruction
Your task is to write GraphQL for the Natural Language Query provided. Use the provided API reference and Schema to generate the GraphQL. The GraphQL should be valid for Weaviate.
Only use the API reference to understand the syntax of the request.
## Natural Language QuerySchema
{ "classes": [ { "class": "HistoricalEvent", "description": "Information about historical events", "vectorIndexType": "hnsw", "vectorizer": "text2vec-transformers", "properties": [ { "name": "eventName", "dataType": ["text"], "description": "Name of the historical event" }, { "name": "description", "dataType": ["text"], "description": "Detailed description of the event" }, { "name": "year", "dataType": ["int"], "description": "Year the event occurred" }, { "name": "hadSignificantImpact", "dataType": ["boolean"], "description": "Whether the event had a significant impact" }, { "name": "involvedCountries", "dataType": ["Country"], "description": "Countries involved in the event" }{ "class": "Country", "description": "Information about countries", "vectorIndexType": "hnsw", "vectorizer": "text2vec-transformers", "properties": [ { "name": "countryName", "dataType": ["text"], "description": "Name of the country" }, { "name": "population", "dataType": ["int"], "description": "Population of the country" }}}
API reference
- Limit BM25 search results Limit the results[] You can limit the number of results returned by a
bm25search, - to a fixed number, using thelimit: <N>operator - to the first N "drops" inscore, using theautocutoperatorautocutcan be combined withlimit: N, which would limit autocut's input to the firstNobjects. Limiting the number of results Use thelimitargument to specify the maximum number of results that should be returned: ``graphql { Get { JeopardyQuestion( bm25: { query: "safety" }, limit: 3 ) { question answer _additional { score } } } }``
Answer
"""
device = "cuda:0"
inputs = tokenizer(text, return_tensors="pt").to(device)
# this was needed due to a issue with model not taking token_type_ids
# inputs.pop("token_type_ids")
outputs = model.generate(**inputs, max_new_tokens=300)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))