|
- # -*- coding: utf-8 -*-
- import redis
- import json
- import copy
- import configparser
- from knowledge import Knowledge
- from sources import essource
-
-
- redis_conn = redis.Redis(
- host='192.168.10.244',
- port=6381,
- db=0,
- decode_responses=True)
-
- config = configparser.ConfigParser()
- config.read("settings.ini", encoding="utf-8")
- llmname = ['baidu', 'spark', 'zhipu']
- llmdict = {}
- kldict = {}
- for i in llmname:
- llm_config = dict(config.items(i + 'llm'))
- llms = __import__('llms.%s' % i + 'llm',
- fromlist=['llms'])
- string = 'llms.' + (i + 'llm').capitalize()
- llmdict[i] = eval(string)(**llm_config)
- kldict[i] = Knowledge(i)
- con = dict(config.items('essource'))
- con['index'] = 'a'
- es = essource.Essource(**con)
-
- while True:
- a = redis_conn.lpop("es_question_mark_log")
- if a is not None:
- jo = json.loads(a)
- types = jo['type']
- for k in llmname:
- if k == jo['llm']:
- if jo['like'] < 0:
- redis_conn.rpush('es_question_marked_log', a)
- else:
- es.upload(a)
- else:
- b = copy.deepcopy(jo)
- if b['type'] == 0:
- b['answer'] = llmdict[k].link(b['question'])[0]
- else:
- temp = kldict[k].recommend(b['tenant_id'],
- b['question'])
- if len(temp['data']) > 0:
- answers = []
- for tempanswer in temp['data']['result']:
- answers.append(tempanswer['name'])
- b['answer'] = answers
- else:
- continue
- b['llm'] = k
- b['like'] = -1
- print(b)
- redis_conn.rpush('es_question_marked_log', str(b))
- else:
- print("none")
- break
|