Much of the time the model will attempt to send very invalid JSON because it wants to write out very clean easy to read code. Here’s an example function that accepts graphql as the first argument, as a str
.
import requests
import json
def pokemon_graphql(query: str):
'''Query the PokeAPI with GraphQL. Provides up to date information.'''
headers = {'Content-Type': 'application/json'}
# Define the url of the GraphQL API
url = "https://beta.pokeapi.co/graphql/v1beta"
# Make the POST request to the GraphQL API
response = requests.post(url, json={'query': query}, headers=headers)
# Print the response as JSON
return json.loads(response.text)
schema = {
"name": "pokemon_graphql",
"description": "Query the PokeAPI with GraphQL. Provides up to date information.",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string"
}
},
"required": [
"query"
]
}
}
Sometimes it gets it very right.
Other times it gets it very wrong, though very readable!:
What I wish I could do is indulge the model by setting the parameters schema to a literal string.
def pokemon_graphql(query: str):
'''Query the PokeAPI with GraphQL. Provides up to date information.'''
headers = {'Content-Type': 'application/json'}
# Define the url of the GraphQL API
url = "https://beta.pokeapi.co/graphql/v1beta"
# Make the POST request to the GraphQL API
response = requests.post(url, json={'query': query}, headers=headers)
# Print the response as JSON
return json.loads(response.text)
schema = {
'name': 'pokemon_graphql',
'description': 'Query the PokeAPI with GraphQL. Provides up to date information.',
# What if we could accept just a plain string?!
'parameters': { "type": "string" }
}
c = Conversation(
model="gpt-3.5-turbo-0613",
)
c.register(pokemon_graphql, json_schema=schema)
c.submit(
system("You are allowed to debug and keep trying if your graphQL queries fail."),
"Tell me up to date information about the pokemon named murkrow"
)
However, this errors with
InvalidRequestError: Invalid schema for function 'pokemon_graphql': schema must be a JSON Schema of 'type: "object"', got 'type: "string"'.
Something similar happens for allowing it to submit code or really anything where the one and only argument is a string. Perhaps we could indulge the model and expand the JSON schema that is allowed in the parameters
schema. Maybe the field isn’t parameters
for that case? Not sure! Not really my call either but I’d love to be able to really crank up what we can do with strings into functions if it can do plaintext as input.