Skip to content

[Feature Request] Support for more complex HTTP requests in search_engines.js #73

@blacklight

Description

@blacklight
  • Surfingkeys Version: 1.12
  • Surfingkeys-conf Version (git hash): main HEAD
  • Operating System: Any
  • Browser Version: Any

Details

First of all, thanks for the amazing work you've put in this repo! It served me as a solid base to customize my SurfingKeys experience to the next level.

There's a feature I miss quite a bit though, and that's the ability to make HTTP requests other than GET in search_engines.js.

I'm not sure if I missed some polymorphic logic on completions.<search-engine>.search and completions.<search-engine>.compl, but it seems to me that it only supports string parameters (i.e. it only supports GET requests to the URL provided as a template).

That probably works in >90% of the cases, but recently I've implemented on my fork the support for ChatGPT results, and their API only supports POST for the queries.

My workaround has been to spin up my own little service that proxies GET requests to POST requests to the ChatGPT API, and then use that URL for the completions, but this definitely isn't scalable.

I also see it as a problem if somebody wants to implement search results from (x)RPC or GraphQL APIs, since those are likely to take POST/PUT requests.

I may work on a PR for it if there's enough interest. I have two possible approaches in mind:

  1. compl and search can be either strings or objects containing the static configuration of an HTTP request to be passed to e.g. axios. Example:
completions.cg = {
  compl: {
    method: 'POST',
    url: 'https://api.openai.com/v1/completions',
    data: {
      prompt: '$QUERY$',  // I'm open on how to define the user query placeholder
      model: 'text-davinci-003',
      max_tokens: 2048,
    },
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${conf.priv.chatgptKey}`,
    }
  },
  // ...
}
  1. compl and search can be callbacks. Example:
completions.cg = {
  compl: async (query, conf) => {
    return await axios.post(
      'https://api.openai.com/v1/completions',
      {
        prompt: query,
        model: 'text-davinci-003',
        max_tokens: 2048,
      },
      {
        headers: {
          'Content-Type': 'application/json',
          'Authorization': `Bearer ${conf.priv.chatgptKey}`,
        }
      }
  }
  // ...
}

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