Skip to content

[Enhancement](llm) Support some LLM functions #2486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
{
"title": "LLM_CLASSIFY",
"language": "en"
}
---

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## Description

Used to classify text into a specified set of labels.

## Syntax

```sql
LLM_CLASSIFY([<resource_name>], <text>, <labels>)
```

## Parameters

| Parameter | Description |
| ----------------- | ------------------------------------------- |
| `<resource_name>` | The specified resource name, optional |
| `<text>` | The text to be classified |
| `<labels>` | Array of classification labels |

## Return Value

Returns the single label that best matches the text.

If any input is NULL, returns NULL.

The result is generated by a large language model, so the output may vary.

## Examples

```sql
SET default_llm_classify_resource = 'resource_name';
SELECT LLM_CLASSIFY('Apache Doris is a databases system.', ['useage', 'introduce']) AS Result;
```
```text
+-----------+
| Result |
+-----------+
| introduce |
+-----------+
```

```sql
SELECT LLM_CLASSIFY('resource_name', 'Apache Doris is developing rapidly.', ['science', 'sport']) AS Result;
```
```text
+---------+
| Result |
+---------+
| science |
+---------+
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
{
"title": "LLM_EXTRACT",
"language": "en"
}
---

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## Description

Used to extract information corresponding to specific labels from text.

## Syntax

```sql
LLM_EXTRACT([<resource_name>], <text>, <labels>)
```

## Parameters

| Parameter | Description |
| ----------------- | -------------------------------------------- |
| `<resource_name>` | The specified resource name, optional |
| `<text>` | The text from which to extract information |
| `<labels>` | Array of labels to extract |

## Return Value

Returns a string containing all extracted labels and their corresponding values.

If any input is NULL, returns NULL.

The result is generated by a large language model, so the output may vary.

## Examples

```sql
SET default_llm_extract_resource = 'resource_name';
SELECT LLM_EXTRACT('Apache Doris is an MPP-based real-time data warehouse known for its high query speed.',
['product_name', 'architecture', 'key_feature']) AS Result;
```
```text
+---------------------------------------------------------------------------------------+
| Result |
+---------------------------------------------------------------------------------------+
| product_name="Apache Doris", architecture="MPP-based", key_feature="high query speed" |
+---------------------------------------------------------------------------------------+
```

```sql
SELECT LLM_EXTRACT('resource_name', 'Apache Doris began in 2008 as an internal project named Palo.',
['original name', 'founding time']) AS Result;
```
```text
+----------------------------------------+
| Result |
+----------------------------------------+
| original name=Palo, founding time=2008 |
+----------------------------------------+
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
{
"title": "LLM_FIXGRAMMAR",
"language": "en"
}
---

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## Description

Used to correct grammatical errors in text.

## Syntax

```sql
LLM_FIXGRAMMAR([<resource_name>], <text>)
```

## Parameters

| Parameter | Description |
| ----------------- | ------------------------------------------- |
| `<resource_name>` | The specified resource name, optional |
| `<text>` | The text to be grammar-corrected |

## Return Value

Returns the text string after grammar correction.

If any input is NULL, returns NULL.

The result is generated by a large language model, so the output may vary.

## Examples

```sql
SET default_llm_fixgrammar_resource = 'resource_name';
SELECT LLM_FIXGRAMMAR('Apache Doris a great system DB') AS Result;
```
```text
+------------------------------------------+
| Result |
+------------------------------------------+
| Apache Doris is a great database system. |
+------------------------------------------+
```

```sql
SELECT LLM_FIXGRAMMAR('resource_name', 'I am like to using Doris') AS Result;
```
```text
+--------------------+
| Result |
+--------------------+
| I like using Doris |
+--------------------+
```
Loading