(self, load_dict)
| 1464 | |
| 1465 | class ConversationBot: |
| 1466 | def __init__(self, load_dict): |
| 1467 | # load_dict = {'VisualQuestionAnswering':'cuda:0', 'ImageCaptioning':'cuda:1',...} |
| 1468 | print(f"Initializing VisualChatGPT, load_dict={load_dict}") |
| 1469 | if 'ImageCaptioning' not in load_dict: |
| 1470 | raise ValueError("You have to load ImageCaptioning as a basic function for VisualChatGPT") |
| 1471 | |
| 1472 | self.models = {} |
| 1473 | # Load Basic Foundation Models |
| 1474 | for class_name, device in load_dict.items(): |
| 1475 | self.models[class_name] = globals()[class_name](device=device) |
| 1476 | |
| 1477 | # Load Template Foundation Models |
| 1478 | for class_name, module in globals().items(): |
| 1479 | if getattr(module, 'template_model', False): |
| 1480 | template_required_names = {k for k in inspect.signature(module.__init__).parameters.keys() if k!='self'} |
| 1481 | loaded_names = set([type(e).__name__ for e in self.models.values()]) |
| 1482 | if template_required_names.issubset(loaded_names): |
| 1483 | self.models[class_name] = globals()[class_name]( |
| 1484 | **{name: self.models[name] for name in template_required_names}) |
| 1485 | |
| 1486 | print(f"All the Available Functions: {self.models}") |
| 1487 | |
| 1488 | self.tools = [] |
| 1489 | for instance in self.models.values(): |
| 1490 | for e in dir(instance): |
| 1491 | if e.startswith('inference'): |
| 1492 | func = getattr(instance, e) |
| 1493 | self.tools.append(Tool(name=func.name, description=func.description, func=func)) |
| 1494 | self.llm = OpenAI(temperature=0) |
| 1495 | self.memory = ConversationBufferMemory(memory_key="chat_history", output_key='output') |
| 1496 | |
| 1497 | def init_agent(self, lang): |
| 1498 | self.memory.clear() #clear previous history |
nothing calls this directly
no outgoing calls
no test coverage detected