SLKun commited on
Commit
2c09f98
·
1 Parent(s): 97f247c

update ollama compatible api

Browse files
Files changed (1) hide show
  1. lightrag/api/routers/ollama_api.py +26 -2
lightrag/api/routers/ollama_api.py CHANGED
@@ -234,7 +234,7 @@ class OllamaAPI:
234
  @self.router.get("/version", dependencies=[Depends(combined_auth)])
235
  async def get_version():
236
  """Get Ollama version information"""
237
- return OllamaVersionResponse(version="0.5.4")
238
 
239
  @self.router.get("/tags", dependencies=[Depends(combined_auth)])
240
  async def get_tags():
@@ -244,9 +244,9 @@ class OllamaAPI:
244
  {
245
  "name": self.ollama_server_infos.LIGHTRAG_MODEL,
246
  "model": self.ollama_server_infos.LIGHTRAG_MODEL,
 
247
  "size": self.ollama_server_infos.LIGHTRAG_SIZE,
248
  "digest": self.ollama_server_infos.LIGHTRAG_DIGEST,
249
- "modified_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
250
  "details": {
251
  "parent_model": "",
252
  "format": "gguf",
@@ -337,7 +337,10 @@ class OllamaAPI:
337
  data = {
338
  "model": self.ollama_server_infos.LIGHTRAG_MODEL,
339
  "created_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
 
340
  "done": True,
 
 
341
  "total_duration": total_time,
342
  "load_duration": 0,
343
  "prompt_eval_count": prompt_tokens,
@@ -377,6 +380,7 @@ class OllamaAPI:
377
  "model": self.ollama_server_infos.LIGHTRAG_MODEL,
378
  "created_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
379
  "response": f"\n\nError: {error_msg}",
 
380
  "done": False,
381
  }
382
  yield f"{json.dumps(error_data, ensure_ascii=False)}\n"
@@ -385,6 +389,7 @@ class OllamaAPI:
385
  final_data = {
386
  "model": self.ollama_server_infos.LIGHTRAG_MODEL,
387
  "created_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
 
388
  "done": True,
389
  }
390
  yield f"{json.dumps(final_data, ensure_ascii=False)}\n"
@@ -399,7 +404,10 @@ class OllamaAPI:
399
  data = {
400
  "model": self.ollama_server_infos.LIGHTRAG_MODEL,
401
  "created_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
 
402
  "done": True,
 
 
403
  "total_duration": total_time,
404
  "load_duration": 0,
405
  "prompt_eval_count": prompt_tokens,
@@ -444,6 +452,8 @@ class OllamaAPI:
444
  "created_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
445
  "response": str(response_text),
446
  "done": True,
 
 
447
  "total_duration": total_time,
448
  "load_duration": 0,
449
  "prompt_eval_count": prompt_tokens,
@@ -557,6 +567,12 @@ class OllamaAPI:
557
  data = {
558
  "model": self.ollama_server_infos.LIGHTRAG_MODEL,
559
  "created_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
 
 
 
 
 
 
560
  "done": True,
561
  "total_duration": total_time,
562
  "load_duration": 0,
@@ -605,6 +621,7 @@ class OllamaAPI:
605
  "content": f"\n\nError: {error_msg}",
606
  "images": None,
607
  },
 
608
  "done": False,
609
  }
610
  yield f"{json.dumps(error_data, ensure_ascii=False)}\n"
@@ -613,6 +630,11 @@ class OllamaAPI:
613
  final_data = {
614
  "model": self.ollama_server_infos.LIGHTRAG_MODEL,
615
  "created_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
 
 
 
 
 
616
  "done": True,
617
  }
618
  yield f"{json.dumps(final_data, ensure_ascii=False)}\n"
@@ -633,6 +655,7 @@ class OllamaAPI:
633
  "content": "",
634
  "images": None,
635
  },
 
636
  "done": True,
637
  "total_duration": total_time,
638
  "load_duration": 0,
@@ -697,6 +720,7 @@ class OllamaAPI:
697
  "content": str(response_text),
698
  "images": None,
699
  },
 
