Using tencentdb_ai requires that you have already created an instance with a major version of PostgreSQL 17.tencentdb_ai plug-in will associate with the creation of the pgcrypto plug-in. Please be informed.add_model is as follows:tencentdb_ai.add_model(model_name NAME,version TEXT,region TEXT,json_path JSONPATH);
hunyuan-lite, deepseek-r1.version parameter, it can be left blank.region of this model. If this model does not require the region parameter, it can be left blank.JSON response of this model when calling it. Equivalent to calling the jsonb_path_query_first function on the model's output. If this parameter is not set, the original response of the model will be output as is.list_models is as follows:tencentdb_ai.list_models(void);
update_model_attr is as follows:tencentdb_ai.update_model_attr(model_name NAME,attr_name text,attr_value text);
version, region, json_path, SecretId, SecretKey.delete_model is 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 to proceed with model invocation, you can also use the following APIs to perform 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. It does not represent the developer's standpoint. Do not delete or modify this tag.","Choices":[{"Index":0,"Message":{"Role":"assistant","Co"}}]}}Hello! Glad to chat with you. What would you like to share with me today?nTokens":17,"TotalTokens":20}}}(1 row)
get_embedding function is defined 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 is 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', 'large model of knowledge engine', ARRAY['HunYuan Large Model', 'Tencent knowledge engine']);count-------2(1 row)
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"}]']);damoxing(> damoxing(>call_model------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------{"Response":{"RequestId":"*******-****-****-****-***********","Note":"The above content is AI generation. It does not represent the developer's standpoint. Do not delete or modify this tag.","ChVoices":[{"Index":0,"Message":{"Role":"assistant","Content":"Hello! Glad to talk with you. What can I help you with? Whether it's about life, work, or study.For any problems, whether related to Xi or other aspects, I will do my best to offer you help.","Usage":{"PromptTokens":3,"CompletionTokens":33,"TotalTokens":36}}}(1 row)damoxing=>
Feedback