| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import argparse
- import asyncio
- import json
- import re
- from typing import List, Dict, Any
- from pydantic import ValidationError
- from config.settings import MONGO_URL, MONGO_DB_NAME
- from utils.logu import get_logger
- from src.manager.template_manager import TemplateManager
- logger = get_logger('cli')
- import asyncio
- import aiofiles
- import os
- import sys
- template_str = '''[
- {
- "$match": {"product_name": "{{ product_name }}"}
- },
- {
- '$project': {
- 'combined': {
- '$concatArrays': [
- {
- '$map': {
- 'input': '$competitor.results',
- 'as': 'result',
- 'in': {
- 'asin': '$$result.asin',
- 'main_key': '$$result.main_key',
- 'monthly_searches': '$$result.monthly_searches',
- 'type': 'result'
- }
- }
- }, {
- '$map': {
- 'input': '$competitor.tail_keys',
- 'as': 'tail',
- 'in': {
- 'tail_key': '$$tail.tail_key',
- 'monthly_searches': '$$tail.monthly_searches',
- 'type': 'tail_key'
- }
- }
- }
- ]
- }
- }
- }, {
- '$unwind': '$combined'
- }, {
- '$replaceRoot': {
- 'newRoot': '$combined'
- }
- }
- ]'''
- async def task():
- collections = ['Product', 'templates', ]
- m = TemplateManager()
- await m.initialize()
- name = 'agent.mainkeys_tailkeys'
- await m.create_or_update_template(
- name=name,
- collection_name='agent.product',
- template_str=template_str,
- description='获取Agent有关的关键词信息,避免 reason 干扰下一步分析', )
- res = await m.execute_template(name, context={'product_name': '电线保护套'})
- print(res)
- def main():
- asyncio.run(task())
- if __name__ == "__main__":
- main()
|