-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- feat(ai-ollama): 添加新组件 `@celljs/ai-ollama`,支持 Ollama 通用能力 - chore: 升级并修复 TypeDoc 文档 - feat(core): 添加 Assert 工具类和 MimeType 相关的工具类
- Loading branch information
1 parent
76f832b
commit 9d35071
Showing
275 changed files
with
4,935 additions
and
2,181 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
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
153 changes: 153 additions & 0 deletions
153
ai-packages/ai-core/src/common/embedding/embedding-protocol.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,153 @@ | ||
import { MimeType, MimeTypeUtils } from '@celljs/core'; | ||
import { Usage } from '../chat/metadata/metadata-protocol'; | ||
import { Model, ModelOptions, ModelRequest, ModelResponse, ModelResult, ResponseMetadata, ResultMetadata } from '../model/model-protocol'; | ||
|
||
export const EmbeddingModel = Symbol('EmbeddingModel'); | ||
|
||
/** | ||
* Represents the metadata for an embedding result. | ||
*/ | ||
export interface EmbeddingResultMetadata extends ResultMetadata { | ||
/** | ||
* The modality type of the source data used to generate the embedding. | ||
*/ | ||
modalityType: ModalityType; | ||
|
||
/** | ||
* The document ID associated with the embedding. | ||
*/ | ||
documentId: string; | ||
|
||
/** | ||
* The MIME type of the source data used to generate the embedding. | ||
*/ | ||
mimeType: MimeType; | ||
|
||
/** | ||
* The document data associated with the embedding. | ||
*/ | ||
documentData: any; | ||
} | ||
|
||
/** | ||
* Enum representing the modality type of the source data. | ||
*/ | ||
export enum ModalityType { | ||
TEXT = 'TEXT', | ||
IMAGE = 'IMAGE', | ||
AUDIO = 'AUDIO', | ||
VIDEO = 'VIDEO' | ||
} | ||
|
||
/** | ||
* Utility class for modality-related operations. | ||
*/ | ||
export class ModalityUtils { | ||
private static TEXT_MIME_TYPE = MimeTypeUtils.parseMimeType('text/*'); | ||
private static IMAGE_MIME_TYPE = MimeTypeUtils.parseMimeType('image/*'); | ||
private static VIDEO_MIME_TYPE = MimeTypeUtils.parseMimeType('video/*'); | ||
private static AUDIO_MIME_TYPE = MimeTypeUtils.parseMimeType('audio/*'); | ||
|
||
/** | ||
* Infers the {@link ModalityType} of the source data used to generate the | ||
* embedding using the source data {@link MimeType}. | ||
* @param mimeType the {@link MimeType} of the source data. | ||
* @return Returns the {@link ModalityType} of the source data used to generate | ||
* the embedding. | ||
*/ | ||
public static getModalityType(mimeType: MimeType): ModalityType { | ||
if (!mimeType) { | ||
return ModalityType.TEXT; | ||
} | ||
|
||
if (mimeType.isCompatibleWith(ModalityUtils.IMAGE_MIME_TYPE)) { | ||
return ModalityType.IMAGE; | ||
} else if (mimeType.isCompatibleWith(ModalityUtils.AUDIO_MIME_TYPE)) { | ||
return ModalityType.AUDIO; | ||
} else if (mimeType.isCompatibleWith(ModalityUtils.VIDEO_MIME_TYPE)) { | ||
return ModalityType.VIDEO; | ||
} else if (mimeType.isCompatibleWith(ModalityUtils.TEXT_MIME_TYPE)) { | ||
return ModalityType.TEXT; | ||
} | ||
|
||
throw new Error('Unsupported MimeType: ' + mimeType); | ||
} | ||
} | ||
|
||
/** | ||
* Metadata for the embedding response. | ||
*/ | ||
export interface EmbeddingResponseMetadata extends ResponseMetadata { | ||
/** | ||
* The model that handled the request. | ||
*/ | ||
model: string; | ||
|
||
/** | ||
* The AI provider specific metadata on API usage. | ||
* @see Usage | ||
*/ | ||
usage: Usage; | ||
} | ||
|
||
/** | ||
* Represents a single embedding vector. | ||
*/ | ||
export interface Embedding extends ModelResult<number[]> { | ||
/** | ||
* The embedding vector values. | ||
*/ | ||
embedding: number[]; | ||
|
||
/** | ||
* The embedding index in a list of embeddings. | ||
*/ | ||
index: number; | ||
|
||
/** | ||
* The metadata associated with the embedding. | ||
*/ | ||
metadata: EmbeddingResultMetadata; | ||
} | ||
|
||
export interface EmbeddingOptions extends ModelOptions { | ||
|
||
/** | ||
* The name of the embedding model to use. | ||
*/ | ||
model?: string; | ||
|
||
/** | ||
* The dimensionality of the embedding vectors. | ||
*/ | ||
dimensions?: number; | ||
} | ||
|
||
export interface EmbeddingRequest extends ModelRequest<string[]> { | ||
/** | ||
* The list of input strings for the embedding request. | ||
*/ | ||
inputs: string[]; | ||
|
||
/** | ||
* The options for the embedding request. | ||
*/ | ||
options: EmbeddingOptions; | ||
} | ||
|
||
/** | ||
* Embedding response object. | ||
*/ | ||
export interface EmbeddingResponse extends ModelResponse<Embedding> { | ||
/** | ||
* Embedding data. | ||
*/ | ||
embeddings: Embedding[]; | ||
|
||
/** | ||
* Embedding metadata. | ||
*/ | ||
metadata: EmbeddingResponseMetadata; | ||
} | ||
|
||
export interface EmbeddingModel extends Model<EmbeddingRequest, EmbeddingResponse> {} |
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 @@ | ||
export * from './embedding-protocol'; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './chat'; | ||
export * from './model'; | ||
export * from './embedding'; | ||
export * from './utils'; |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
|
||
export * from './model-protocol'; | ||
export * from './function'; |
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,19 @@ | ||
{ | ||
"extends": "@celljs/component/configs/base.tsconfig.json", | ||
"compilerOptions": { | ||
"composite": true, | ||
"rootDir": "src", | ||
"outDir": "lib" | ||
}, | ||
"include": [ | ||
"src" | ||
], | ||
"references": [ | ||
{ | ||
"path": "../../packages/core" | ||
}, | ||
{ | ||
"path": "../../packages/http" | ||
} | ||
] | ||
} |
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,8 @@ | ||
{ | ||
"extends": [ | ||
"../../configs/typedoc.base.jsonc" | ||
], | ||
"entryPoints": [ | ||
"src/common/index.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,10 @@ | ||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
extends: [ | ||
require.resolve('@celljs/component/configs/build.eslintrc.json') | ||
], | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: 'tsconfig.json' | ||
} | ||
}; |
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 @@ | ||
# Cell - AI Ollama Component |
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,45 @@ | ||
{ | ||
"name": "@celljs/ai-ollama", | ||
"version": "3.0.0", | ||
"description": "Ollama models support", | ||
"main": "lib/common/index.js", | ||
"typings": "lib/common/index.d.ts", | ||
"dependencies": { | ||
"@celljs/core": "3.0.0", | ||
"@celljs/http": "3.0.0", | ||
"@celljs/ai-core": "3.0.0", | ||
"class-transformer": "^0.5.1", | ||
"rxjs": "^6.6.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"keywords": [ | ||
"cell-component" | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/cellbang/cell.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/cellbang/cell/issues" | ||
}, | ||
"homepage": "https://github.com/cellbang/cell", | ||
"files": [ | ||
"lib", | ||
"src", | ||
"cell.yml" | ||
], | ||
"scripts": { | ||
"lint": "cell-component lint", | ||
"build": "cell-component build", | ||
"watch": "cell-component watch", | ||
"clean": "cell-component clean", | ||
"test": "cell-component test:js" | ||
}, | ||
"devDependencies": { | ||
"@celljs/component": "3.0.0" | ||
}, | ||
"gitHead": "bbf636b21ea1a347affcc05a5f6f58b35bedef6d" | ||
} |
Oops, something went wrong.