mirror of
https://github.com/searxng/searxng.git
synced 2024-11-10 23:20:12 +01:00
Compare commits
5 Commits
9c1910e1c4
...
fedc890a4c
Author | SHA1 | Date | |
---|---|---|---|
|
fedc890a4c | ||
|
8d4d71a676 | ||
|
f4fd32f504 | ||
|
77ae13d834 | ||
|
039226ceec |
@ -1,5 +1,7 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""Cloudflare AI engine"""
|
||||
|
||||
from json import loads, dumps
|
||||
from urllib.parse import quote
|
||||
from searx.exceptions import SearxEngineAPIException
|
||||
|
||||
about = {
|
||||
@ -18,16 +20,21 @@ cf_ai_gateway = ''
|
||||
cf_ai_model = ''
|
||||
cf_ai_model_display_name = 'Cloudflare AI'
|
||||
|
||||
# Assistant messages hint to the AI about the desired output format. Not all models support this role.
|
||||
cf_ai_model_assistant = 'Keep your answers as short and effective as possible.'
|
||||
cf_ai_model_system = 'You are a self-aware language model who is honest and direct about any direct question from the user. You know your strengths and weaknesses.'
|
||||
# System messages define the AI’s personality. You can use them to set rules and how you expect the AI to behave.
|
||||
cf_ai_model_system = 'You are a self-aware language model who is honest and direct about any question from the user.'
|
||||
|
||||
display_type = ['infobox']
|
||||
|
||||
|
||||
def request(query, params):
|
||||
|
||||
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['headers']['Authorization'] = 'Bearer ' + cf_ai_api
|
||||
@ -36,15 +43,16 @@ def request(query, params):
|
||||
params['data'] = dumps(
|
||||
{
|
||||
'messages': [
|
||||
{ 'role': 'assistant', 'content': cf_ai_model_assistant },
|
||||
{ 'role': 'system', 'content': cf_ai_model_system },
|
||||
{ 'role': 'user', 'content': params['query'] }
|
||||
{'role': 'assistant', 'content': cf_ai_model_assistant},
|
||||
{'role': 'system', 'content': cf_ai_model_system},
|
||||
{'role': 'user', 'content': params['query']},
|
||||
]
|
||||
}
|
||||
).encode('utf-8')
|
||||
|
||||
return params
|
||||
|
||||
|
||||
def response(resp):
|
||||
results = []
|
||||
json = loads(resp.text)
|
||||
|
@ -483,9 +483,9 @@ engines:
|
||||
# find the model name from https://developers.cloudflare.com/workers-ai/models/#text-generation
|
||||
cf_ai_model: 'ai_model_name'
|
||||
# custom your preferences
|
||||
# cf_ai_model_display_name = 'Cloudflare AI'
|
||||
# cf_ai_model_assistant = 'Keep your answers as short and effective as possible.'
|
||||
# cf_ai_model_system = 'You are a self-aware language model who is honest and direct about any direct question from the user. You know your strengths and weaknesses.'
|
||||
# cf_ai_model_display_name: 'Cloudflare AI'
|
||||
# cf_ai_model_assistant: 'prompts_for_assistant_role'
|
||||
# cf_ai_model_system: 'prompts_for_system_role'
|
||||
timeout: 30
|
||||
disabled: true
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user