测试 Streaming

This commit is contained in:
Twilight 2024-05-24 09:49:05 +08:00
parent 9747ccdbba
commit 834928dbe9
3 changed files with 89 additions and 3 deletions

View File

@ -10,26 +10,42 @@ import { ref } from "vue";
import { useUserStore } from "@/store/user";
import {GrpcWebFetchTransport} from "@protobuf-ts/grpcweb-transport"
import {LibraryServiceClient} from "@/proto/library/library.client.ts"
import {DocumentServiceClient} from "@/proto/document/document.client.ts"
import * as libraryProto from "@/proto/library/library.ts";
import * as documentProto from "@/proto/document/document.ts";
let listLibrary: libraryProto.ListLibrariesRequest = {
page: 1
}
let empty: documentProto.Empty = {}
let transport = new GrpcWebFetchTransport({
baseUrl: "https://test.ivampiresp.com",
format: "text",
meta: {
"Authorization": "Bearer 1",
},
timeout: 100 * 1000,
});
let client = new LibraryServiceClient(transport)
let documentClient = new DocumentServiceClient(transport)
let s = documentClient.testStream(empty)
let out = client.listLibraries(listLibrary, {})
out.then((r) => console.log(r))
s.responses.onMessage(e => {
console.log(e)
})
s.then(res => {
console.log(res)
})
console.log(s)
// let out = client.listLibraries(listLibrary, {})
// out.then((r) => console.log(r))
const userStore = useUserStore();
const token = ref("");

View File

@ -4,6 +4,8 @@
import type { RpcTransport } from "@protobuf-ts/runtime-rpc";
import type { ServiceInfo } from "@protobuf-ts/runtime-rpc";
import { DocumentService } from "./document";
import type { TestStreamResponse } from "./document";
import type { ServerStreamingCall } from "@protobuf-ts/runtime-rpc";
import type { DocumentChunkList } from "./document";
import type { VectorSearchByTextInDocumentRequest } from "./document";
import type { Empty } from "./document";
@ -47,6 +49,10 @@ export interface IDocumentServiceClient {
* @generated from protobuf rpc: VectorSearchByTextInDocument(DocumentService.VectorSearchByTextInDocumentRequest) returns (DocumentService.DocumentChunkList);
*/
vectorSearchByTextInDocument(input: VectorSearchByTextInDocumentRequest, options?: RpcOptions): UnaryCall<VectorSearchByTextInDocumentRequest, DocumentChunkList>;
/**
* @generated from protobuf rpc: TestStream(DocumentService.Empty) returns (stream DocumentService.TestStreamResponse);
*/
testStream(input: Empty, options?: RpcOptions): ServerStreamingCall<Empty, TestStreamResponse>;
}
/**
* @generated from protobuf service DocumentService.DocumentService
@ -101,4 +107,11 @@ export class DocumentServiceClient implements IDocumentServiceClient, ServiceInf
const method = this.methods[5], opt = this._transport.mergeOptions(options);
return stackIntercept<VectorSearchByTextInDocumentRequest, DocumentChunkList>("unary", this._transport, method, opt, input);
}
/**
* @generated from protobuf rpc: TestStream(DocumentService.Empty) returns (stream DocumentService.TestStreamResponse);
*/
testStream(input: Empty, options?: RpcOptions): ServerStreamingCall<Empty, TestStreamResponse> {
const method = this.methods[6], opt = this._transport.mergeOptions(options);
return stackIntercept<Empty, TestStreamResponse>("serverStreaming", this._transport, method, opt, input);
}
}

View File

@ -221,6 +221,15 @@ export interface DocumentChunkList {
*/
libraryId: number;
}
/**
* @generated from protobuf message DocumentService.TestStreamResponse
*/
export interface TestStreamResponse {
/**
* @generated from protobuf field: string name = 1;
*/
name: string;
}
// @generated message type with reflection information, may provide speed optimized methods
class Empty$Type extends MessageType<Empty> {
constructor() {
@ -1033,6 +1042,53 @@ class DocumentChunkList$Type extends MessageType<DocumentChunkList> {
* @generated MessageType for protobuf message DocumentService.DocumentChunkList
*/
export const DocumentChunkList = new DocumentChunkList$Type();
// @generated message type with reflection information, may provide speed optimized methods
class TestStreamResponse$Type extends MessageType<TestStreamResponse> {
constructor() {
super("DocumentService.TestStreamResponse", [
{ no: 1, name: "name", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
]);
}
create(value?: PartialMessage<TestStreamResponse>): TestStreamResponse {
const message = globalThis.Object.create((this.messagePrototype!));
message.name = "";
if (value !== undefined)
reflectionMergePartial<TestStreamResponse>(this, message, value);
return message;
}
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: TestStreamResponse): TestStreamResponse {
let message = target ?? this.create(), end = reader.pos + length;
while (reader.pos < end) {
let [fieldNo, wireType] = reader.tag();
switch (fieldNo) {
case /* string name */ 1:
message.name = reader.string();
break;
default:
let u = options.readUnknownField;
if (u === "throw")
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
let d = reader.skip(wireType);
if (u !== false)
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
}
}
return message;
}
internalBinaryWrite(message: TestStreamResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
/* string name = 1; */
if (message.name !== "")
writer.tag(1, WireType.LengthDelimited).string(message.name);
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
return writer;
}
}
/**
* @generated MessageType for protobuf message DocumentService.TestStreamResponse
*/
export const TestStreamResponse = new TestStreamResponse$Type();
/**
* @generated ServiceType for protobuf service DocumentService.DocumentService
*/
@ -1042,5 +1098,6 @@ export const DocumentService = new ServiceType("DocumentService.DocumentService"
{ name: "GetDocument", options: {}, I: GetDocumentRequest, O: Document },
{ name: "UpdateDocument", options: {}, I: UpdateDocumentRequest, O: Document },
{ name: "DeleteDocument", options: {}, I: DeleteDocumentRequest, O: Empty },
{ name: "VectorSearchByTextInDocument", options: {}, I: VectorSearchByTextInDocumentRequest, O: DocumentChunkList }
{ name: "VectorSearchByTextInDocument", options: {}, I: VectorSearchByTextInDocumentRequest, O: DocumentChunkList },
{ name: "TestStream", serverStreaming: true, options: {}, I: Empty, O: TestStreamResponse }
]);