-
Notifications
You must be signed in to change notification settings - Fork 14
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
Assistant, Files, Foundation Models, Operation sdk and update for mono generated #178
Changes from 6 commits
c0b16ac
93cd9d8
92c2b53
56ddf8c
263d666
ab8097f
6b0b997
4ac7875
28ca8af
4740eba
3137c86
aed6fe3
f982538
48e0018
ab76484
8b2dade
6b7cc8b
3e59086
60af6d7
af3ae16
91f943b
35e877e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ export * as thread from './generated/yandex/cloud/ai/assistants/v1/threads/threa | |
export * as threadService from './generated/yandex/cloud/ai/assistants/v1/threads/thread_service'; | ||
export * as user from './generated/yandex/cloud/ai/assistants/v1/users/user'; | ||
export * as userService from './generated/yandex/cloud/ai/assistants/v1/users/user_service'; | ||
|
||
export * as SDK from './sdk'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Че т я не очень понял, а откуда оно взялось? Я в proto не вижу каких-либо модулей There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ты про то, что оно появилось в // generated file ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { Client } from 'nice-grpc'; | ||
import { assistantService } from '..'; | ||
import { Assistant } from '../generated/yandex/cloud/ai/assistants/v1/assistant'; | ||
import { | ||
AssistantServiceService, | ||
CreateAssistantRequest, | ||
DeleteAssistantRequest, | ||
GetAssistantRequest, | ||
ListAssistantsRequest, | ||
ListAssistantVersionsRequest, | ||
UpdateAssistantRequest, | ||
} from '../generated/yandex/cloud/ai/assistants/v1/assistant_service'; | ||
import { ClientCallArgs, SessionArg, TypeFromProtoc } from './types'; | ||
|
||
export type CreateAssistantProps = Omit< | ||
TypeFromProtoc<CreateAssistantRequest, 'folderId'>, | ||
'modelUri' | ||
> & { | ||
modelId: string; | ||
}; | ||
|
||
export type GetAssistantProps = TypeFromProtoc<GetAssistantRequest, 'assistantId'>; | ||
|
||
export type ListAssistantProps = TypeFromProtoc<ListAssistantsRequest, 'folderId'>; | ||
|
||
export type DeleteAssistantProps = TypeFromProtoc<DeleteAssistantRequest, 'assistantId'>; | ||
|
||
export type ListAssistantVersionsProps = TypeFromProtoc< | ||
ListAssistantVersionsRequest, | ||
'assistantId' | ||
>; | ||
|
||
export type UpdateAssistantProps = TypeFromProtoc<UpdateAssistantRequest, 'assistantId'>; | ||
|
||
export class AssistantWithSdk { | ||
private assistantSdk: AssistantSdk; | ||
private assistant: Assistant; | ||
|
||
constructor(assistantSdk: AssistantSdk, assistant: Assistant) { | ||
this.assistantSdk = assistantSdk; | ||
this.assistant = assistant; | ||
} | ||
|
||
get data() { | ||
return this.assistant; | ||
} | ||
|
||
private updateData(assistant: Assistant) { | ||
this.assistant = assistant; | ||
return this; | ||
} | ||
|
||
delete(params: Omit<DeleteAssistantProps, 'assistantId'>, args?: ClientCallArgs) { | ||
const p = this.assistantSdk.delete({ ...params, assistantId: this.assistant.id }, args); | ||
return p; | ||
} | ||
|
||
update(params: Omit<UpdateAssistantProps, 'assistantId'>, args?: ClientCallArgs) { | ||
const p = this.assistantSdk.update({ ...params, assistantId: this.assistant.id }, args); | ||
return p.then(this.updateData.bind(this)); | ||
} | ||
} | ||
|
||
export class AssistantSdk { | ||
private assistantClient: Client<typeof AssistantServiceService, ClientCallArgs>; | ||
|
||
constructor(session: SessionArg) { | ||
this.assistantClient = session.client(assistantService.AssistantServiceClient); | ||
} | ||
|
||
private static _withSdk(this: AssistantSdk, assistantP: Promise<Assistant>) { | ||
async function withSdk(this: AssistantSdk) { | ||
const assistant = await assistantP; | ||
return new AssistantWithSdk(this, assistant); | ||
} | ||
|
||
return Object.assign(assistantP, { withSdk: withSdk.bind(this) }); | ||
} | ||
|
||
create(params: CreateAssistantProps, args?: ClientCallArgs) { | ||
const { modelId, ...restParams } = params; | ||
|
||
const p = this.assistantClient.create( | ||
assistantService.CreateAssistantRequest.fromPartial({ | ||
...restParams, | ||
modelUri: `gpt://${params.folderId}/${modelId}`, | ||
}), | ||
args, | ||
); | ||
|
||
return AssistantSdk._withSdk.call(this, p); | ||
} | ||
|
||
get(params: GetAssistantProps, args?: ClientCallArgs) { | ||
const p = this.assistantClient.get( | ||
assistantService.GetAssistantRequest.fromPartial(params), | ||
args, | ||
); | ||
return AssistantSdk._withSdk.call(this, p); | ||
} | ||
|
||
list(params: ListAssistantProps, args?: ClientCallArgs) { | ||
const p = this.assistantClient.list( | ||
assistantService.ListAssistantsRequest.fromPartial(params), | ||
args, | ||
); | ||
|
||
return p; | ||
} | ||
|
||
delete(params: DeleteAssistantProps, args?: ClientCallArgs) { | ||
const p = this.assistantClient.delete( | ||
assistantService.DeleteAssistantRequest.fromPartial(params), | ||
args, | ||
); | ||
return p; | ||
} | ||
|
||
listVersions(params: ListAssistantVersionsProps, args?: ClientCallArgs) { | ||
const p = this.assistantClient.listVersions( | ||
assistantService.ListAssistantVersionsRequest.fromPartial(params), | ||
args, | ||
); | ||
return p; | ||
} | ||
|
||
update(params: UpdateAssistantProps, args?: ClientCallArgs) { | ||
const p = this.assistantClient.update( | ||
assistantService.UpdateAssistantRequest.fromPartial(params), | ||
args, | ||
); | ||
|
||
return AssistantSdk._withSdk.call(this, p); | ||
} | ||
} | ||
|
||
export const initAssistantSdk = (session: SessionArg) => { | ||
return new AssistantSdk(session); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './assistantSdk'; | ||
export * from './messageSdk'; | ||
export * from './runSdk'; | ||
export * from './threadSdk'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { messageService } from '..'; | ||
import { MessageContent } from '../generated/yandex/cloud/ai/assistants/v1/threads/message'; | ||
import { | ||
CreateMessageRequest, | ||
GetMessageRequest, | ||
ListMessagesRequest, | ||
MessageServiceService, | ||
} from '../generated/yandex/cloud/ai/assistants/v1/threads/message_service'; | ||
import { ClientCallArgs, SessionArg, TypeFromProtoc } from './types'; | ||
import { Client } from 'nice-grpc'; | ||
|
||
export type SendMessageProps = TypeFromProtoc<CreateMessageRequest, 'threadId'>; | ||
|
||
export type GetMessageProps = TypeFromProtoc<GetMessageRequest, 'threadId' | 'messageId'>; | ||
|
||
export type ListMessagesProps = TypeFromProtoc<ListMessagesRequest, 'threadId'>; | ||
|
||
export class MessageSdk { | ||
private messageClient: Client<typeof MessageServiceService, ClientCallArgs>; | ||
|
||
constructor(session: SessionArg) { | ||
this.messageClient = session.client(messageService.MessageServiceClient); | ||
} | ||
|
||
public static getMessageContent(...args: string[]): TypeFromProtoc<MessageContent> { | ||
return { content: args.map((content) => ({ text: { content } })) }; | ||
} | ||
|
||
public static messageContentToString(messageContent?: MessageContent): string { | ||
return ( | ||
messageContent?.content.reduce((res, { text }) => { | ||
if (text?.content) { | ||
res += text.content; | ||
} | ||
|
||
return res; | ||
}, '') ?? '' | ||
); | ||
} | ||
|
||
public send(params: SendMessageProps, args?: ClientCallArgs) { | ||
const p = this.messageClient.create( | ||
messageService.CreateMessageRequest.fromPartial(params), | ||
args, | ||
); | ||
|
||
return p; | ||
} | ||
|
||
get(params: GetMessageProps, args?: ClientCallArgs) { | ||
const p = this.messageClient.get( | ||
messageService.GetMessageRequest.fromPartial(params), | ||
args, | ||
); | ||
|
||
return p; | ||
} | ||
|
||
list(params: ListMessagesProps, args?: ClientCallArgs) { | ||
const p = this.messageClient.list( | ||
messageService.ListMessagesRequest.fromPartial(params), | ||
args, | ||
); | ||
|
||
return p; | ||
} | ||
} | ||
|
||
export const initMessageSdk = (session: SessionArg) => { | ||
return new MessageSdk(session); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { ClientCallArgs, SessionArg, TypeFromProtoc } from './types'; | ||
|
||
import { | ||
CreateRunRequest, | ||
GetLastRunByThreadRequest, | ||
GetRunRequest, | ||
ListenRunRequest, | ||
ListRunsRequest, | ||
RunServiceService, | ||
} from '../generated/yandex/cloud/ai/assistants/v1/runs/run_service'; | ||
import { Run } from '../generated/yandex/cloud/ai/assistants/v1/runs/run'; | ||
import { CallOptions } from '@grpc/grpc-js'; | ||
import { runService } from '..'; | ||
import { Client } from 'nice-grpc'; | ||
|
||
export type GetRunProps = TypeFromProtoc<GetRunRequest, 'runId'>; | ||
|
||
export type CreateRunProps = TypeFromProtoc<CreateRunRequest, 'threadId' | 'assistantId'>; | ||
|
||
export type GetLastRunByThreadProps = TypeFromProtoc<GetLastRunByThreadRequest, 'threadId'>; | ||
|
||
export type ListRunsProps = TypeFromProtoc<ListRunsRequest, 'folderId'>; | ||
|
||
export type ListenRunProps = TypeFromProtoc<ListenRunRequest, 'runId'>; | ||
|
||
type RunClientType = Client<typeof RunServiceService, ClientCallArgs>; | ||
|
||
export class RunWithSdk { | ||
private runSdk: RunSdk; | ||
private run: Run; | ||
|
||
constructor(runSdk: RunSdk, run: Run) { | ||
this.runSdk = runSdk; | ||
this.run = run; | ||
} | ||
|
||
get data() { | ||
return this.run; | ||
} | ||
|
||
listen(params: Omit<ListenRunProps, 'runId'>, args?: ClientCallArgs & CallOptions) { | ||
return this.runSdk.listen({ ...params, runId: this.run.id }, args); | ||
} | ||
} | ||
|
||
export class RunSdk { | ||
private runClient: RunClientType; | ||
|
||
constructor(session: SessionArg) { | ||
this.runClient = session.client(runService.RunServiceClient); | ||
} | ||
|
||
private static _withSdk(this: RunSdk, runP: Promise<Run>) { | ||
async function withSdk(this: RunSdk) { | ||
const run = await runP; | ||
return new RunWithSdk(this, run); | ||
} | ||
|
||
return Object.assign(runP, { withSdk: withSdk.bind(this) }); | ||
} | ||
|
||
create(params: CreateRunProps, args?: ClientCallArgs) { | ||
const p = this.runClient.create(runService.CreateRunRequest.fromPartial(params), args); | ||
return RunSdk._withSdk.call(this, p); | ||
} | ||
|
||
get(params: GetRunProps, args?: ClientCallArgs) { | ||
const p = this.runClient.get(runService.GetRunRequest.fromPartial(params), args); | ||
return RunSdk._withSdk.call(this, p); | ||
} | ||
|
||
getLastByThread(params: GetLastRunByThreadProps, args?: ClientCallArgs) { | ||
const p = this.runClient.getLastByThread( | ||
runService.GetLastRunByThreadRequest.fromPartial(params), | ||
args, | ||
); | ||
return RunSdk._withSdk.call(this, p); | ||
} | ||
|
||
list(params: ListRunsProps, args?: ClientCallArgs) { | ||
const p = this.runClient.list(runService.ListRunsRequest.fromPartial(params), args); | ||
return p; | ||
} | ||
|
||
listen(params: ListenRunProps, args?: ClientCallArgs & CallOptions) { | ||
return this.runClient.listen(runService.ListenRunRequest.fromPartial(params), args); | ||
} | ||
} | ||
|
||
export const initRunSdk = (session: SessionArg) => { | ||
return new RunSdk(session); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это правило prettier'ом хэндлится?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6b0b997
не знаю что это за правило, случайно удалил