from scholarly import scholarly


def search_and_format_reference(query):
    # 搜索文章
    search_query = scholarly.search_pubs("Graphof thoughts")


    # 获取搜索结果中的第一个匹配项
    first_match = next(search_query, None)
    print("first_match", first_match)

    # if first_match:
    #     # 提取文章的详细信息
    #     article = scholarly.fill(first_match)
    #
    #     # 构建引用格式
    #     authors = ', '.join([author['name'] for author in article['bib']['author']])
    #     title = article['bib']['title']
    #     conference = article['bib'].get('journal', article['bib'].get('conference', ''))
    #     year = article['bib']['pub_year']
    #     pages = article['bib'].get('pages', '')
    #     publisher = article['bib'].get('publisher', 'Unknown Publisher')
    #
    #     # 格式化为标准引用
    #     reference = f"{authors}. {title}. In {conference}, {pages}, {publisher}, {year}."
    #     return reference
    # else:
    #     return "No matching article found."
