Skip to content

请求:增加重试功能,openai传入参数配置化,增加获取当前时间的工具 #104

@Remhardt

Description

@Remhardt

想要增加三个功能点

  1. 增加重试功能,当前在 openai_llm.py这个函数中,如果大模型返回不符合规定结构或者调用失败,整个任务就无法进行,希望可以增加内部重试功能,且重试次数可配置。
  2. 同样是在这里,希望可以把配置形成.json文件,然后可以直接解包传入api,这样应该可以多兼容其他家模型,例如我这边使用的bigmodel模型就是去掉了那个参数。
  3. 希望可以在工具列表里增加“获取当前时间”的工具,当然也可以在prompt里面自己调用后嵌入。当前如果任务大模型决定不使用web和搜索时可能会存在大模型不清楚具体当前具体时间,导致给出过期信息的问题。
    async def ask(self, messages: List[Dict[str, str]], 
                tools: Optional[List[Dict[str, Any]]] = None,
                response_format: Optional[Dict[str, Any]] = None,
                tool_choice: Optional[str] = None) -> Dict[str, Any]:
        """Send chat request to OpenAI API"""
        response = None
        try:
            if tools:
                logger.debug(f"Sending request to OpenAI with tools, model: {self._model_name}")
                response = await self.client.chat.completions.create(
                    model=self._model_name,
                    temperature=self._temperature,
                    max_tokens=self._max_tokens,
                    messages=messages,
                    tools=tools,
                    response_format=response_format,
                    tool_choice=tool_choice,
                    parallel_tool_calls=False,  #去掉后可以兼容bigmodel的使用
                )
            else:
                logger.debug(f"Sending request to OpenAI without tools, model: {self._model_name}")
                response = await self.client.chat.completions.create(
                    model=self._model_name,
                    temperature=self._temperature,
                    max_tokens=self._max_tokens,
                    messages=messages,
                    response_format=response_format,
                )
            logger.debug(f"Response from OpenAI: {response.model_dump()}")
            return response.choices[0].message.model_dump()
        except Exception as e:
            logger.error(f"Error calling OpenAI API: {str(e)}")
            raise

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions