-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #273.
- Loading branch information
Showing
9 changed files
with
252 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as React from 'react'; | ||
|
||
import { SvgIcon } from '@mui/joy'; | ||
import { SxProps } from '@mui/joy/styles/types'; | ||
|
||
export function MistralIcon(props: { sx?: SxProps }) { | ||
return <SvgIcon viewBox='0 0 24 24' width='24' height='24' strokeWidth={0} stroke='none' fill='currentColor' strokeLinecap='butt' strokeLinejoin='miter' {...props}> | ||
<path d='m 2,2 v 4 4 V 14 v 4 4 h 4 v -4 -4 h 4 v 4 h 4 v -4 h 4 v 4 4 h 4 v -4 -4 -4 -4 V 2 h -4 v 4 h -4 v 4 h -4 v -4 H 6 V 2 Z' /> | ||
</SvgIcon>; | ||
} |
33 changes: 33 additions & 0 deletions
33
src/modules/llms/transports/server/openai/mistral.wiretypes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { z } from 'zod'; | ||
|
||
|
||
// [Mistral] Models List API - Response | ||
|
||
export const wireMistralModelsListOutputSchema = z.object({ | ||
id: z.string(), | ||
object: z.literal('model'), | ||
created: z.number(), | ||
owned_by: z.string(), | ||
root: z.null().optional(), | ||
parent: z.null().optional(), | ||
// permission: z.array(wireMistralModelsListPermissionsSchema) | ||
}); | ||
|
||
// export type WireMistralModelsListOutput = z.infer<typeof wireMistralModelsListOutputSchema>; | ||
|
||
/* | ||
const wireMistralModelsListPermissionsSchema = z.object({ | ||
id: z.string(), | ||
object: z.literal('model_permission'), | ||
created: z.number(), | ||
allow_create_engine: z.boolean(), | ||
allow_sampling: z.boolean(), | ||
allow_logprobs: z.boolean(), | ||
allow_search_indices: z.boolean(), | ||
allow_view: z.boolean(), | ||
allow_fine_tuning: z.boolean(), | ||
organization: z.string(), | ||
group: z.null().optional(), | ||
is_blocking: z.boolean() | ||
}); | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as React from 'react'; | ||
|
||
import { FormInputKey } from '~/common/components/forms/FormInputKey'; | ||
import { InlineError } from '~/common/components/InlineError'; | ||
import { Link } from '~/common/components/Link'; | ||
import { SetupFormRefetchButton } from '~/common/components/forms/SetupFormRefetchButton'; | ||
import { apiQuery } from '~/common/util/trpc.client'; | ||
|
||
import { DModelSourceId, useModelsStore, useSourceSetup } from '../../store-llms'; | ||
import { modelDescriptionToDLLM } from '../openai/OpenAISourceSetup'; | ||
|
||
import { ModelVendorMistral } from './mistral.vendor'; | ||
|
||
|
||
const MISTRAL_REG_LINK = 'https://console.mistral.ai/'; | ||
|
||
|
||
export function MistralSourceSetup(props: { sourceId: DModelSourceId }) { | ||
|
||
// external state | ||
const { source, sourceSetupValid, sourceHasLLMs, access, updateSetup } = | ||
useSourceSetup(props.sourceId, ModelVendorMistral); | ||
|
||
// derived state | ||
const { oaiKey: mistralKey } = access; | ||
|
||
const needsUserKey = !ModelVendorMistral.hasBackendCap?.(); | ||
const shallFetchSucceed = !needsUserKey || (!!mistralKey && sourceSetupValid); | ||
const showKeyError = !!mistralKey && !sourceSetupValid; | ||
|
||
// fetch models | ||
const { isFetching, refetch, isError, error } = apiQuery.llmOpenAI.listModels.useQuery({ access }, { | ||
enabled: false, | ||
onSuccess: models => source && useModelsStore.getState().setLLMs( | ||
models.models.map(model => modelDescriptionToDLLM(model, source)), | ||
props.sourceId, | ||
), | ||
staleTime: Infinity, | ||
}); | ||
|
||
return <> | ||
|
||
<FormInputKey | ||
id='mistral-key' label='Mistral Key' | ||
rightLabel={<>{needsUserKey | ||
? !mistralKey && <Link level='body-sm' href={MISTRAL_REG_LINK} target='_blank'>request Key</Link> | ||
: '✔️ already set in server'} | ||
</>} | ||
value={mistralKey} onChange={value => updateSetup({ oaiKey: value })} | ||
required={needsUserKey} isError={showKeyError} | ||
placeholder='...' | ||
/> | ||
|
||
<SetupFormRefetchButton | ||
refetch={refetch} disabled={/*!shallFetchSucceed ||*/ isFetching} error={isError} | ||
/> | ||
|
||
{isError && <InlineError error={error} />} | ||
|
||
</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { backendCaps } from '~/modules/backend/state-backend'; | ||
|
||
import { MistralIcon } from '~/common/components/icons/MistralIcon'; | ||
|
||
import type { IModelVendor } from '../IModelVendor'; | ||
import type { OpenAIAccessSchema } from '../../transports/server/openai/openai.router'; | ||
import type { VChatMessageIn, VChatMessageOut } from '../../transports/chatGenerate'; | ||
|
||
import { LLMOptionsOpenAI, openAICallChatGenerate, SourceSetupOpenAI } from '../openai/openai.vendor'; | ||
import { OpenAILLMOptions } from '../openai/OpenAILLMOptions'; | ||
|
||
import { MistralSourceSetup } from './MistralSourceSetup'; | ||
|
||
|
||
// special symbols | ||
|
||
export type SourceSetupMistral = Pick<SourceSetupOpenAI, 'oaiKey' | 'oaiHost'>; | ||
|
||
|
||
/** Implementation Notes for the Mistral vendor | ||
*/ | ||
export const ModelVendorMistral: IModelVendor<SourceSetupMistral, OpenAIAccessSchema, LLMOptionsOpenAI> = { | ||
id: 'mistral', | ||
name: 'Mistral', | ||
rank: 15, | ||
location: 'cloud', | ||
instanceLimit: 1, | ||
hasBackendCap: () => backendCaps().hasLlmMistral, | ||
|
||
// components | ||
Icon: MistralIcon, | ||
SourceSetupComponent: MistralSourceSetup, | ||
LLMOptionsComponent: OpenAILLMOptions, | ||
|
||
// functions | ||
initializeSetup: () => ({ | ||
oaiHost: 'https://api.mistral.ai/', | ||
oaiKey: '', | ||
}), | ||
validateSetup: (setup) => { | ||
return setup.oaiKey?.length >= 32; | ||
}, | ||
getTransportAccess: (partialSetup): OpenAIAccessSchema => ({ | ||
dialect: 'mistral', | ||
oaiKey: partialSetup?.oaiKey || '', | ||
oaiOrg: '', | ||
oaiHost: partialSetup?.oaiHost || '', | ||
heliKey: '', | ||
moderationCheck: false, | ||
}), | ||
callChatGenerate(llm, messages: VChatMessageIn[], maxTokens?: number): Promise<VChatMessageOut> { | ||
return openAICallChatGenerate(this.getTransportAccess(llm._source.setup), llm.options, messages, null, null, maxTokens); | ||
}, | ||
callChatGenerateWF() { | ||
throw new Error('Mistral does not support "Functions" yet'); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c0c724a
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.
Successfully deployed to the following URLs:
big-agi – ./
big-agi-enricoros.vercel.app
big-agi-git-main-stable-enricoros.vercel.app
get.big-agi.com