tencentdb_ai is that you have already created an instance with the major version PostgreSQL 17.tencentdb_ai plugin will also create the pgcrypto plugin. Please be aware of this.add_model function is defined as follows:tencentdb_ai.add_model(model_name NAME,version TEXT,region TEXT,json_path JSONPATH);
hunyuan-lite, deepseek-r1, and so onversion for this model. If the model does not require the version parameter, you can leave it blank.region for this model. If the model does not require the region parameter, you can leave it blank.JSON response when the model is called. This is equivalent to applying the jsonb_path_query_first function to the model output. If this parameter is not specified, the model's raw response is output as-is by default.list_models function is defined as follows:tencentdb_ai.list_models(void);
update_model_attr function is defined as follows:tencentdb_ai.update_model_attr(model_name NAME,attr_name text,attr_value text);
version, region, json_path, SecretId, and SecretKey.delete_model function is 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 to invoke models, you can also use the following APIs for model invocation in specific scenarios.chat_completions function is defined 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-generated and does not represent the developer's position. Please do not delete or modify this marker.","Choices":[{"Index":0,"Message":{"Role":"assistant","Content":"Hello there! I'm very happy to chat with you. Is there anything you'd like to share with me today?"},"FinishReason":"stop"}],"Created":1739786393,"Id":"*******-****-****-****-*********","Usage":{"PromptTokens":3,"CompletionTokens":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', 'Knowledge Engine Large Model', ARRAY['Hunyuan Large Model', 'Tencent Knowledge Engine']);count-------2(1 row)
image_to_text function is defined 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"}]']);damoxing(> damoxing(>call_model------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------{"Response":{"RequestId":"*******-****-****-****-***********","Note":"The above content is AI-generated and does not represent the developer's position. Please do not delete or modify this marker.","Choices":[{"Index":0,"Message":{"Role":"assistant","Content":"Hello! I'm very happy to communicate with you. Is there anything I can help you with? Whether it's about life, work, or study,or any other questions, I will do my best to help you."},"FinishReason":"stop"}],"Created":1739793838,"Id":"*******-****-****-****-***********","Usage":{"PromptTokens":3,"CompletionTokens":33,"TotalTokens":36}}}(1 row)damoxing=>
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback