Skip to content

Commit

Permalink
- chore: 升级 typescript 等基础构建工具依赖
Browse files Browse the repository at this point in the history
- feat(ai-ollama): 添加新组件 `@celljs/ai-ollama`,支持 Ollama 通用能力
- chore: 升级并修复 TypeDoc 文档
- feat(core): 添加 Assert 工具类和 MimeType 相关的工具类
  • Loading branch information
muxiangqiu committed Oct 7, 2024
1 parent 76f832b commit 9d35071
Show file tree
Hide file tree
Showing 275 changed files with 4,935 additions and 2,181 deletions.
74 changes: 37 additions & 37 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fail-fast: false
matrix:
os: [windows-2019, ubuntu-18.04, macos-10.15]
node: ['16.x']
node: ['20.x']

runs-on: ${{ matrix.os }}
timeout-minutes: 60
Expand Down Expand Up @@ -56,47 +56,47 @@ jobs:
run: |
yarn test
# publish:
# needs: build
# if: github.ref == 'refs/heads/main' && github.event_name != 'schedule' # We still publish the manually dispatched workflows: 'workflow_dispatch'.
# runs-on: ubuntu-18.04
publish:
needs: build
if: github.ref == 'refs/heads/main' && github.event_name != 'schedule' # We still publish the manually dispatched workflows: 'workflow_dispatch'.
runs-on: ubuntu-18.04

# The current approach is silly. We should be smarter and use `actions/upload-artifact` and `actions/download-artifact` instead of rebuilding
# everything from scratch again. (git checkout, Node.js install, yarn, etc.) It was not possible to share artifacts on Travis CI without an
# external storage (such as S3), so we did rebuild everything before the npm publish. We should overcome this limitation with GH Actions.
The current approach is silly. We should be smarter and use `actions/upload-artifact` and `actions/download-artifact` instead of rebuilding
everything from scratch again. (git checkout, Node.js install, yarn, etc.) It was not possible to share artifacts on Travis CI without an
external storage (such as S3), so we did rebuild everything before the npm publish. We should overcome this limitation with GH Actions.

# steps:
# - name: Checkout
# uses: actions/checkout@v2
# with:
# fetch-depth: 0 # To fetch all history for all branches and tags. (Will be required for caching with lerna: https://github.com/markuplint/markuplint/pull/111)
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0 # To fetch all history for all branches and tags. (Will be required for caching with lerna: https://github.com/markuplint/markuplint/pull/111)

# - name: Use Node.js 14.x
# uses: actions/setup-node@v1
# with:
# node-version: '14.x'
# registry-url: 'https://registry.npmjs.org'
- name: Use Node.js 20.x
uses: actions/setup-node@v1
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'

# - name: Use Python 3.x
# uses: actions/setup-python@v2
# with:
# python-version: '3.x'
- name: Use Python 3.x
uses: actions/setup-python@v2
with:
python-version: '3.x'

# - name: Pre-Publish
- name: Pre-Publish
run: |
yarn --skip-integrity-check --network-timeout 100000
yarn docs
env:
NODE_OPTIONS: --max_old_space_size=4096

# - name: Publish NPM
# run: |
# yarn --skip-integrity-check --network-timeout 100000
# yarn docs
# yarn run publish
# env:
# NODE_OPTIONS: --max_old_space_size=4096
# NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # The variable name comes from here: https://github.com/actions/setup-node/blob/70b9252472eee7495c93bb1588261539c3c2b98d/src/authutil.ts#L48

# - name: Publish NPM
# run: |
# yarn run publish
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # The variable name comes from here: https://github.com/actions/setup-node/blob/70b9252472eee7495c93bb1588261539c3c2b98d/src/authutil.ts#L48

# - name: Publish GH Pages
# uses: peaceiris/actions-gh-pages@v3
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_dir: ./gh-pages
- name: Publish GH Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./gh-pages
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change

## 3.1.0 (待发布)

- chore: 升级 typescript 等基础构建工具依赖
- feat(ai-ollama): 添加新组件 `@celljs/ai-ollama`,支持 Ollama 通用能力
- chore: 升级并修复 TypeDoc 文档
- feat(core): 添加 Assert 工具类和 MimeType 相关的工具类

## 3.0.0

- chore: Malagu 改名为 CellJS

## 2.60.3

- fix(cli-common): 修复组件判别逻辑错误
Expand Down
2 changes: 1 addition & 1 deletion ai-packages/ai-core/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module.exports = {
],
parserOptions: {
tsconfigRootDir: __dirname,
project: 'compile.tsconfig.json'
project: 'tsconfig.json'
}
};
3 changes: 3 additions & 0 deletions ai-packages/ai-core/src/common/chat/model/chat-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Model, ModelResponse, ModelResult, StreamingModel } from '../../model/m
import { AssistantMessage } from '../message';
import { Prompt } from '../prompt/prompt-protocol';

export const StreamingChatModel = Symbol('StreamingChatModel');
export const ChatModel = Symbol('ChatModel');

/**
* Represents a response returned by the AI.
*/
Expand Down
153 changes: 153 additions & 0 deletions ai-packages/ai-core/src/common/embedding/embedding-protocol.ts
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> {}
1 change: 1 addition & 0 deletions ai-packages/ai-core/src/common/embedding/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './embedding-protocol';
1 change: 1 addition & 0 deletions ai-packages/ai-core/src/common/index.ts
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';
1 change: 1 addition & 0 deletions ai-packages/ai-core/src/common/model/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

export * from './model-protocol';
export * from './function';
3 changes: 3 additions & 0 deletions ai-packages/ai-core/src/common/model/model-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import { Media } from '../chat';
import { Observable } from 'rxjs';

export const Model = Symbol('Model');
export const StreamingModel = Symbol('StreamingModel');

/**
* Interface representing the customizable options for AI model interactions. This marker
* interface allows for the specification of various settings and parameters that can
Expand Down
19 changes: 19 additions & 0 deletions ai-packages/ai-core/tsconfig.json
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"
}
]
}
8 changes: 8 additions & 0 deletions ai-packages/ai-core/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": [
"../../configs/typedoc.base.jsonc"
],
"entryPoints": [
"src/common/index.ts"
],
}
10 changes: 10 additions & 0 deletions ai-packages/ai-ollama/.eslintrc.js
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'
}
};
1 change: 1 addition & 0 deletions ai-packages/ai-ollama/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Cell - AI Ollama Component
45 changes: 45 additions & 0 deletions ai-packages/ai-ollama/package.json
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"
}
Loading

0 comments on commit 9d35071

Please sign in to comment.