code: #!/usr/bin/env python3
  from dataclasses import dataclass, field
  from typing import cast
  
  from loguru import logger
  from llama_index.core import Document, VectorStoreIndex, Settings
  from llama_index.core.query_engine import CitationQueryEngine
  import nest_asyncio
  
  from uglychain import Model, Retriever, StorageRetriever
  from uglychain.storage import Storage, SQLiteStorage
  from uglychain.llm.llama_index import LlamaIndexLLM
  
  import sys
  import logging
  
  logging.basicConfig(stream=sys.stdout, level=logging.INFO)
  logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
  
  nest_asyncio.apply()
  Settings.llm = LlamaIndexLLM(model=Model.GPT3_TURBO)
  
  
  @dataclass
  class GithubIndex:
      filename: str = "data/github/github.db"
      model: Model = Model.DEFAULT
      summarizer_db: Storage = field(init=False)
      retriever: StorageRetriever = field(init=False)
  
      def __post_init__(self):
          self.summarizer_db = SQLiteStorage(self.filename, "ReadmeSummarizer", 30)
          self.retriever = Retriever.LlamaIndex.getStorage(
              persist_dir="./data/github/repos"
          )
          if self._need_update:
              self._update()
  
      def search(self, query: str):
          index = cast(VectorStoreIndex, self.retriever.index)  # type: ignore
          query_engine = CitationQueryEngine.from_args(index, similarity_top_k=5)
          # query_engine = index.as_query_engine(llm=LlamaIndexLLM(Model.GPT3_TURBO), similarity_top_k=8) # type: ignore
          return query_engine.query(query)
          # self.retriever.get(query, "refine")
  
      @property
      def _need_update(self):
          return False
  
      def _update(self):
          doc_chunks = []
          data = self.summarizer_db.load(condition="timestamp = date('now','localtime')")
          for key, value in data.items():
              doc = Document(text=value, doc_id=key)
              doc_chunks.append(doc)
          index = cast(VectorStoreIndex, self.retriever.index)  # type: ignore
          logger.info("refresh_ref_docs")
          index.refresh_ref_docs(doc_chunks)
          self.retriever.storage.save(index)
          logger.info("refresh_ref_docs done")
  
  
  if __name__ == "__main__":
      index = GithubIndex()
      result = index.search("给我介绍几个关于使用大模型自动写代码的项目吧！")
      # logger.debug(result.source_nodes)
      logger.info(result)
  
apis: llama_index.core.query_engine.CitationQueryEngine.from_args llama_index.core.Document
extract_api: [((454, 512), 'logging.basicConfig', 'logging.basicConfig', ([], {'stream': 'sys.stdout', 'level': 'logging.INFO'}), '(stream=sys.stdout, level=logging.INFO)\n', (473, 512), False, 'import logging\n'), ((587, 607), 'nest_asyncio.apply', 'nest_asyncio.apply', ([], {}), '()\n', (605, 607), False, 'import nest_asyncio\n'), ((623, 660), 'uglychain.llm.llama_index.LlamaIndexLLM', 'LlamaIndexLLM', ([], {'model': 'Model.GPT3_TURBO'}), '(model=Model.GPT3_TURBO)\n', (636, 660), False, 'from uglychain.llm.llama_index import LlamaIndexLLM\n'), ((544, 584), 'logging.StreamHandler', 'logging.StreamHandler', ([], {'stream': 'sys.stdout'}), '(stream=sys.stdout)\n', (565, 584), False, 'import logging\n'), ((799, 816), 'dataclasses.field', 'field', ([], {'init': '(False)'}), '(init=False)\n', (804, 816), False, 'from dataclasses import dataclass, field\n'), ((851, 868), 'dataclasses.field', 'field', ([], {'init': '(False)'}), '(init=False)\n', (856, 868), False, 'from dataclasses import dataclass, field\n'), ((2276, 2295), 'loguru.logger.info', 'logger.info', (['result'], {}), '(result)\n', (2287, 2295), False, 'from loguru import logger\n'), ((513, 532), 'logging.getLogger', 'logging.getLogger', ([], {}), '()\n', (530, 532), False, 'import logging\n'), ((928, 980), 'uglychain.storage.SQLiteStorage', 'SQLiteStorage', (['self.filename', '"""ReadmeSummarizer"""', '(30)'], {}), "(self.filename, 'ReadmeSummarizer', 30)\n", (941, 980), False, 'from uglychain.storage import Storage, SQLiteStorage\n'), ((1006, 1072), 'uglychain.Retriever.LlamaIndex.getStorage', 'Retriever.LlamaIndex.getStorage', ([], {'persist_dir': '"""./data/github/repos"""'}), "(persist_dir='./data/github/repos')\n", (1037, 1072), False, 'from uglychain import Model, Retriever, StorageRetriever\n'), ((1203, 1247), 'typing.cast', 'cast', (['VectorStoreIndex', 'self.retriever.index'], {}), '(VectorStoreIndex, self.retriever.index)\n', (1207, 1247), False, 'from typing import cast\n'), ((1287, 1343), 'llama_index.core.query_engine.CitationQueryEngine.from_args', 'CitationQueryEngine.from_args', (['index'], {'similarity_top_k': '(5)'}), '(index, similarity_top_k=5)\n', (1316, 1343), False, 'from llama_index.core.query_engine import CitationQueryEngine\n'), ((1892, 1936), 'typing.cast', 'cast', (['VectorStoreIndex', 'self.retriever.index'], {}), '(VectorStoreIndex, self.retriever.index)\n', (1896, 1936), False, 'from typing import cast\n'), ((1961, 1992), 'loguru.logger.info', 'logger.info', (['"""refresh_ref_docs"""'], {}), "('refresh_ref_docs')\n", (1972, 1992), False, 'from loguru import logger\n'), ((2087, 2123), 'loguru.logger.info', 'logger.info', (['"""refresh_ref_docs done"""'], {}), "('refresh_ref_docs done')\n", (2098, 2123), False, 'from loguru import logger\n'), ((1808, 1840), 'llama_index.core.Document', 'Document', ([], {'text': 'value', 'doc_id': 'key'}), '(text=value, doc_id=key)\n', (1816, 1840), False, 'from llama_index.core import Document, VectorStoreIndex, Settings\n')]