http://franz.com/ns/allegrograph/8.0.0/llm/response

Ask GPT for a list of responses.

Namespace:

PREFIX llm: <http://franz.com/ns/allegrograph/8.0.0/llm/> 

General forms:

?response llm:response ?prompt.  
(?response ?node) llm:response ?prompt. 

For example, the pattern

?response llm:response "list 10 US States". 

will bind ?response to ten string literals extracted from the OpenAI API JSON response.

The predicate binds an optional second parameter ?node with a unique IRI. For example

(?celebrity ?node) llm:response "write a list of 10 celebrities". 

binds the response ?node to a unique URI like

http://franz.com/ns/allegrograph/8.0.0/llm/node#2baf1f40105d9501fe319a8ec463fdf4 

A query may use this IRI to link the response to other resources and add properties:

INSERT {  
  ?node :name ?celebrity.  
} WHERE {  
  (?celebrity ?node) llm:response "write a list of 10 celebrities".  
}  

API Key

If you are using OpenAI, you need an API key to utilize this predicate. (Ollama does not require a key but does require other setup as described in the Ollama document just linked.) See https://platform.openai.com/overview for instructions on obtaining a key (start with the Quickstart Tutorial and follow the links there to get a key). There are three ways to configure your API key, as a query option prefix or in a couple of places in the Allegrograph configuration.

As a query option prefix, write:

PREFIX franzOption_openaiApiKey: <franz:sk-U01ABc2defGHIJKlmnOpQ3RstvVWxyZABcD4eFG5jiJKlmno> 

Syntax for config file:

QueryOption openaiApiKey=<franz:sk-U01ABc2defGHIJKlmnOpQ3RstvVWxyZABcD4eFG5jiJKlmno> 

In the file data/settings/default-query-options:

(("franzOption_openaiApiKey" "<franz:sk-U01ABc2defGHIJKlmnOpQ3RstvVWxyZABcD4eFG5jiJKlmno>")) 

API Options

The proprietary OpenAI API exposes many options and parameters for interaction with their LLM models. Currently the AllegroGraph magic predicates and functions take an opinionated approach and hide most of these options behind the scenes. Specifically, we set

API endpoint: https://api.openai.com/v1/chat/completions 

Endpoint parameters:

functions:  
  [{"name":"array_of_strings",  
    "description":"function to list an array of specified items","parameters":  
    {"type":"object",  
     "properties":  
     {"array":  
      {"description":"the list of items",  
       "type":"array",  
       "items":{"type":"string"}}}}}]  
function-call: {"name":"array_of_strings"} 

Additionally we impose an API timeout of 10 seconds.

Finally, when the OpenAI API times out, returns an error, or the magic predicate implementation fails to parse the response, or any other error occurs, the magic predicate displays an informative message in Webview. Please contact AllegroGraph Support if you require different API options or customization.

Notes

The following namespace abbreviations are used:

The SPARQL magic properties reference has additional information on using AllegroGraph magic properties and functions.