APOC 生成式AI程序
APOC 扩展程序库集成了各种 AI/ML 平台,提供了一系列实用工具,可快速演示生成式AI功能。该库包含用于生成文本、图像和向量嵌入的程序。它还支持从自然语言生成和执行 Cypher 查询以及进行模式解释。
APOC 扩展集成了
用法
这是一个快速示例
// generate embedding
CALL apoc.ml.openai.embedding(['Knowledge Graphs work well with LLMs'], $apiKey, {}) yield index, text, embedding;
// generate text
CALL apoc.ml.openai.completion('What color is the sky? Answer in one word: ', $apiKey, {config}) yield value;
/*
{ created=1684248202, model="text-davinci-003", id="cmpl-7GqBWwX49yMJljdmnLkWxYettZoOy",
usage={completion_tokens=2, prompt_tokens=12, total_tokens=14},
choices=[{finish_reason="stop", index=0, text="Blue", logprobs=null}], object="text_completion"}
*/
CALL apoc.ml.query("What movies did Tom Hanks play in?", {apiKey: $apiKey}) yield value, query
RETURN *;
CALL apoc.ml.schema({apiKey: $apiKey});
/*
The graph database schema represents a system where users can follow other users and review movies.
Users (:Person) can either follow other users (:Person) or review movies (:Movie).
The relationships allow users to express their preferences and opinions about movies.
This schema can be compared to social media platforms where users can follow each other and leave reviews or ratings for movies they have watched.
It can also be related to movie recommendation systems where user preferences and reviews play a crucial role in generating personalized recommendations.
*/
大多数程序除了您的输入外,还需要 API 密钥或令牌的配置以及模型名称。
API 密钥也可以在 apoc.conf
中配置,以使所有用户都能使用该功能,请务必通过速率和预算限制来保护这些密钥。