tencentdb_ai is the premise for an instance of PostgreSQL 17 already created.tencentdb_ai plug-in will associate the creation of the pgcrypto plug-in. Please be informed.add_model function defined as follows:tencentdb_ai.add_model(model_name NAME,version TEXT,region TEXT,json_path JSONPATH);
hunyuan-lite, deepseek-r1version. Leave it blank if version is not required.region. Leave it blank if region is not required.JSON response from this model during a call. It is equivalent to performing the jsonb_path_query_first function on the model output. If this parameter is not set, the original response of the model is output by default.list_models function defined as follows:tencentdb_ai.list_models(void);
update_model_attr function defined as follows:tencentdb_ai.update_model_attr(model_name NAME,attr_name text,attr_value text);
version, region, json_path, SecretId, SecretKey.delete_model function defined as follows:tencentdb_ai.delete_model(model_name NAME);
tencentdb_ai.call_model(model_name NAME,common_params TEXT[],api_params TEXT[]);
ARRAY['Action: ChatCompletions', 'Version: 2023-09-01']ARRAY['"Stream": false', '"Model": "hunyuan-lite"', '"Messages": [{"Role": "user", "Content": "Hello"}]']call_model function for model invocation, you can also use the following APIs for model invocation in specific scenarios.chat_completions function definition is as follows:tencentdb_ai.chat_completions(model_name NAME,content TEXT,args TEXT[] default NULL);
SELECT tencentdb_ai.chat_completions('hunyuan-lite', 'Hello');chat_completions----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------{"Response":{"RequestId":"*******-****-****-****-***********","Note":"The above content is AI generation and does not mean the developer standpoint, do not delete or modify this tag","Choices":[{"Index":0,"Message":{"Role":"assistant","CoHello. Glad to chat with you. What would you like to share today?nTokens":17,"TotalTokens":20}}}(1 row)
get_embedding function definition as follows:tencentdb_ai.get_embedding(model_name NAME,content TEXT[]);
damoxing1=> SELECT tencentdb_ai.get_embedding('hunyuan-embedding',ARRAY['Hello', 'PostgreSQL']);
run_rerank function defined as follows:tencentdb_ai.run_rerank(model_name NAME,query TEXT,documents TEXT[],args TEXT[] DEFAULT NULL);
damoxing1=> SELECT COUNT(*) FROM tencentdb_ai.run_rerank('lke-reranker-base', 'knowledge engine large model', ARRAY['HunYuan Large Model', 'Tencent knowledge engine']);count-------2(1 row)
The function definition of image_to_text is as follows:tencentdb_ai.image_to_text(model_name NAME,query TEXT,image TEXT,args TEXT[] DEFAULT NULL);
damoxing=> CREATE EXTENSION tencentdb_ai CASCADE;NOTICE: installing required extension "pgcrypto"CREATE EXTENSION
damoxing=> SELECT * FROM pg_extension;oid | extname | extowner | extnamespace | extrelocatable | extversion | extconfig | extcondition-------+--------------+----------+--------------+----------------+------------+-----------+--------------14275 | plpgsql | 10 | 11 | f | 1.0 | |16440 | pgcrypto | 16437 | 2200 | t | 1.3 | |16477 | tencentdb_ai | 16437 | 2200 | t | 1.0 | {16479} | {""}(3 rows)
damoxing=> SELECT tencentdb_ai.add_model('hunyuan-lite','2023-09-01', NULL, NULL);add_model-----------(1 row)
damoxing=> SELECT tencentdb_ai.update_model_attr('hunyuan-lite', 'SecretId', 'AKID***************');update_model_attr-------------------(1 row)damoxing=> SELECT tencentdb_ai.update_model_attr('hunyuan-lite', 'SecretKey', '********************');update_model_attr-------------------(1 row)
damoxing=> SELECT * FROM tencentdb_ai.list_models();-[ RECORD 1 ]--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------model_name | hunyuan-litejson_path |secretid | ***************************secretkey | ***************************version |region |id_random | 516234453022key_random | 134577899689
call_model API.damoxing=> SELECT tencentdb_ai.call_model('hunyuan-lite',ARRAY['Action: ChatCompletions', 'Version: 2023-09-01'],ARRAY['"Stream": false', '"Model": "hunyuan-lite"', '"Messages": [{"Role": "user", "Content": "Hello"}]']);call_model------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------{"Response":{"RequestId":"*******-****-****-****-***********","Note":"The above content is AI generation and does not mean the developer standpoint, do not delete or modify this tag","Chchoices":[{"Index":0,"Message":{"Role":"assistant","Content":"Hello! I'm happy to chat with you. What can I help you with? Whether it's about life, work, or learning."}}]}study or other issues, I'll do my best to offer help."},"FinishReason":"stop"}],"Created":1739793838,"Id":"*******-****-****-****-***********","Usage":{"PromptTokens":3,"CompletionTokens":33,"TotalTokens":36}}}(1 row)damoxing=>
Feedback