-
Notifications
You must be signed in to change notification settings - Fork 245
feat(ai-assistant): Assistant Eval improvements #7250
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,39 @@ | ||
| import { createOpenAI } from '@ai-sdk/openai'; | ||
| import { buildPrompts } from './prompts'; | ||
| import { | ||
| type ChatTransport, | ||
| convertToModelMessages, | ||
| type UIMessage, | ||
| type UIMessageChunk, | ||
| convertToModelMessages, | ||
| type LanguageModel, | ||
| type ModelMessage, | ||
| streamText, | ||
| } from 'ai'; | ||
| import { createOpenAI } from '@ai-sdk/openai'; | ||
|
|
||
| export class DocsProviderTransport implements ChatTransport<UIMessage> { | ||
| private openai: ReturnType<typeof createOpenAI>; | ||
| private createResponse: ReturnType<typeof makeCreateResponse>; | ||
|
|
||
| constructor({ baseUrl }: { baseUrl: string }) { | ||
| this.openai = createOpenAI({ | ||
| const openai = createOpenAI({ | ||
| baseURL: baseUrl, | ||
| apiKey: '', | ||
| }); | ||
| this.createResponse = makeCreateResponse({ | ||
| languageModel: openai.responses('mongodb-chat-latest'), | ||
| }); | ||
| } | ||
|
|
||
| sendMessages({ | ||
| messages, | ||
| // TODO: pass the metadata correctly in a strongly typed manner. | ||
| // I'm not sure how to do this. | ||
| metadata, | ||
| abortSignal, | ||
| }: Parameters<ChatTransport<UIMessage>['sendMessages']>[0]) { | ||
| const result = streamText({ | ||
| model: this.openai.responses('mongodb-chat-latest'), | ||
| const result = this.createResponse({ | ||
| messages: convertToModelMessages(messages), | ||
| abortSignal: abortSignal, | ||
| abortSignal, | ||
| systemPromptType: metadata?.type as keyof typeof buildPrompts, | ||
| }); | ||
|
|
||
| return Promise.resolve(result.toUIMessageStream()); | ||
|
|
@@ -35,3 +44,40 @@ export class DocsProviderTransport implements ChatTransport<UIMessage> { | |
| return Promise.resolve(null); | ||
| } | ||
| } | ||
|
|
||
| export function makeCreateResponse({ | ||
|
Author
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. moved LLM call to a helper function which is used both here and in the evals |
||
| languageModel, | ||
| }: { | ||
| languageModel: LanguageModel; | ||
| }) { | ||
| return function createResponse({ | ||
| messages, | ||
| abortSignal, | ||
| systemPromptType, | ||
| headers, | ||
| }: { | ||
| messages: ModelMessage[]; | ||
| abortSignal?: AbortSignal; | ||
| systemPromptType?: keyof typeof buildPrompts; | ||
| headers?: Record<string, string>; | ||
| }) { | ||
| const instructions = | ||
| systemPromptType && buildPrompts[systemPromptType]?.system | ||
| ? buildPrompts[systemPromptType].system | ||
| : undefined; | ||
|
|
||
| const result = streamText({ | ||
| model: languageModel, | ||
| messages: messages, | ||
| abortSignal: abortSignal, | ||
| headers, | ||
| providerOptions: { | ||
| openai: { | ||
| // Have to pass like this because it only accepts JSONValue (not instructions: undefined). | ||
| ...(instructions ? { instructions } : {}), | ||
| }, | ||
| }, | ||
| }); | ||
| return result; | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| export const buildExplainPlanPrompt = ({ | ||
| const explainPlanSystemPrompt = `TODO:....add custom prompt stuff here`; | ||
|
Author
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. add these prompts in future PR. julian or whoever is working on this can iterate on the prompts and PR them |
||
|
|
||
| const buildExplainPlanUserPrompt = ({ | ||
| explainPlan, | ||
| }: { | ||
| explainPlan: string; | ||
|
|
@@ -12,7 +14,9 @@ ${explainPlan}`, | |
| }; | ||
| }; | ||
|
|
||
| export const buildConnectionErrorPrompt = ({ | ||
| const connectionErrorSystemPrompt = `TODO:....add custom prompt stuff here`; | ||
|
|
||
| const buildConnectionUserErrorPrompt = ({ | ||
| connectionString, | ||
| connectionError, | ||
| }: { | ||
|
|
@@ -29,3 +33,14 @@ Error message: | |
| ${connectionError}`, | ||
| }; | ||
| }; | ||
|
|
||
| export const buildPrompts = { | ||
|
Author
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. more extensible by using Record data structure |
||
| 'explain-plan': { | ||
| user: buildExplainPlanUserPrompt, | ||
| system: explainPlanSystemPrompt, | ||
| }, | ||
| 'connection-error': { | ||
| user: buildConnectionUserErrorPrompt, | ||
| system: connectionErrorSystemPrompt, | ||
| }, | ||
| } as const; | ||
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.
pls help with the typescripting here. i couldnt easily figure this out