Skip to content
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

Modify the calling method of openai, and use function calling to reduce the size of the first input token. #1145

Open
wants to merge 18 commits into
base: main
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ package-lock.json
/chat2db-server/ali-dbhub-server-domain/ali-dbhub-server-domain-support/src/main/resources/lib/*
/chat2db-server/ali-dbhub-server-domain/ali-dbhub-server-domain-support/lib/*
/lib
/out/*
/out/*
/chat2db-gateway/target
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,17 @@ const ChatInput = (props: IProps) => {
};

const renderSelectTable = () => {
const { tables, onSelectTableSyncModel, selectedTables, onSelectTables } = props;
const { tables, onSelectTableSyncModel, selectedTables, onSelectTables,syncTableModel } = props;
const options = (tables || []).map((t) => ({ value: t, label: t }));
return (
<div className={styles.aiSelectedTable}>
<Radio.Group
onChange={(v) => onSelectTableSyncModel(v.target.value)}
// value={syncTableModel}
value={SyncModelType.MANUAL}
value={syncTableModel}
style={{ marginBottom: '8px' }}
>
<Space direction="horizontal">
{/* <Radio value={SyncModelType.AUTO}>自动</Radio> */}
<Radio value={SyncModelType.AUTO}>自动</Radio>
<Radio value={SyncModelType.MANUAL}>手动</Radio>
</Space>
</Radio.Group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const SelectBoundInfo = memo((props: IProps) => {
boundInfo.databaseName,
boundInfo.schemaName,
);
setSelectedTables(tableNameListTemp.slice(0, 1));
//setSelectedTables(tableNameListTemp.slice(0, 1));
}
}, [allTableList, isActive]);

Expand Down
84 changes: 84 additions & 0 deletions chat2db-gateway/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.hejianjun</groupId>
<artifactId>chat2db-gateway</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>chat2db-gateway</name>
<description>Project for chat2db-gateway</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<java.version>11</java.version>
<elasticsearch.version>8.12.2</elasticsearch.version>
<jakarta-json.version>2.0.1</jakarta-json.version>
</properties>

<dependencies>
<!-- Spring Boot starter web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Elasticsearch Java API Client -->
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.12.2</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>${jakarta-json.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.3</version>
</dependency>




<!-- Spring Boot starter test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
18 changes: 18 additions & 0 deletions chat2db-gateway/src/main/java/com/hejianjun/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.hejianjun;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@Slf4j
@SpringBootApplication
public class Application {
/**
* 主程序入口
* @param args 命令行参数
*/
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.hejianjun.bean;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
@AllArgsConstructor
public class SchemaDocument {
private String schema;
private List<BigDecimal> vector;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.hejianjun.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
* 表结构请求
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class TableSchemaRequest {

// 数据源ID
@NotNull
private Long dataSourceId;
// 数据库名称
@NotNull
private String databaseName;
// API密钥
private String apiKey;
// 数据源模式
private String dataSourceSchema;
// 模式向量
@NotNull
private List<List<BigDecimal>> schemaVector;
// 模式列表
@NotNull
private List<String> schemaList;
// 插入前删除
private Boolean deleteBeforeInsert = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.hejianjun.config;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.message.BasicHeader;
import org.elasticsearch.client.RestClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ElasticsearchClientConfig {

String apiKey = "0E9NGIy7gb8a3TDVM8dC";

/**
* 创建ElasticsearchClient实例
*
* @return ElasticsearchClient实例
*/
@Bean
public ElasticsearchClient elasticsearchClient() {
// 初始化低级客户端
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200))
.setDefaultHeaders(new Header[]{
new BasicHeader("Authorization", "ApiKey " + apiKey)
})
.build();

// 使用低级客户端创建传输层
ElasticsearchTransport transport = new RestClientTransport(
restClient, new JacksonJsonpMapper());

// 创建ElasticsearchClient实例
return new ElasticsearchClient(transport);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.hejianjun.controller;

import com.hejianjun.bean.TableSchemaRequest;
import com.hejianjun.service.TableSchemaService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/api/client/milvus")
public class TableSchemaController {

private final TableSchemaService service;


/**
* 保存表结构
* @param request 表结构请求对象
* @return 保存成功的文档ID
*/
@PostMapping("/schema/save")
public ResponseEntity<List<String>> saveSchema(@RequestBody TableSchemaRequest request) {
try {
List<String> documentId = service.saveSchemaBatch(request);
return ResponseEntity.ok(documentId);
} catch (IOException e) {
log.error("保存表结构时发生错误", e);
return ResponseEntity.internalServerError().build();
}
}

/**
* 通过向量搜索表结构
* @param request 表结构搜索请求
* @return 搜索结果列表
*/
@PostMapping("/schema/search")
public ResponseEntity<TableSchemaRequest> searchByVector(@RequestBody TableSchemaRequest request) {
try {
TableSchemaRequest tableSchemaRequest = service.searchByVector(request);
return ResponseEntity.ok(tableSchemaRequest);
} catch (IOException e) {
log.error("Error searching schema", e);
return ResponseEntity.internalServerError().build();
}
}
}
Loading