Error in executing SPARQL query with GraphSparqlQAChain and custom LLM (llamacpp)
Labels: name: auto:bug, name: area: models

### System Info

Langchain Version: 0.0.339
Python Version: 3.10.12


### Who can help?

@hwchase17
When trying to execute the example from the GraphSparqlQAChain docs a ValueError arises, in my understanding because it cannot parse the query correctly and execute it against the graph.

```
> Entering new GraphSparqlQAChain chain...
Llama.generate: prefix-match hit
 The URI of Tim Berners-Lee's work homepage is <https://www.w3.org/People/Berners-Lee/>.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-13-432f483fbf1b>](https://localhost:8080/#) in <cell line: 2>()
      1 llm_chain = GraphSparqlQAChain.from_llm(llm=llm, graph=graph, verbose=True)
----> 2 llm_chain.run("What is Tim Berners-Lee's work homepage?")

3 frames
[/usr/local/lib/python3.10/dist-packages/langchain/chains/base.py](https://localhost:8080/#) in run(self, callbacks, tags, metadata, *args, **kwargs)
    503             if len(args) != 1:
    504                 raise ValueError("`run` supports only one positional argument.")
--> 505             return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
    506                 _output_key
    507             ]

[/usr/local/lib/python3.10/dist-packages/langchain/chains/base.py](https://localhost:8080/#) in __call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    308         except BaseException as e:
    309             run_manager.on_chain_error(e)
--> 310             raise e
    311         run_manager.on_chain_end(outputs)
    312         final_outputs: Dict[str, Any] = self.prep_outputs(

[/usr/local/lib/python3.10/dist-packages/langchain/chains/base.py](https://localhost:8080/#) in __call__(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)
    302         try:
    303             outputs = (
--> 304                 self._call(inputs, run_manager=run_manager)
    305                 if new_arg_supported
    306                 else self._call(inputs)

[/usr/local/lib/python3.10/dist-packages/langchain/chains/graph_qa/sparql.py](https://localhost:8080/#) in _call(self, inputs, run_manager)
    101             intent = "UPDATE"
    102         else:
--> 103             raise ValueError(
    104                 "I am sorry, but this prompt seems to fit none of the currently "
    105                 "supported SPARQL query types, i.e., SELECT and UPDATE."

ValueError: I am sorry, but this prompt seems to fit none of the currently supported SPARQL query types, i.e., SELECT and UPDATE. 
```

### Information

- [X] The official example notebooks/scripts
- [X] My own modified scripts

### Related Components

- [X] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Steps to reproduce the behaviour:

1. Follow the example as per the documentation: https://python.langchain.com/docs/use_cases/graph/graph_sparql_qa
2. Instead of the OpenAPI use a custom llamacpp deploy i.e. 
```
llm = LlamaCpp(
    model_path=model_path,
    n_gpu_layers=32,
    n_batch=512,
    callback_manager=callback_manager,
    n_ctx=2048,
    verbose=True,  # Verbose is required to pass to the callback manager
)
```
3. Run the chain:
```
llm_chain = GraphSparqlQAChain.from_llm(llm=llm, graph=graph, verbose=True)
llm_chain.run("What is Tim Berners-Lee's work homepage?")
```

### Expected behavior

Apart from giving the right result (which it does) the SPARQL query should be shown and run against the graph, as per documentation this should be the reply:
```
    > Entering new GraphSparqlQAChain chain...
    Identified intent:
    SELECT
    Generated SPARQL:
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    SELECT ?homepage
    WHERE {
        ?person foaf:name "Tim Berners-Lee" .
        ?person foaf:workplaceHomepage ?homepage .
    }
    Full Context:
    []
    
    > Finished chain.
    "Tim Berners-Lee's work homepage is http://www.w3.org/People/Berners-Lee/."
```