Updated the Knowledge Graph article (#327)

Co-authored-by: Jason Liu <jxnl@users.noreply.github.com>
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Co-authored-by: Jason Liu <jason@jxnl.co>
This commit is contained in:
Ivan Leo
2024-01-05 23:33:42 +01:00
committed by GitHub
parent eb6d1c423b
commit 9c17578547
2 changed files with 110 additions and 9 deletions
+4 -6
View File
@@ -1,4 +1,4 @@
import openai
from openai import OpenAI
import instructor
from graphviz import Digraph
@@ -6,7 +6,7 @@ from typing import List, Optional
from pydantic import BaseModel, Field
instructor.patch()
client = instructor.patch(OpenAI())
class Node(BaseModel):
@@ -56,14 +56,12 @@ class KnowledgeGraph(BaseModel):
def generate_graph(input: List[str]) -> KnowledgeGraph:
cur_state = KnowledgeGraph()
num_iterations = len(input)
for i, inp in enumerate(input):
new_updates = openai.ChatCompletion.create(
new_updates = client.chat.completions.create(
model="gpt-3.5-turbo-16k",
messages=[
{
"content": "You are an iterative knowledge graph builder. You are given the current state of the graph, and you must append the nodes and edges to it. Do not provide any duplicates and try to reuse nodes as much as possible."
"role": "system",
"content": """You are an iterative knowledge graph builder.
You are given the current state of the graph, and you must append the nodes and edges