评分系统分流部分的代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. import redis
  3. import json
  4. import copy
  5. import configparser
  6. from knowledge import Knowledge
  7. from sources import essource
  8. redis_conn = redis.Redis(
  9. host='192.168.10.244',
  10. port=6381,
  11. db=0,
  12. decode_responses=True)
  13. config = configparser.ConfigParser()
  14. config.read("settings.ini", encoding="utf-8")
  15. llmname = ['baidu', 'spark', 'zhipu']
  16. llmdict = {}
  17. kldict = {}
  18. for i in llmname:
  19. llm_config = dict(config.items(i + 'llm'))
  20. llms = __import__('llms.%s' % i + 'llm',
  21. fromlist=['llms'])
  22. string = 'llms.' + (i + 'llm').capitalize()
  23. llmdict[i] = eval(string)(**llm_config)
  24. kldict[i] = Knowledge(i)
  25. con = dict(config.items('essource'))
  26. con['index'] = 'a'
  27. es = essource.Essource(**con)
  28. while True:
  29. a = redis_conn.lpop("es_question_mark_log")
  30. if a is not None:
  31. jo = json.loads(a)
  32. types = jo['type']
  33. for k in llmname:
  34. if k == jo['llm']:
  35. if jo['like'] < 0:
  36. redis_conn.rpush('es_question_marked_log', a)
  37. else:
  38. es.upload(a)
  39. else:
  40. b = copy.deepcopy(jo)
  41. if b['type'] == 0:
  42. b['answer'] = llmdict[k].link(b['question'])[0]
  43. else:
  44. temp = kldict[k].recommend(b['tenant_id'],
  45. b['question'])
  46. if len(temp['data']) > 0:
  47. answers = []
  48. for tempanswer in temp['data']['result']:
  49. answers.append(tempanswer['name'])
  50. b['answer'] = answers
  51. else:
  52. continue
  53. b['llm'] = k
  54. b['like'] = -1
  55. print(b)
  56. redis_conn.rpush('es_question_marked_log', str(b))
  57. else:
  58. print("none")
  59. break