Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First LLM prompt for cypher, query and schema in APOC #3649

Merged
merged 6 commits into from Jul 24, 2023
Merged

Conversation

jexp
Copy link
Member

@jexp jexp commented Jul 6, 2023

For review

Uses OpenAI with a potentially configured API (apoc.openai.key) in apoc.conf (e.g. for Sandbox)

Extracts the database schema using apoc.meta.data

  • Uses a system prompt for base grounding
  • Adds a schema prompt
  • Provides the user question
  • adds apoc.ml.schema for describing the schema of the database
  • adds apoc.ml.cypher for generating N cypher queries for the user question
  • adds apoc.ml.query for generating and executing cypher queries (with generation-retries (3 by default) if the query failed)
  • Still needs docs and tests (a bit tricky due to the probabalistic nature)
apoc-llm-prompt

@jexp jexp requested a review from conker84 July 6, 2023 10:46
Copy link
Contributor

@conker84 conker84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you so much @jexp just a couple of nit pick for discussion

if (userQuestion != null && !userQuestion.isBlank()) prompt.add(Map.of("role", "user", "content", userQuestion));
if (assistantPrompt != null && !assistantPrompt.isBlank()) prompt.add(Map.of("role", "assistant", "content", assistantPrompt));
String result = OpenAI.executeRequest(apiKey, Map.of(), "chat/completions",
"gpt-3.5-turbo", "messages", prompt, "$", apocConfig)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the model is hardcoded, and as GPT-4 is now in GA maybe we can think about having it as a configuration parameter, as we did in OpenAI class

Result result = tx.execute(query);
AtomicReference<String> ref = new AtomicReference<>(query);
return result.stream()
.map(row -> new PromptMapResult(row, ref.getAndSet(null)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe instead of doing this we can use the ProcedureCallContext and return the query every time but only if requested from the developer

@conker84 conker84 merged commit 027de47 into dev Jul 24, 2023
5 of 7 checks passed
@conker84 conker84 deleted the llm-prompt branch July 24, 2023 12:06
vga91 pushed a commit that referenced this pull request Jul 24, 2023
* First LLM prompt for cypher, query and schema in APOC

* Added integration tests

* enable open.ai key management globally

* Added tests

* added docs

* added configuration map to procs

---------

Co-authored-by: Andrea Santurbano <santand@gmail.com>
vga91 added a commit that referenced this pull request Jul 25, 2023
* First LLM prompt for cypher, query and schema in APOC (#3649)

* First LLM prompt for cypher, query and schema in APOC

* Added integration tests

* enable open.ai key management globally

* Added tests

* added docs

* added configuration map to procs

---------

Co-authored-by: Andrea Santurbano <santand@gmail.com>

* Removed unused imports and fixed StartupExtendedTest

---------

Co-authored-by: Michael Hunger <github@jexp.de>
Co-authored-by: Andrea Santurbano <santand@gmail.com>
vga91 pushed a commit that referenced this pull request Jul 27, 2023
* First LLM prompt for cypher, query and schema in APOC

* Added integration tests

* enable open.ai key management globally

* Added tests

* added docs

* added configuration map to procs

---------

Co-authored-by: Andrea Santurbano <santand@gmail.com>
vga91 pushed a commit that referenced this pull request Jul 27, 2023
* First LLM prompt for cypher, query and schema in APOC

* Added integration tests

* enable open.ai key management globally

* Added tests

* added docs

* added configuration map to procs

---------

Co-authored-by: Andrea Santurbano <santand@gmail.com>
vga91 pushed a commit that referenced this pull request Jul 27, 2023
* First LLM prompt for cypher, query and schema in APOC

* Added integration tests

* enable open.ai key management globally

* Added tests

* added docs

* added configuration map to procs

---------

Co-authored-by: Andrea Santurbano <santand@gmail.com>
vga91 pushed a commit that referenced this pull request Jul 27, 2023
* First LLM prompt for cypher, query and schema in APOC

* Added integration tests

* enable open.ai key management globally

* Added tests

* added docs

* added configuration map to procs

---------

Co-authored-by: Andrea Santurbano <santand@gmail.com>
vga91 pushed a commit that referenced this pull request Jul 27, 2023
* First LLM prompt for cypher, query and schema in APOC

* Added integration tests

* enable open.ai key management globally

* Added tests

* added docs

* added configuration map to procs

---------

Co-authored-by: Andrea Santurbano <santand@gmail.com>
vga91 added a commit that referenced this pull request Aug 3, 2023
* [NOID] Add OpenAI (LLM) procedures (#3575) (#3582)

* Add OpenAI (LLM) procedures (#3575)

* WIP

* Add completion API

* add chatCompletion

* prettificiation

* WIP

* prettify

* Refactoring, todo docs & tests

* Added Tests & Docs for OpenAI procs (WIP)

* Update openai.adoc

From @tomasonjo

---------

Co-authored-by: Tomaz Bratanic <bratanic.tomaz@gmail.com>

* Removed unused deps after OpenAI procedures addition (#3585)

* Updated extended.txt to fix checkCoreWithExtraDependenciesJars failure after Open AI procedures

---------

Co-authored-by: Michael Hunger <github@jexp.de>
Co-authored-by: Tomaz Bratanic <bratanic.tomaz@gmail.com>

* [NOID] First LLM prompt for cypher, query and schema in APOC (#3649)

* First LLM prompt for cypher, query and schema in APOC

* Added integration tests

* enable open.ai key management globally

* Added tests

* added docs

* added configuration map to procs

---------

Co-authored-by: Andrea Santurbano <santand@gmail.com>

---------

Co-authored-by: Michael Hunger <github@jexp.de>
Co-authored-by: Tomaz Bratanic <bratanic.tomaz@gmail.com>
Co-authored-by: Andrea Santurbano <santand@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants