mMrBun / AIPC

Apache License 2.0
56 stars 20 forks source link

旧版本代码 #13

Closed 2576591129 closed 8 months ago

2576591129 commented 8 months ago

您好,请问下旧版本的chat2bi 代码您还有嘛?就是没有 api 搜索的功能,您在上一年11月中旬上传的,那个版本的更加简洁明了的看到chatglm3的两个功能

mMrBun commented 8 months ago

@2576591129 你看下git历史提交记录应该可以看到

mMrBun commented 8 months ago

@2576591129 不知道你要的是不是这个,这个是我最开始写的一个版本

import json
from transformers import AutoTokenizer, AutoModel

from tools import system_info

tokenizer = AutoTokenizer.from_pretrained("/data/models/llm/chatglm3-6b/", trust_remote_code=True)
model = AutoModel.from_pretrained("/data/models/llm/chatglm3-6b/", trust_remote_code=True).cuda()
model = model.eval()

def model_chat(task_query):
    model_history = [system_info]
    model_response, model_history = model.chat(tokenizer, task_query, history=model_history)
    return run_task(model_response, model_history)

def run_task(model_response, model_history):
    if isinstance(model_response, dict):
        import function_map
        func = getattr(function_map, model_response.get("name"))
        param = model_response.get("parameters")
        func_response = func(**param)
        result = json.dumps(func_response, ensure_ascii=False)
        model_response, model_history = model.chat(tokenizer, result, history=model_history, role="observation")
        model_response, model_history = run_task(model_response, model_history)
        return model_response, model_history
    else:
        return model_response, model_history

if __name__ == '__main__':
    query = """
        今天下午我要去北京出差,请帮我查询一下当地的天气,另外我应该采取什么样的穿衣风格?
    """
    response, _ = model_chat(query)
    print(response)
2576591129 commented 8 months ago

好的 感谢感谢,我用git checkout 找到了,感谢大佬的分享,希望您可以持续分享