@@ -26,228 +26,29 @@ export async function GET(request: NextRequest, { params }: { params: { graph: s
2626
2727export async function POST ( request : NextRequest , { params } : { params : { graph : string } } ) {
2828
29- const type = request . nextUrl . searchParams . get ( 'type' ) || "count"
30- const graphName = params . graph
29+ const prefix = request . nextUrl . searchParams . get ( 'prefix' ) !
3130
3231 try {
33- switch ( type ) {
34- // case "commit": {
35- // const result = await fetch(`${process.env.BEAKEND_URL}/list_commits`, {
36- // method: 'POST',
37- // body: JSON.stringify({ repo: graphName }),
38- // headers: {
39- // "Authorization": process.env.SECRET_TOKEN!,
40- // "Content-Type": 'application/json'
41- // }
42- // })
43-
44- // if (!result.ok) {
45- // throw new Error(await result.text())
46- // }
47-
48- // const json = await result.json()
49-
50- // return NextResponse.json({ result: json }, { status: 200 })
51- // }
52- // case "switchCommit": {
53- // return NextResponse.json({
54- // result: {
55- // deletions: {
56- // 'nodes': [
57- // {
58- // "alias": "",
59- // "id": 2,
60- // "labels": [
61- // "Function"
62- // ],
63- // "properties": {
64- // "args": [
65- // [
66- // "cls",
67- // "Unknown"
68- // ]
69- // ],
70- // "name": "setUpClass",
71- // "path": "tests/test_kg_gemini.py",
72- // "src": "def setUpClass(cls):\n\n cls.ontology = Ontology([], [])\n\n cls.ontology.add_entity(\n Entity(\n label=\"Actor\",\n attributes=[\n Attribute(\n name=\"name\",\n attr_type=AttributeType.STRING,\n unique=True,\n required=True,\n ),\n ],\n )\n )\n cls.ontology.add_entity(\n Entity(\n label=\"Movie\",\n attributes=[\n Attribute(\n name=\"title\",\n attr_type=AttributeType.STRING,\n unique=True,\n required=True,\n ),\n ],\n )\n )\n cls.ontology.add_relation(\n Relation(\n label=\"ACTED_IN\",\n source=\"Actor\",\n target=\"Movie\",\n attributes=[\n Attribute(\n name=\"role\",\n attr_type=AttributeType.STRING,\n unique=False,\n required=False,\n ),\n ],\n )\n )\n\n cls.graph_name = \"IMDB_gemini\"\n\n model = GeminiGenerativeModel(model_name=\"gemini-1.5-flash-001\")\n cls.kg = KnowledgeGraph(\n name=cls.graph_name,\n ontology=cls.ontology,\n model_config=KnowledgeGraphModelConfig.with_model(model),\n )",
73- // "src_end": 82,
74- // "src_start": 29
75- // }
76- // },
77- // {
78- // "alias": "",
79- // "id": 13,
80- // "labels": [
81- // "Function"
82- // ],
83- // "properties": {
84- // "args": [
85- // [
86- // "self",
87- // "Unknown"
88- // ],
89- // [
90- // "restaurants_kg",
91- // "KnowledgeGraph"
92- // ],
93- // [
94- // "attractions_kg",
95- // "KnowledgeGraph"
96- // ]
97- // ],
98- // "name": "import_data",
99- // "path": "tests/test_multi_agent.py",
100- // "src": "def import_data(\n self,\n restaurants_kg: KnowledgeGraph,\n attractions_kg: KnowledgeGraph,\n ):\n with open(\"tests/data/cities.json\") as f:\n cities = loads(f.read())\n with open(\"tests/data/restaurants.json\") as f:\n restaurants = loads(f.read())\n with open(\"tests/data/attractions.json\") as f:\n attractions = loads(f.read())\n\n for city in cities:\n restaurants_kg.add_node(\n \"City\",\n {\n \"name\": city[\"name\"],\n \"weather\": city[\"weather\"],\n \"population\": city[\"population\"],\n },\n )\n restaurants_kg.add_node(\"Country\", {\"name\": city[\"country\"]})\n restaurants_kg.add_edge(\n \"IN_COUNTRY\",\n \"City\",\n \"Country\",\n {\"name\": city[\"name\"]},\n {\"name\": city[\"country\"]},\n )\n\n attractions_kg.add_node(\n \"City\",\n {\n \"name\": city[\"name\"],\n \"weather\": city[\"weather\"],\n \"population\": city[\"population\"],\n },\n )\n attractions_kg.add_node(\"Country\", {\"name\": city[\"country\"]})\n attractions_kg.add_edge(\n \"IN_COUNTRY\",\n \"City\",\n \"Country\",\n {\"name\": city[\"name\"]},\n {\"name\": city[\"country\"]},\n )\n\n for restaurant in restaurants:\n restaurants_kg.add_node(\n \"Restaurant\",\n {\n \"name\": restaurant[\"name\"],\n \"description\": restaurant[\"description\"],\n \"rating\": restaurant[\"rating\"],\n \"food_type\": restaurant[\"food_type\"],\n },\n )\n restaurants_kg.add_edge(\n \"IN_CITY\",\n \"Restaurant\",\n \"City\",\n {\"name\": restaurant[\"name\"]},\n {\"name\": restaurant[\"city\"]},\n )\n\n for attraction in attractions:\n attractions_kg.add_node(\n \"Attraction\",\n {\n \"name\": attraction[\"name\"],\n \"description\": attraction[\"description\"],\n \"type\": attraction[\"type\"],\n },\n )\n attractions_kg.add_edge(\n \"IN_CITY\",\n \"Attraction\",\n \"City\",\n {\"name\": attraction[\"name\"]},\n {\"name\": attraction[\"city\"]},\n )",
101- // "src_end": 310,
102- // "src_start": 230
103- // }
104- // },
105- // ],
106- // 'edges': [
107- // {
108- // "alias": "",
109- // "dest_node": 13,
110- // "id": 460,
111- // "properties": {},
112- // "relation": "CALLS",
113- // "src_node": 2
114- // },
115- // ]
116- // },
117- // additions: {
118- // 'nodes': [
119- // {
120- // "alias": "",
121- // "id": 13,
122- // "labels": [
123- // "File"
124- // ],
125- // "properties": {
126- // "ext": ".py",
127- // "name": "test_kg_gemini.py",
128- // "path": "tests"
129- // }
130- // },
131- // {
132- // "alias": "",
133- // "id": 2,
134- // "labels": [
135- // "Class"
136- // ],
137- // "properties": {
138- // "doc": "\"\"\"\n Test Knowledge Graph\n \"\"\"",
139- // "name": "TestKGGemini",
140- // "path": "tests/test_kg_gemini.py",
141- // "src_end": 106,
142- // "src_start": 23
143- // }
144- // },
145- // ],
146- // 'edges': [
147- // {
148- // "alias": "",
149- // "dest_node": 13,
150- // "id": 460,
151- // "properties": {},
152- // "relation": "DEFINES",
153- // "src_node": 2
154- // },
155- // ],
156- // },
157- // modifications: {
158- // 'nodes': [
159- // {
160- // "alias": "",
161- // "id": 3,
162- // "labels": [
163- // "Function"
164- // ],
165- // "properties": {
166- // "args": [
167- // []
168- // ],
169- // "name": "",
170- // "path": "",
171- // "src": "",
172- // "src_end": 0,
173- // "src_start": 0
174- // }
175- // },
176- // {
177- // "alias": "",
178- // "id": 61,
179- // "labels": [
180- // "Function"
181- // ],
182- // "properties": {
183- // "args": [
184- // [],
185- // []
186- // ],
187- // "doc": "",
188- // "name": "",
189- // "path": "",
190- // "ret_type": "",
191- // "src": "",
192- // "src_end": 0,
193- // "src_start": 0
194- // }
195- // },
196- // ],
197- // 'edges': [
198- // {
199- // "alias": "",
200- // "dest_node": 61,
201- // "id": 439,
202- // "properties": {
203- // name: "Source"
204- // },
205- // "relation": "CALLS",
206- // "src_node": 3
207- // },
208- // ]
209- // }
210- // }
211- // }, { status: 200 })
212- // }
213- case "autoComplete" : {
214- const prefix = request . nextUrl . searchParams . get ( 'prefix' ) !
215- const result = await fetch ( `${ process . env . BACKEND_URL } /auto_complete` , {
216- method : 'POST' ,
217- body : JSON . stringify ( { repo : graphName , prefix } ) ,
218- headers : {
219- "Authorization" : process . env . SECRET_TOKEN ! ,
220- "Content-Type" : 'application/json'
221- }
222- } )
223-
224- if ( ! result . ok ) {
225- throw new Error ( await result . text ( ) )
226- }
227-
228- const json = await result . json ( )
32+ if ( ! prefix ) {
33+ throw new Error ( "Prefix is required" )
34+ }
22935
230- return NextResponse . json ( { result : json } , { status : 200 } )
36+ const result = await fetch ( `${ process . env . BACKEND_URL } /auto_complete` , {
37+ method : 'POST' ,
38+ body : JSON . stringify ( { repo : params . graph , prefix } ) ,
39+ headers : {
40+ "Authorization" : process . env . SECRET_TOKEN ! ,
41+ "Content-Type" : 'application/json'
23142 }
232- default : {
233- const result = await fetch ( `${ process . env . BACKEND_URL } /repo_info` , {
234- method : 'POST' ,
235- body : JSON . stringify ( { repo : graphName } ) ,
236- headers : {
237- "Authorization" : process . env . SECRET_TOKEN ! ,
238- "Content-Type" : 'application/json'
239- }
240- } )
43+ } )
24144
242- if ( ! result . ok ) {
243- throw new Error ( await result . text ( ) )
244- }
45+ if ( ! result . ok ) {
46+ throw new Error ( await result . text ( ) )
47+ }
24548
246- const json = await result . json ( )
49+ const json = await result . json ( )
24750
248- return NextResponse . json ( { result : json } , { status : 200 } )
249- }
250- }
51+ return NextResponse . json ( { result : json } , { status : 200 } )
25152 } catch ( err ) {
25253 return NextResponse . json ( { message : ( err as Error ) . message } , { status : 400 } )
25354 }
0 commit comments