700
  "done": True,
701
  "total_duration": total_time,
702
  "load_duration": 0,
 
234
  @self.router.get("/version", dependencies=[Depends(combined_auth)])
235
  async def get_version():
236
  """Get Ollama version information"""
237
+ return OllamaVersionResponse(version="0.9.3")
238
 
239
  @self.router.get("/tags", dependencies=[Depends(combined_auth)])
240
  async def get_tags():
 
244
  {
245
  "name": self.ollama_server_infos.LIGHTRAG_MODEL,
246
  "model": self.ollama_server_infos.LIGHTRAG_MODEL,
247
+ "modified_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
248
  "size": self.ollama_server_infos.LIGHTRAG_SIZE,
249
  "digest": self.ollama_server_infos.LIGHTRAG_DIGEST,
 
250
  "details": {
251
  "parent_model": "",
252
  "format": "gguf",
 
337
  data = {
338
  "model": self.ollama_server_infos.LIGHTRAG_MODEL,
339
  "created_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
340
+ "response": "",
341
  "done": True,
342
+ "done_reason": "stop",
343
+ "context": [],
344
  "total_duration": total_time,
345
  "load_duration": 0,
346
  "prompt_eval_count": prompt_tokens,
 
380
  "model": self.ollama_server_infos.LIGHTRAG_MODEL,
381
  "created_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
382
  "response": f"\n\nError: {error_msg}",
383
+ "error": f"\n\nError: {error_msg}",
384
  "done": False,
385
  }
386
  yield f"{json.dumps(error_data, ensure_ascii=False)}\n"
 
389
  final_data = {
390
  "model": self.ollama_server_infos.LIGHTRAG_MODEL,
391
  "created_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
392
+ "response": "",
393
  "done": True,
394
  }
395
  yield f"{json.dumps(final_data, ensure_ascii=False)}\n"
 
404
  data = {
405
  "model": self.ollama_server_infos.LIGHTRAG_MODEL,
406
  "created_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
407
+ "response": "",
408
  "done": True,
409
+ "done_reason": "stop",
410
+ "context": [],
411
  "total_duration": total_time,
412
  "load_duration": 0,
413
  "prompt_eval_count": prompt_tokens,
 
452
  "created_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
453
  "response": str(response_text),
454
  "done": True,
455
+ "done_reason": "stop",
456
+ "context": [],
457
  "total_duration": total_time,
458
  "load_duration": 0,
459
  "prompt_eval_count": prompt_tokens,
 
567
  data = {
568
  "model": self.ollama_server_infos.LIGHTRAG_MODEL,
569
  "created_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
570
+ "message": {
571
+ "role": "assistant",
572
+ "content": "",
573
+ "images": None,
574
+ },
575
+ "done_reason": "stop",
576
  "done": True,
577
  "total_duration": total_time,
578
  "load_duration": 0,
 
621
  "content": f"\n\nError: {error_msg}",
622
  "images": None,
623
  },
624
+ "error": f"\n\nError: {error_msg}",
625
  "done": False,
626
  }
627
  yield f"{json.dumps(error_data, ensure_ascii=False)}\n"
 
630
  final_data = {
631
  "model": self.ollama_server_infos.LIGHTRAG_MODEL,
632
  "created_at": self.ollama_server_infos.LIGHTRAG_CREATED_AT,
633
+ "message": {
634
+ "role": "assistant",
635
+ "content": "",
636
+ "images": None,
637
+ },
638
  "done": True,
639
  }
640
  yield f"{json.dumps(final_data, ensure_ascii=False)}\n"
 
655
  "content": "",
656
  "images": None,
657
  },
658
+ "done_reason": "stop",
659
  "done": True,
660
  "total_duration": total_time,
661
  "load_duration": 0,
 
720
  "content": str(response_text),
721
  "images": None,
722
  },
723
+ "done_reason": "stop",
724
  "done": True,
725
  "total_duration": total_time,
726
  "load_duration": 0,