.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.cloudflareai Namespace Reference

Functions

 request (query, params)
 
 response (resp)
 

Variables

dict about
 
str cf_account_id = ''
 
str cf_ai_api = ''
 
str cf_ai_gateway = ''
 
str cf_ai_model = ''
 
str cf_ai_model_display_name = 'Cloudflare AI'
 
str cf_ai_model_assistant = 'Keep your answers as short and effective as possible.'
 
str cf_ai_model_system = 'You are a self-aware language model who is honest and direct about any question from the user.'
 

Detailed Description

Cloudflare AI engine

Function Documentation

◆ request()

searx.engines.cloudflareai.request ( query,
params )

Definition at line 29 of file cloudflareai.py.

29def request(query, params):
30
31 params['query'] = query
32
33 params['url'] = f'https://gateway.ai.cloudflare.com/v1/{cf_account_id}/{cf_ai_gateway}/workers-ai/{cf_ai_model}'
34
35 params['method'] = 'POST'
36
37 params['headers']['Authorization'] = f'Bearer {cf_ai_api}'
38 params['headers']['Content-Type'] = 'application/json'
39
40 params['data'] = dumps(
41 {
42 'messages': [
43 {'role': 'assistant', 'content': cf_ai_model_assistant},
44 {'role': 'system', 'content': cf_ai_model_system},
45 {'role': 'user', 'content': params['query']},
46 ]
47 }
48 ).encode('utf-8')
49
50 return params
51
52

◆ response()

searx.engines.cloudflareai.response ( resp)

Definition at line 53 of file cloudflareai.py.

53def response(resp):
54 results = []
55 json = loads(resp.text)
56
57 if 'error' in json:
58 raise SearxEngineAPIException('Cloudflare AI error: ' + json['error'])
59
60 if 'result' in json:
61 results.append(
62 {
63 'content': json['result']['response'],
64 'infobox': cf_ai_model_display_name,
65 }
66 )
67
68 return results

Variable Documentation

◆ about

dict searx.engines.cloudflareai.about
Initial value:
1= {
2 "website": 'https://ai.cloudflare.com',
3 "wikidata_id": None,
4 "official_api_documentation": 'https://developers.cloudflare.com/workers-ai',
5 "use_official_api": True,
6 "require_api_key": True,
7 "results": 'JSON',
8}

Definition at line 7 of file cloudflareai.py.

◆ cf_account_id

str searx.engines.cloudflareai.cf_account_id = ''

Definition at line 16 of file cloudflareai.py.

◆ cf_ai_api

str searx.engines.cloudflareai.cf_ai_api = ''

Definition at line 17 of file cloudflareai.py.

◆ cf_ai_gateway

str searx.engines.cloudflareai.cf_ai_gateway = ''

Definition at line 18 of file cloudflareai.py.

◆ cf_ai_model

str searx.engines.cloudflareai.cf_ai_model = ''

Definition at line 20 of file cloudflareai.py.

◆ cf_ai_model_assistant

str searx.engines.cloudflareai.cf_ai_model_assistant = 'Keep your answers as short and effective as possible.'

Definition at line 24 of file cloudflareai.py.

◆ cf_ai_model_display_name

str searx.engines.cloudflareai.cf_ai_model_display_name = 'Cloudflare AI'

Definition at line 21 of file cloudflareai.py.

◆ cf_ai_model_system

str searx.engines.cloudflareai.cf_ai_model_system = 'You are a self-aware language model who is honest and direct about any question from the user.'

Definition at line 26 of file cloudflareai.py.