我正在使用 com.google.cloud.dialogflow.v2beta1.Document 通过Java RPC创建文档,当我尝试时,我们有setContent()方法,该方法用于创建具有原始内容的文档创建文档时,我遇到了异常。
原因:com.google.api.gax.rpc.InvalidArgumentException:操作 有名字 “项目/ agent-fa5be / operations / ks-add_document-NDQ0NDQ3MjI5MDA3NTIxMzgyNA” 失败,状态为= GrpcStatusCode {transportCode = INVALID_ARGUMENT} 和message = CSV文档必须正好有两列。的 提供的文档有1列。
当我检查dialogflow.v2beta1文档时,明显提到的内容已弃用,请使用raw_content而不是content。但是com.google.cloud.dialogflow.v2beta1.Document中没有支持raw_content的方法
答案 0 :(得分:0)
我正在尝试类似的问题。我尝试了不同的库和技术,直到找到了可行的方法。就我而言,我必须按如下方式解析每一行:
let input = ['Question1', 'Answer1\n'];
let input2 = ['Question2', 'Answer2\n'];
let base64data = input.toString('base64') + input2.toString('base64');
const request = {
parent: 'projects/PROJECT_ID/knowledgeBases/KNOWLEDGEBASE_ID',
document: {
knowledgeTypes: ['FAQ'],
displayName: 'Echele',
content: base64data,
source: 'rawContent',
mimeType: 'text/csv',
},
};
这使我可以提交文档,希望它也对您有用! 问候
答案 1 :(得分:-1)
请找到可行的解决方案
String documentName="test.csv";
try {
byte[] bytedata = filedata.toString().getBytes();
ByteString bytestring = ByteString.copyFrom(bytedata);
byte[] bytedata1 = "text/csv".getBytes();
ByteString mimestring = ByteString.copyFrom(bytedata1);
DocumentsSettings docuemtnSettings = DocumentsSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credentials)).build();
DocumentsClient documentsClient = DocumentsClient.create(docuemtnSettings);
Document document = Document.newBuilder().setDisplayName(documentName).setContentBytes(bytestring)
.setMimeTypeBytes(mimestring).addKnowledgeTypes(KnowledgeType.FAQ).build();
CreateDocumentRequest createDocumentRequest = CreateDocumentRequest.newBuilder().setDocument(document)
.setParent(knowledgeBaseName).build();
OperationFuture<Document, KnowledgeOperationMetadata> response = documentsClient
.createDocumentAsync(createDocumentRequest);
Document createdDocument = response.get();
System.out.format(" - docuemnt created ID: %s\n", createdDocument.getName());