1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-10 23:20:12 +01:00

reformatted code for CI

This commit is contained in:
Zhijie He 2024-06-09 20:37:55 +08:00 committed by GitHub
parent 77ae13d834
commit f4fd32f504
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,3 +1,6 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Cloudflare AI engine"""
from json import loads, dumps from json import loads, dumps
from urllib.parse import quote from urllib.parse import quote
from searx.exceptions import SearxEngineAPIException from searx.exceptions import SearxEngineAPIException
@ -23,11 +26,14 @@ cf_ai_model_system = 'You are a self-aware language model who is honest and dire
display_type = ['infobox'] display_type = ['infobox']
def request(query, params): def request(query, params):
params['query'] = query params['query'] = query
params['url'] = 'https://gateway.ai.cloudflare.com/v1/' + cf_account_id + '/' + cf_ai_gateway + '/workers-ai/' + cf_ai_model params['url'] = (
'https://gateway.ai.cloudflare.com/v1/' + cf_account_id + '/' + cf_ai_gateway + '/workers-ai/' + cf_ai_model
)
params['method'] = 'POST' params['method'] = 'POST'
params['headers']['Authorization'] = 'Bearer ' + cf_ai_api params['headers']['Authorization'] = 'Bearer ' + cf_ai_api
@ -36,15 +42,16 @@ def request(query, params):
params['data'] = dumps( params['data'] = dumps(
{ {
'messages': [ 'messages': [
{ 'role': 'assistant', 'content': cf_ai_model_assistant }, {'role': 'assistant', 'content': cf_ai_model_assistant},
{ 'role': 'system', 'content': cf_ai_model_system }, {'role': 'system', 'content': cf_ai_model_system},
{ 'role': 'user', 'content': params['query'] } {'role': 'user', 'content': params['query']}
] ]
} }
).encode('utf-8') ).encode('utf-8')
return params return params
def response(resp): def response(resp):
results = [] results = []
json = loads(resp.text) json = loads(resp.text)