yufeikang / raycast_api_proxy

214 stars 30 forks source link

Web search support? #28

Open littleblack111 opened 1 month ago

littleblack111 commented 1 month ago

Will this be added? reffrence: https://github.com/zhuozhiyongde/Unlocking-Raycast-With-Surge/blob/main/app/main.py

I tried to add it my self, but after adding it, gpt will keep returning: count_tools_token_fail: json: cannot unmarshal array into Go value of type dto.OpenAITools (request id: 20240527010538565210467sNOZG6wQ)

code: from app.serp import tool_serp(serp.py is from https://github.com/zhuozhiyongde/Unlocking-Raycast-With-Surge/blob/main/app/functions/serp.py) ... tools.append(self.build_openai_function_img_tool(raycast_data)) tools.append(self.__build_web_search_tool()) async for i in self.warp_chat( ...

... def __build_web_search_tool(self): tools = { "serp": { "description": "Search Engine Results Page", "parameters": { "type": "object", "properties": { "query": { "type": "string", "description": "The search query to be used", } }, },

后面的字段为附属字段,在调用 OpenAI 时会移除

            "handler": tool_serp,
            "notification": 'data: {"notification":"Searching in Google...","notification_type":"tool_used","text":""}\n\n',
            "extra_messages": [
                {
                    "role": "system",
                    "content": "It is possible to summarize the information from the above, but please note that if you use relevant information in your answer, please mark the citation as strictly '[Source](URL)', and note that the first bracket must be the hard-coded English \"Source \"in the first parenthesis, which is relevant for subsequent rendering. You don't have to use markdown's markup syntax.",
                }
            ],
            "required_environ": ["APYHUB_API_KEY"],
        },
    }
    format_tools = []
    for tool in tools:
        if "required_environ" in tools[tool]:
            if any(
                [not os.environ.get(env) for env in tools[tool]["required_environ"]]
            ):
                continue
        format_tools.append(
            {
                "type": "function",
                "function": {
                    "name": tool,
                    "description": tools[tool]["description"],
                    "parameters": tools[tool]["parameters"],
                },
            }
        )

    return format_tools

... from the OpenAIChatBot class

please implement this feature, hope the code helps

littleblack111 commented 3 weeks ago

@yufeikang pls consider