mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-19 14:11:04 +08:00
Go: add ingestion server (#15094)
### What problem does this PR solve? 1. Go ingestion server will connected with admin server with gRPC stream 2. Go ingestion server will be responsible for ingestion tasks ``` RAGFlow(admin)> list ingestors; +-----------------+-----------+----------------------------------+---------------------------+----------+------------+--------------+--------+------------+---------------+ | address | cpu_usage | id | last_heartbeat | name | process_id | rss_usage | status | task_count | vms_usage | +-----------------+-----------+----------------------------------+---------------------------+----------+------------+--------------+--------+------------+---------------+ | 127.0.0.1:58564 | 0 | bdd1870eea2646e0aacb8a2cd3307aa2 | 2026-05-24T18:16:17+08:00 | ingestor | 680152 | 212.72265625 | active | 0 | 2589.12109375 | +-----------------+-----------+----------------------------------+---------------------------+----------+------------+--------------+--------+------------+---------------+ RAGFlow(admin)> start ingestion 'abc'; +----------------------------------+ | task_id | +----------------------------------+ | e714777639ca4760ab427b5f211e81ad | +----------------------------------+ RAGFlow(admin)> stop ingestion 'f7bd39d0a724457eb5fdce6d81699776'; +----------------------------------+ | task_id | +----------------------------------+ | f7bd39d0a724457eb5fdce6d81699776 | +----------------------------------+ RAGFlow(admin)> list tasks; +-----+----------------------------------+-------+------+----------------------------------+---------------------------+------------+------------+ | ETA | assign_to | error | from | id | last_update | start_time | status | +-----+----------------------------------+-------+------+----------------------------------+---------------------------+------------+------------+ | 0 | 17937da188b84f23a5c10bb87588944b | | CLI | eae6431da72a40e796cff3a03008091b | 2026-05-24T19:46:03+08:00 | | COMPLETED | | 0 | 17937da188b84f23a5c10bb87588944b | | CLI | 6cccdd174bd049ecb05a774bbb47593f | 2026-05-24T19:46:03+08:00 | | COMPLETED | | 0 | 17937da188b84f23a5c10bb87588944b | | CLI | ef360d777e57485799adb96b30f2b4b8 | 2026-05-24T19:46:03+08:00 | | CANCELED | | 0 | 17937da188b84f23a5c10bb87588944b | | CLI | bcc5c5448cb64de48b6b6171c36fb790 | 2026-05-24T19:46:03+08:00 | | CANCELED | | 0 | 17937da188b84f23a5c10bb87588944b | | CLI | bfc25384c43a443294fe2da979a38ac2 | 2026-05-24T19:46:03+08:00 | | DISPATCHED | | 0 | 17937da188b84f23a5c10bb87588944b | | CLI | 84960537b85d413b8990a9efd5952d67 | 2026-05-24T19:46:04+08:00 | | DISPATCHED | | 0 | 17937da188b84f23a5c10bb87588944b | | CLI | 3d223c1b51e24b36861a3bfb2f1d58d4 | 2026-05-24T19:46:03+08:00 | | CANCELED | | 0 | 17937da188b84f23a5c10bb87588944b | | CLI | e433b0e356b846c89c301621a3c54494 | 2026-05-24T19:46:03+08:00 | | COMPLETED | | 0 | 17937da188b84f23a5c10bb87588944b | | CLI | 7c93a3880f074ebd8eca14e6b51bb7ef | 2026-05-24T19:46:03+08:00 | | COMPLETED | | 0 | 17937da188b84f23a5c10bb87588944b | | CLI | df2e4ef51aaf4390bff9a23f2692486e | 2026-05-24T19:46:04+08:00 | | DISPATCHED | | 0 | 17937da188b84f23a5c10bb87588944b | | CLI | 7377c53010194ef7a83aa206698d66ff | 2026-05-24T19:46:05+08:00 | | DISPATCHED | | 0 | 17937da188b84f23a5c10bb87588944b | | CLI | df64d1a1f9d348e3a2f174c4d7d69e73 | 2026-05-24T19:46:05+08:00 | | DISPATCHED | | 0 | 17937da188b84f23a5c10bb87588944b | | CLI | b59834512e2847e1bdf13ace04b8a456 | 2026-05-24T19:46:06+08:00 | | DISPATCHED | | 0 | 17937da188b84f23a5c10bb87588944b | | CLI | 0064bb0ab69344028d1ecfda053826f4 | 2026-05-24T19:46:03+08:00 | | QUEUED | +-----+----------------------------------+-------+------+----------------------------------+---------------------------+------------+------------+ ``` ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -1281,3 +1281,162 @@ func (c *RAGFlowClient) ListAdminTasks(cmd *Command) (ResponseIf, error) {
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *RAGFlowClient) ListAdminIngestors(cmd *Command) (ResponseIf, error) {
|
||||
if c.ServerType != "admin" {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
|
||||
}
|
||||
resp, err := c.HTTPClient.Request("GET", "/admin/ingestors", "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list ingestors: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list ingestors: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("list ingestors failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
func (c *RAGFlowClient) ListAdminIngestionTasks(cmd *Command) (ResponseIf, error) {
|
||||
if c.ServerType != "admin" {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
|
||||
}
|
||||
|
||||
resp, err := c.HTTPClient.Request("GET", "/admin/ingestion/tasks", "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list admin tasks: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list admin tasks: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("list admin tasks failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *RAGFlowClient) AdminStartIngestionCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.ServerType != "admin" {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
|
||||
}
|
||||
|
||||
fileURI, ok := cmd.Params["uri"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("uri not provided")
|
||||
}
|
||||
payload := map[string]interface{}{
|
||||
"uri": fileURI,
|
||||
"from": "CLI",
|
||||
}
|
||||
|
||||
resp, err := c.HTTPClient.Request("POST", "/admin/ingestion", "admin", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to ingest file: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to ingest file: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("ingest file failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *RAGFlowClient) AdminStopIngestionCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.ServerType != "admin" {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
|
||||
}
|
||||
|
||||
taskID, ok := cmd.Params["task_id"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("uri not provided")
|
||||
}
|
||||
payload := map[string]interface{}{
|
||||
"task_id": taskID,
|
||||
"from": "CLI",
|
||||
}
|
||||
|
||||
resp, err := c.HTTPClient.Request("DELETE", "/admin/ingestion", "admin", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to ingest file: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to ingest file: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("ingest file failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *RAGFlowClient) AdminShutdownIngestor(cmd *Command) (ResponseIf, error) {
|
||||
if c.ServerType != "admin" {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
|
||||
}
|
||||
|
||||
ingestorName, ok := cmd.Params["ingestor_name"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("ingestor_name not provided")
|
||||
}
|
||||
payload := map[string]interface{}{
|
||||
"ingestor_name": ingestorName,
|
||||
}
|
||||
|
||||
resp, err := c.HTTPClient.Request("DELETE", "/admin/ingestors", "admin", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to shutdown ingestor: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to shutdown ingestor: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("shutdown ingestor failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
@@ -192,6 +192,10 @@ func (p *Parser) parseAdminListCommand() (*Command, error) {
|
||||
return p.parseAdminListFiles()
|
||||
case TokenTasks:
|
||||
return p.parseAdminListTasks()
|
||||
case TokenIngestors:
|
||||
return p.parseAdminListIngestors()
|
||||
case TokenIngestion:
|
||||
return p.parseAdminListIngestionTasks()
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown LIST target: %s", p.curToken.Value)
|
||||
}
|
||||
@@ -376,6 +380,24 @@ func (p *Parser) parseAdminListTasks() (*Command, error) {
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminListIngestors() (*Command, error) {
|
||||
p.nextToken() // consume TASKS
|
||||
cmd := NewCommand("admin_list_ingestors")
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminListIngestionTasks() (*Command, error) {
|
||||
p.nextToken() // consume Ingestion
|
||||
|
||||
if p.curToken.Type != TokenTasks {
|
||||
return nil, fmt.Errorf("expected TASKS")
|
||||
}
|
||||
|
||||
cmd := NewCommand("list_admin_ingestion_tasks")
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminShowCommand() (*Command, error) {
|
||||
p.nextToken() // consume SHOW
|
||||
|
||||
@@ -1543,10 +1565,19 @@ func (p *Parser) parseAdminStartupCommand() (*Command, error) {
|
||||
|
||||
func (p *Parser) parseAdminShutdownCommand() (*Command, error) {
|
||||
p.nextToken() // consume SHUTDOWN
|
||||
if p.curToken.Type != TokenService {
|
||||
return nil, fmt.Errorf("expected SERVICE")
|
||||
|
||||
switch p.curToken.Type {
|
||||
case TokenService:
|
||||
return p.parseAdminShutdownServiceCommand()
|
||||
case TokenIngestor:
|
||||
return p.parseAdminShutdownIngestorCommand()
|
||||
default:
|
||||
return nil, fmt.Errorf("expected SERVICE or INGESTOR")
|
||||
}
|
||||
p.nextToken()
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminShutdownServiceCommand() (*Command, error) {
|
||||
p.nextToken() // consume SERVICE
|
||||
|
||||
serviceNum, err := p.parseNumber()
|
||||
if err != nil {
|
||||
@@ -1564,6 +1595,25 @@ func (p *Parser) parseAdminShutdownCommand() (*Command, error) {
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminShutdownIngestorCommand() (*Command, error) {
|
||||
p.nextToken() // consume INGESTOR
|
||||
|
||||
ingestorName, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmd := NewCommand("admin_shutdown_ingestor_command")
|
||||
cmd.Params["ingestor_name"] = ingestorName
|
||||
|
||||
p.nextToken()
|
||||
// Semicolon is optional for UNSET TOKEN
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminRestartCommand() (*Command, error) {
|
||||
p.nextToken() // consume RESTART
|
||||
if p.curToken.Type != TokenService {
|
||||
@@ -1587,6 +1637,73 @@ func (p *Parser) parseAdminRestartCommand() (*Command, error) {
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseStartIngestion() (*Command, error) {
|
||||
p.nextToken() // consume Start
|
||||
|
||||
if p.curToken.Type != TokenIngestion {
|
||||
return nil, fmt.Errorf("expect INGESTION")
|
||||
}
|
||||
p.nextToken() // consume Ingest
|
||||
|
||||
uri, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmd := NewCommand("admin_start_ingestion_command")
|
||||
cmd.Params["uri"] = uri
|
||||
p.nextToken()
|
||||
|
||||
// Semicolon is optional for UNSET TOKEN
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseStopIngestion() (*Command, error) {
|
||||
p.nextToken() // consume Stop
|
||||
|
||||
if p.curToken.Type != TokenIngestion {
|
||||
return nil, fmt.Errorf("expect INGESTION")
|
||||
}
|
||||
p.nextToken() // consume Ingest
|
||||
|
||||
taskID, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmd := NewCommand("admin_stop_ingestion_command")
|
||||
cmd.Params["task_id"] = taskID
|
||||
p.nextToken()
|
||||
|
||||
// Semicolon is optional for UNSET TOKEN
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminIngestCommand() (*Command, error) {
|
||||
p.nextToken() // consume Ingest
|
||||
|
||||
uri, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmd := NewCommand("admin_ingest_command")
|
||||
cmd.Params["uri"] = uri
|
||||
p.nextToken()
|
||||
|
||||
// Semicolon is optional for UNSET TOKEN
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminUnsetCommand() (*Command, error) {
|
||||
p.nextToken() // consume UNSET
|
||||
|
||||
|
||||
@@ -185,6 +185,16 @@ func (c *RAGFlowClient) ExecuteAdminCommand(cmd *Command) (ResponseIf, error) {
|
||||
return c.ShowModel(cmd)
|
||||
case "list_admin_tasks":
|
||||
return c.ListAdminTasks(cmd)
|
||||
case "admin_list_ingestors":
|
||||
return c.ListAdminIngestors(cmd)
|
||||
case "admin_start_ingestion_command":
|
||||
return c.AdminStartIngestionCommand(cmd)
|
||||
case "admin_stop_ingestion_command":
|
||||
return c.AdminStopIngestionCommand(cmd)
|
||||
case "admin_shutdown_ingestor_command":
|
||||
return c.AdminShutdownIngestor(cmd)
|
||||
case "list_admin_ingestion_tasks":
|
||||
return c.ListAdminIngestionTasks(cmd)
|
||||
// TODO: Implement other commands
|
||||
default:
|
||||
return nil, fmt.Errorf("command '%s' would be executed with API", cmd.Type)
|
||||
@@ -324,6 +334,8 @@ func (c *RAGFlowClient) ExecuteUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
return c.RemoveChunks(cmd)
|
||||
case "list_metadata":
|
||||
return c.ListMetadata(cmd)
|
||||
case "parse_documents_user_command":
|
||||
return c.ParseDocumentsUserCommand(cmd)
|
||||
// ContextEngine commands
|
||||
case "ce_ls":
|
||||
return c.CEList(cmd)
|
||||
|
||||
@@ -447,6 +447,16 @@ func (l *Lexer) lookupIdent(ident string) Token {
|
||||
return Token{Type: TokenTask, Value: ident}
|
||||
case "TASKS":
|
||||
return Token{Type: TokenTasks, Value: ident}
|
||||
case "START":
|
||||
return Token{Type: TokenStart, Value: ident}
|
||||
case "STOP":
|
||||
return Token{Type: TokenStop, Value: ident}
|
||||
case "INGESTOR":
|
||||
return Token{Type: TokenIngestor, Value: ident}
|
||||
case "INGESTORS":
|
||||
return Token{Type: TokenIngestors, Value: ident}
|
||||
case "INGESTION":
|
||||
return Token{Type: TokenIngestion, Value: ident}
|
||||
case "LOG":
|
||||
return Token{Type: TokenLog, Value: ident}
|
||||
case "LEVEL":
|
||||
|
||||
@@ -129,6 +129,10 @@ func (p *Parser) parseAdminCommand() (*Command, error) {
|
||||
return p.parseAdminShutdownCommand()
|
||||
case TokenRestart:
|
||||
return p.parseAdminRestartCommand()
|
||||
case TokenStart:
|
||||
return p.parseStartIngestion()
|
||||
case TokenStop:
|
||||
return p.parseStopIngestion()
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown command: %s", p.curToken.Value)
|
||||
}
|
||||
@@ -259,7 +263,7 @@ func (p *Parser) expectSemicolon() error {
|
||||
}
|
||||
|
||||
func isKeyword(tokenType int) bool {
|
||||
return tokenType >= TokenLogin && tokenType <= TokenTag
|
||||
return tokenType >= TokenLogin && tokenType <= TokenPanic
|
||||
}
|
||||
|
||||
// isCECommand checks if the given string is a Filesystem command
|
||||
|
||||
@@ -157,6 +157,11 @@ const (
|
||||
TokenURL
|
||||
TokenTask
|
||||
TokenTasks
|
||||
TokenIngestor
|
||||
TokenIngestors
|
||||
TokenStart
|
||||
TokenStop
|
||||
TokenIngestion
|
||||
TokenLog
|
||||
TokenLevel
|
||||
TokenDebug
|
||||
|
||||
@@ -3232,6 +3232,54 @@ func (c *RAGFlowClient) RemoveChunks(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *RAGFlowClient) ParseDocumentsUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.HTTPClient.APIToken == "" && c.HTTPClient.LoginToken == "" {
|
||||
return nil, fmt.Errorf("API token not set. Please login first")
|
||||
}
|
||||
|
||||
if c.ServerType != "user" {
|
||||
return nil, fmt.Errorf("this command is only allowed in USER mode")
|
||||
}
|
||||
|
||||
datasetID, ok := cmd.Params["dataset_id"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("dataset_id not provided")
|
||||
}
|
||||
|
||||
documents, ok := cmd.Params["documents"].([]string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("documents not provided")
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("/datasets/%s/documents/parse", datasetID)
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"documents": documents,
|
||||
}
|
||||
|
||||
// Normal mode
|
||||
resp, err := c.HTTPClient.Request("POST", url, "web", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list documents: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list documents: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result SimpleResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("list documents failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// formatRequestError Uniformly handle and format network errors in HTTP requests
|
||||
func formatRequestError(action string, err error) error {
|
||||
if err == nil {
|
||||
|
||||
@@ -3159,8 +3159,10 @@ func (p *Parser) parseParseCommand() (*Command, error) {
|
||||
return p.parseParseDataset()
|
||||
case TokenWith:
|
||||
return p.parseModelParseCommand()
|
||||
default:
|
||||
case TokenDocument:
|
||||
return p.parseParseDocs()
|
||||
default:
|
||||
return nil, fmt.Errorf("expected DATASET, WITH, or DOCUMENT")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3194,31 +3196,32 @@ func (p *Parser) parseParseDataset() (*Command, error) {
|
||||
}
|
||||
|
||||
func (p *Parser) parseParseDocs() (*Command, error) {
|
||||
documentNames, err := p.parseQuotedString()
|
||||
p.nextToken() // consume document
|
||||
|
||||
documentsStr, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p.nextToken()
|
||||
if p.curToken.Type != TokenOf {
|
||||
return nil, fmt.Errorf("expected OF")
|
||||
}
|
||||
p.nextToken()
|
||||
if p.curToken.Type != TokenDataset {
|
||||
return nil, fmt.Errorf("expected DATASET")
|
||||
if p.curToken.Type != TokenFrom {
|
||||
return nil, fmt.Errorf("expected FROM")
|
||||
}
|
||||
p.nextToken()
|
||||
|
||||
datasetName, err := p.parseQuotedString()
|
||||
datasetID, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmd := NewCommand("parse_dataset_docs")
|
||||
cmd.Params["document_names"] = documentNames
|
||||
cmd.Params["dataset_name"] = datasetName
|
||||
|
||||
p.nextToken()
|
||||
|
||||
cmd := NewCommand("parse_documents_user_command")
|
||||
|
||||
documents := strings.Split(documentsStr, " ")
|
||||
|
||||
cmd.Params["documents"] = documents
|
||||
cmd.Params["dataset_id"] = datasetID
|
||||
|
||||
// Semicolon is optional for UNSET TOKEN
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
|
||||
Reference in New Issue
Block a user