feat: 增强 KnowledgeQAStream Client参数
This commit is contained in:
+5
-1
@@ -105,7 +105,11 @@ if err != nil {
|
||||
}
|
||||
|
||||
// 流式问答
|
||||
err = apiClient.KnowledgeQAStream(context.Background(), session.ID, "什么是机器学习?", func(response *client.StreamResponse) error {
|
||||
err = apiClient.KnowledgeQAStream(context.Background(), session.ID, &client.KnowledgeQARequest{
|
||||
Query: "什么是机器学习?",
|
||||
KnowledgeBaseIDs: []string{knowledgeBaseID}, // 可选:指定知识库
|
||||
WebSearchEnabled: false, // 可选:是否启用网络搜索
|
||||
}, func(response *client.StreamResponse) error {
|
||||
// 处理每个响应片段
|
||||
fmt.Print(response.Content)
|
||||
return nil
|
||||
|
||||
+2
-2
@@ -150,7 +150,7 @@ func ExampleUsage() {
|
||||
|
||||
err = apiClient.KnowledgeQAStream(context.Background(),
|
||||
session.ID,
|
||||
question,
|
||||
&KnowledgeQARequest{Query: question},
|
||||
func(response *StreamResponse) error {
|
||||
if response.ResponseType == ResponseTypeAnswer {
|
||||
answer.WriteString(response.Content)
|
||||
@@ -181,7 +181,7 @@ func ExampleUsage() {
|
||||
|
||||
err = apiClient.KnowledgeQAStream(context.Background(),
|
||||
session.ID,
|
||||
streamQuestion,
|
||||
&KnowledgeQARequest{Query: streamQuestion},
|
||||
func(response *StreamResponse) error {
|
||||
fmt.Print(response.Content)
|
||||
return nil
|
||||
|
||||
+9
-7
@@ -227,7 +227,13 @@ func (c *Client) GenerateTitle(ctx context.Context, sessionID string, request *G
|
||||
|
||||
// KnowledgeQARequest knowledge Q&A request
|
||||
type KnowledgeQARequest struct {
|
||||
Query string `json:"query"`
|
||||
Query string `json:"query"` // Query text for knowledge base search
|
||||
KnowledgeBaseIDs []string `json:"knowledge_base_ids"` // Selected knowledge base IDs for this request
|
||||
KnowledgeIDs []string `json:"knowledge_ids"` // Selected knowledge IDs for this request
|
||||
AgentEnabled bool `json:"agent_enabled"` // Whether agent mode is enabled for this request
|
||||
AgentID string `json:"agent_id"` // Selected custom agent ID for this request
|
||||
WebSearchEnabled bool `json:"web_search_enabled"` // Whether web search is enabled for this request
|
||||
SummaryModelID string `json:"summary_model_id"` // Optional summary model ID (overrides session default)
|
||||
}
|
||||
|
||||
type ResponseType string
|
||||
@@ -250,15 +256,11 @@ type StreamResponse struct {
|
||||
func (c *Client) KnowledgeQAStream(
|
||||
ctx context.Context,
|
||||
sessionID string,
|
||||
query string,
|
||||
request *KnowledgeQARequest,
|
||||
callback func(*StreamResponse) error,
|
||||
) error {
|
||||
path := fmt.Sprintf("/api/v1/knowledge-chat/%s", sessionID)
|
||||
fmt.Printf("Starting KnowledgeQAStream request, session ID: %s, query: %s\n", sessionID, query)
|
||||
|
||||
request := &KnowledgeQARequest{
|
||||
Query: query,
|
||||
}
|
||||
fmt.Printf("Starting KnowledgeQAStream request, session ID: %s, query: %s\n", sessionID, request.Query)
|
||||
|
||||
resp, err := c.doRequest(ctx, http.MethodPost, path, request, nil)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user