StarRocks版本
StarRocks3.4
配置步骤
配置be参数
在be.conf增加以下参数
#python
python_envs = /bdp/anaconda3/envs/py_starrocks/
安装minianaconda,创建python3.11虚拟环境
conda create -n py_starrocks python=3.11 -y
conda activate py_starrocks
conda install openai pyarrow
一定要安装pyarrow,避免系统报错。
创建Python函数
CREATE FUNCTION get_deepseek(STRING)
RETURNS STRING
type = 'Python'
symbol = 'get_deepseek'
file = 'inline'
AS
$$
from openai import OpenAI
def get_deepseek(prompt):
client = OpenAI(api_key="sk", base_url="https://api.deepseek.com")
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": prompt},
],
stream=False
)
return response.choices[0].message.content
$$
;
测试结果
查询单条
select "杭州半云科技" 公司,get_deepseek("杭州半云科技") 公司简介
查询多条
select
get_deepseek(公司) Answer
from
(
select
'杭州半云科技福建分公司' as 公司
union all
select
'杭州半云科技北京分公司' as 公司
)t